Skip to content

Commit

Permalink
review feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
fil512 committed Nov 23, 2019
1 parent 047fefc commit 98d21c4
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public SchemaMigrator(BasicDataSource theDataSource, Properties jpaProperties, L

public void validate() {
if (mySkipValidation) {
ourLog.info("Database running in hibernate auto-update mode. Skipping schema validation.");
ourLog.warn("Database running in hibernate auto-update mode. Skipping schema validation.");
return;
}
try (Connection connection = myDataSource.getConnection()) {
Expand All @@ -52,7 +52,7 @@ public void validate() {

public void migrate() {
if (mySkipValidation) {
ourLog.info("Database running in hibernate auto-update mode. Skipping schema migration.");
ourLog.warn("Database running in hibernate auto-update mode. Skipping schema migration.");
return;
}
myMigrator.migrate();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,6 @@ public JdbcTemplate newJdbcTemnplate() {
public abstract void execute() throws SQLException;

public String getFlywayVersion() {
String retval = "";
String releasePart = myProductVersion;
if (releasePart.startsWith("V")) {
releasePart = releasePart.substring(1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public class RenameColumnTask extends BaseTableTask<RenameColumnTask> {
private static final Logger ourLog = LoggerFactory.getLogger(RenameColumnTask.class);
private String myOldName;
private String myNewName;
private boolean myAllowNeitherColumnToExist;
private boolean myIsOkayIfNeitherColumnExists;
private boolean myDeleteTargetColumnFirstIfBothExist;

public RenameColumnTask(String theProductVersion, String theSchemaVersion) {
Expand Down Expand Up @@ -89,7 +89,7 @@ public void execute() throws SQLException {
throw new SQLException("Can not rename " + getTableName() + "." + myOldName + " to " + myNewName + " because both columns exist!");
}
} else if (!haveOldName && !haveNewName) {
if (isAllowNeitherColumnToExist()) {
if (isOkayIfNeitherColumnExists()) {
return;
}
throw new SQLException("Can not rename " + getTableName() + "." + myOldName + " to " + myNewName + " because neither column exists!");
Expand Down Expand Up @@ -128,12 +128,12 @@ public void execute() throws SQLException {

}

public boolean isAllowNeitherColumnToExist() {
return myAllowNeitherColumnToExist;
public boolean isOkayIfNeitherColumnExists() {
return myIsOkayIfNeitherColumnExists;
}

public void setAllowNeitherColumnToExist(boolean theAllowNeitherColumnToExist) {
myAllowNeitherColumnToExist = theAllowNeitherColumnToExist;
public void setOkayIfNeitherColumnExists(boolean theOkayIfNeitherColumnExists) {
myIsOkayIfNeitherColumnExists = theOkayIfNeitherColumnExists;
}

@Override
Expand All @@ -146,7 +146,7 @@ public boolean equals(Object theO) {

return new EqualsBuilder()
.appendSuper(super.equals(theO))
.append(myAllowNeitherColumnToExist, that.myAllowNeitherColumnToExist)
.append(myIsOkayIfNeitherColumnExists, that.myIsOkayIfNeitherColumnExists)
.append(myDeleteTargetColumnFirstIfBothExist, that.myDeleteTargetColumnFirstIfBothExist)
.append(myOldName, that.myOldName)
.append(myNewName, that.myNewName)
Expand All @@ -159,7 +159,7 @@ public int hashCode() {
.appendSuper(super.hashCode())
.append(myOldName)
.append(myNewName)
.append(myAllowNeitherColumnToExist)
.append(myIsOkayIfNeitherColumnExists)
.append(myDeleteTargetColumnFirstIfBothExist)
.toHashCode();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,16 +176,16 @@ public BuilderWithTableName renameColumn(String theVersion, String theOldName, S
/**
* @param theOldName The old column name
* @param theNewName The new column name
* @param theAllowNeitherColumnToExist Setting this to true means that it's not an error if neither column exists
* @param theDeleteTargetColumnFirstIfBothEixst Setting this to true causes the migrator to be ok with the target column existing. It will make sure that there is no data in the column with the new name, then delete it if so in order to make room for the renamed column. If there is data it will still bomb out.
* @param isOkayIfNeitherColumnExists Setting this to true means that it's not an error if neither column exists
* @param theDeleteTargetColumnFirstIfBothExist Setting this to true causes the migrator to be ok with the target column existing. It will make sure that there is no data in the column with the new name, then delete it if so in order to make room for the renamed column. If there is data it will still bomb out.
*/
public BuilderWithTableName renameColumn(String theVersion, String theOldName, String theNewName, boolean theAllowNeitherColumnToExist, boolean theDeleteTargetColumnFirstIfBothEixst) {
public BuilderWithTableName renameColumn(String theVersion, String theOldName, String theNewName, boolean isOkayIfNeitherColumnExists, boolean theDeleteTargetColumnFirstIfBothExist) {
RenameColumnTask task = new RenameColumnTask(myRelease, theVersion);
task.setTableName(myTableName);
task.setOldName(theOldName);
task.setNewName(theNewName);
task.setAllowNeitherColumnToExist(theAllowNeitherColumnToExist);
task.setDeleteTargetColumnFirstIfBothExist(theDeleteTargetColumnFirstIfBothEixst);
task.setOkayIfNeitherColumnExists(isOkayIfNeitherColumnExists);
task.setDeleteTargetColumnFirstIfBothExist(theDeleteTargetColumnFirstIfBothExist);
addTask(task);
return this;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ private AddColumnTask buildTask() {
}

@Test
public void checkAllHashes() {
public void testCheckAllHashes() {
List<BaseTask<?>> tasks1 = new HapiFhirJpaMigrationTasks(Collections.emptySet()).getAllTasks(VersionEnum.values());
Map<String, Integer> hashesByVersion = new HashMap<>();
for (BaseTask task : tasks1) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ public void testNeitherColumnExistsButAllowed() {
task.setTableName("SOMETABLE");
task.setOldName("myTextCol");
task.setNewName("TEXTCOL");
task.setAllowNeitherColumnToExist(true);
task.setOkayIfNeitherColumnExists(true);
getMigrator().addTask(task);

getMigrator().migrate();
Expand Down

0 comments on commit 98d21c4

Please sign in to comment.