From 39de9d56dbd0d6925fbbded8509d9883bd38497b Mon Sep 17 00:00:00 2001 From: Rob Bygrave Date: Wed, 7 Sep 2022 19:55:43 +1200 Subject: [PATCH] #2825 - DB Migration - create schema migration is repeated unnecessarily --- .../dbmigration/model/ModelContainer.java | 11 +++++++---- .../dbmigration/model/ModelContainerApplyTest.java | 2 ++ 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/ebean-ddl-generator/src/main/java/io/ebeaninternal/dbmigration/model/ModelContainer.java b/ebean-ddl-generator/src/main/java/io/ebeaninternal/dbmigration/model/ModelContainer.java index 3e615fd7d..afd52d186 100644 --- a/ebean-ddl-generator/src/main/java/io/ebeaninternal/dbmigration/model/ModelContainer.java +++ b/ebean-ddl-generator/src/main/java/io/ebeaninternal/dbmigration/model/ModelContainer.java @@ -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?"); diff --git a/ebean-ddl-generator/src/test/java/io/ebeaninternal/dbmigration/model/ModelContainerApplyTest.java b/ebean-ddl-generator/src/test/java/io/ebeaninternal/dbmigration/model/ModelContainerApplyTest.java index 48769a6dc..3daca11b2 100644 --- a/ebean-ddl-generator/src/test/java/io/ebeaninternal/dbmigration/model/ModelContainerApplyTest.java +++ b/ebean-ddl-generator/src/test/java/io/ebeaninternal/dbmigration/model/ModelContainerApplyTest.java @@ -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) {