#2825 - DB Migration - create schema migration is repeated unnecessarily

This commit is contained in:
Rob Bygrave
2022-09-07 19:55:43 +12:00
parent 94dbd9d6ad
commit 39de9d56db
2 changed files with 9 additions and 4 deletions
@@ -161,7 +161,9 @@ public class ModelContainer {
applyChange((AlterForeignKey) change);
} else if (change instanceof AddTableComment) {
applyChange((AddTableComment) change);
} else if (change instanceof Sql || change instanceof CreateSchema) {
} else if (change instanceof CreateSchema) {
applyChange((CreateSchema)change);
} else if (change instanceof Sql) {
// do nothing
} else {
throw new IllegalArgumentException("No rule for " + change);
@@ -173,7 +175,6 @@ public class ModelContainer {
* Set the withHistory flag on the associated base table.
*/
private void applyChange(AddHistoryTable change) {
MTable table = tables.get(change.getBaseTable());
if (table == null) {
throw new IllegalStateException("Table [" + change.getBaseTable() + "] does not exist in model?");
@@ -185,7 +186,6 @@ public class ModelContainer {
* Unset the withHistory flag on the associated base table.
*/
protected void applyChange(DropHistoryTable change) {
MTable table = tables.get(change.getBaseTable());
if (table != null) {
table.setWithHistory(false);
@@ -228,6 +228,10 @@ public class ModelContainer {
}
}
protected void applyChange(CreateSchema createSchema) {
schemas.add(createSchema.getName());
}
/**
* Apply a CreateTable change to the model.
*/
@@ -426,7 +430,6 @@ public class ModelContainer {
* Register a drop column on a history tables that has not been applied yet.
*/
private void registerPendingDropColumn(DropColumn dropColumn) {
MTable table = getTable(dropColumn.getTableName());
if (table == null) {
throw new IllegalArgumentException("Table [" + dropColumn.getTableName() + "] not found?");
@@ -45,6 +45,8 @@ class ModelContainerApplyTest {
ModelContainer model = new ModelContainer();
model.apply(migration, MigrationVersion.parse("1.1"));
assertThat(model.getSchemas()).contains("foo");
}
private Migration newMigration(Object change) {