review feedback
This commit is contained in:
parent
047fefce5e
commit
98d21c4ee3
|
@ -34,7 +34,7 @@ public class SchemaMigrator {
|
||||||
|
|
||||||
public void validate() {
|
public void validate() {
|
||||||
if (mySkipValidation) {
|
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;
|
return;
|
||||||
}
|
}
|
||||||
try (Connection connection = myDataSource.getConnection()) {
|
try (Connection connection = myDataSource.getConnection()) {
|
||||||
|
@ -52,7 +52,7 @@ public class SchemaMigrator {
|
||||||
|
|
||||||
public void migrate() {
|
public void migrate() {
|
||||||
if (mySkipValidation) {
|
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;
|
return;
|
||||||
}
|
}
|
||||||
myMigrator.migrate();
|
myMigrator.migrate();
|
||||||
|
|
|
@ -145,7 +145,6 @@ public abstract class BaseTask<T extends BaseTask> {
|
||||||
public abstract void execute() throws SQLException;
|
public abstract void execute() throws SQLException;
|
||||||
|
|
||||||
public String getFlywayVersion() {
|
public String getFlywayVersion() {
|
||||||
String retval = "";
|
|
||||||
String releasePart = myProductVersion;
|
String releasePart = myProductVersion;
|
||||||
if (releasePart.startsWith("V")) {
|
if (releasePart.startsWith("V")) {
|
||||||
releasePart = releasePart.substring(1);
|
releasePart = releasePart.substring(1);
|
||||||
|
|
|
@ -37,7 +37,7 @@ public class RenameColumnTask extends BaseTableTask<RenameColumnTask> {
|
||||||
private static final Logger ourLog = LoggerFactory.getLogger(RenameColumnTask.class);
|
private static final Logger ourLog = LoggerFactory.getLogger(RenameColumnTask.class);
|
||||||
private String myOldName;
|
private String myOldName;
|
||||||
private String myNewName;
|
private String myNewName;
|
||||||
private boolean myAllowNeitherColumnToExist;
|
private boolean myIsOkayIfNeitherColumnExists;
|
||||||
private boolean myDeleteTargetColumnFirstIfBothExist;
|
private boolean myDeleteTargetColumnFirstIfBothExist;
|
||||||
|
|
||||||
public RenameColumnTask(String theProductVersion, String theSchemaVersion) {
|
public RenameColumnTask(String theProductVersion, String theSchemaVersion) {
|
||||||
|
@ -89,7 +89,7 @@ public class RenameColumnTask extends BaseTableTask<RenameColumnTask> {
|
||||||
throw new SQLException("Can not rename " + getTableName() + "." + myOldName + " to " + myNewName + " because both columns exist!");
|
throw new SQLException("Can not rename " + getTableName() + "." + myOldName + " to " + myNewName + " because both columns exist!");
|
||||||
}
|
}
|
||||||
} else if (!haveOldName && !haveNewName) {
|
} else if (!haveOldName && !haveNewName) {
|
||||||
if (isAllowNeitherColumnToExist()) {
|
if (isOkayIfNeitherColumnExists()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
throw new SQLException("Can not rename " + getTableName() + "." + myOldName + " to " + myNewName + " because neither column exists!");
|
throw new SQLException("Can not rename " + getTableName() + "." + myOldName + " to " + myNewName + " because neither column exists!");
|
||||||
|
@ -128,12 +128,12 @@ public class RenameColumnTask extends BaseTableTask<RenameColumnTask> {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isAllowNeitherColumnToExist() {
|
public boolean isOkayIfNeitherColumnExists() {
|
||||||
return myAllowNeitherColumnToExist;
|
return myIsOkayIfNeitherColumnExists;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setAllowNeitherColumnToExist(boolean theAllowNeitherColumnToExist) {
|
public void setOkayIfNeitherColumnExists(boolean theOkayIfNeitherColumnExists) {
|
||||||
myAllowNeitherColumnToExist = theAllowNeitherColumnToExist;
|
myIsOkayIfNeitherColumnExists = theOkayIfNeitherColumnExists;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -146,7 +146,7 @@ public class RenameColumnTask extends BaseTableTask<RenameColumnTask> {
|
||||||
|
|
||||||
return new EqualsBuilder()
|
return new EqualsBuilder()
|
||||||
.appendSuper(super.equals(theO))
|
.appendSuper(super.equals(theO))
|
||||||
.append(myAllowNeitherColumnToExist, that.myAllowNeitherColumnToExist)
|
.append(myIsOkayIfNeitherColumnExists, that.myIsOkayIfNeitherColumnExists)
|
||||||
.append(myDeleteTargetColumnFirstIfBothExist, that.myDeleteTargetColumnFirstIfBothExist)
|
.append(myDeleteTargetColumnFirstIfBothExist, that.myDeleteTargetColumnFirstIfBothExist)
|
||||||
.append(myOldName, that.myOldName)
|
.append(myOldName, that.myOldName)
|
||||||
.append(myNewName, that.myNewName)
|
.append(myNewName, that.myNewName)
|
||||||
|
@ -159,7 +159,7 @@ public class RenameColumnTask extends BaseTableTask<RenameColumnTask> {
|
||||||
.appendSuper(super.hashCode())
|
.appendSuper(super.hashCode())
|
||||||
.append(myOldName)
|
.append(myOldName)
|
||||||
.append(myNewName)
|
.append(myNewName)
|
||||||
.append(myAllowNeitherColumnToExist)
|
.append(myIsOkayIfNeitherColumnExists)
|
||||||
.append(myDeleteTargetColumnFirstIfBothExist)
|
.append(myDeleteTargetColumnFirstIfBothExist)
|
||||||
.toHashCode();
|
.toHashCode();
|
||||||
}
|
}
|
||||||
|
|
|
@ -176,16 +176,16 @@ public class Builder {
|
||||||
/**
|
/**
|
||||||
* @param theOldName The old column name
|
* @param theOldName The old column name
|
||||||
* @param theNewName The new 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 isOkayIfNeitherColumnExists 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 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);
|
RenameColumnTask task = new RenameColumnTask(myRelease, theVersion);
|
||||||
task.setTableName(myTableName);
|
task.setTableName(myTableName);
|
||||||
task.setOldName(theOldName);
|
task.setOldName(theOldName);
|
||||||
task.setNewName(theNewName);
|
task.setNewName(theNewName);
|
||||||
task.setAllowNeitherColumnToExist(theAllowNeitherColumnToExist);
|
task.setOkayIfNeitherColumnExists(isOkayIfNeitherColumnExists);
|
||||||
task.setDeleteTargetColumnFirstIfBothExist(theDeleteTargetColumnFirstIfBothEixst);
|
task.setDeleteTargetColumnFirstIfBothExist(theDeleteTargetColumnFirstIfBothExist);
|
||||||
addTask(task);
|
addTask(task);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,7 +32,7 @@ public class HashTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void checkAllHashes() {
|
public void testCheckAllHashes() {
|
||||||
List<BaseTask<?>> tasks1 = new HapiFhirJpaMigrationTasks(Collections.emptySet()).getAllTasks(VersionEnum.values());
|
List<BaseTask<?>> tasks1 = new HapiFhirJpaMigrationTasks(Collections.emptySet()).getAllTasks(VersionEnum.values());
|
||||||
Map<String, Integer> hashesByVersion = new HashMap<>();
|
Map<String, Integer> hashesByVersion = new HashMap<>();
|
||||||
for (BaseTask task : tasks1) {
|
for (BaseTask task : tasks1) {
|
||||||
|
|
|
@ -112,7 +112,7 @@ public class RenameColumnTaskTest extends BaseTest {
|
||||||
task.setTableName("SOMETABLE");
|
task.setTableName("SOMETABLE");
|
||||||
task.setOldName("myTextCol");
|
task.setOldName("myTextCol");
|
||||||
task.setNewName("TEXTCOL");
|
task.setNewName("TEXTCOL");
|
||||||
task.setAllowNeitherColumnToExist(true);
|
task.setOkayIfNeitherColumnExists(true);
|
||||||
getMigrator().addTask(task);
|
getMigrator().addTask(task);
|
||||||
|
|
||||||
getMigrator().migrate();
|
getMigrator().migrate();
|
||||||
|
|
Loading…
Reference in New Issue