diff --git a/flyway-core/src/main/java/org/flywaydb/core/Flyway.java b/flyway-core/src/main/java/org/flywaydb/core/Flyway.java index ad7f1ed37d..be1d8e18af 100644 --- a/flyway-core/src/main/java/org/flywaydb/core/Flyway.java +++ b/flyway-core/src/main/java/org/flywaydb/core/Flyway.java @@ -211,7 +211,7 @@ public MigrateResult execute(MigrationResolver migrationResolver, } } - return new DbMigrate(database, schemaHistory, schemas, migrationResolver, configuration, + return new DbMigrate(database, schemaHistory, schemas[0], migrationResolver, configuration, callbackExecutor).migrate(); } }, true); @@ -317,7 +317,7 @@ public ValidateResult execute(MigrationResolver migrationResolver, SchemaHistory */ private ValidateResult doValidate(Database database, MigrationResolver migrationResolver, SchemaHistory schemaHistory, Schema[] schemas, CallbackExecutor callbackExecutor, boolean ignorePending) { - ValidateResult validateResult = new DbValidate(database, schemaHistory, schemas, migrationResolver, + ValidateResult validateResult = new DbValidate(database, schemaHistory, schemas[0], migrationResolver, configuration, ignorePending, callbackExecutor).validate(); if (!validateResult.validationSuccessful && configuration.isCleanOnValidationError()) { @@ -410,7 +410,7 @@ public RepairResult repair() throws FlywayException { public RepairResult execute(MigrationResolver migrationResolver, SchemaHistory schemaHistory, Database database, Schema[] schemas, CallbackExecutor callbackExecutor, StatementInterceptor statementInterceptor) { - return new DbRepair(database, migrationResolver, schemaHistory, schemas, callbackExecutor, configuration).repair(); + return new DbRepair(database, migrationResolver, schemaHistory, callbackExecutor, configuration).repair(); } }, true); } diff --git a/flyway-core/src/main/java/org/flywaydb/core/internal/command/DbInfo.java b/flyway-core/src/main/java/org/flywaydb/core/internal/command/DbInfo.java index c8adabd30c..75601f4730 100644 --- a/flyway-core/src/main/java/org/flywaydb/core/internal/command/DbInfo.java +++ b/flyway-core/src/main/java/org/flywaydb/core/internal/command/DbInfo.java @@ -26,6 +26,8 @@ import org.flywaydb.core.internal.info.MigrationInfoServiceImpl; import org.flywaydb.core.internal.schemahistory.SchemaHistory; +import java.util.Arrays; + public class DbInfo { private final MigrationResolver migrationResolver; private final SchemaHistory schemaHistory; @@ -51,10 +53,11 @@ public MigrationInfoService info() { MigrationInfoServiceImpl migrationInfoService; try { migrationInfoService = - new MigrationInfoServiceImpl(migrationResolver, schemaHistory, schemas, database, configuration, + new MigrationInfoServiceImpl(migrationResolver, schemaHistory, database, configuration, configuration.getTarget(), configuration.isOutOfOrder(), configuration.getCherryPick(), true, true, true, true); migrationInfoService.refresh(); + migrationInfoService.setAllSchemasEmpty(schemas); } catch (FlywayException e) { callbackExecutor.onEvent(Event.AFTER_INFO_ERROR); throw e; diff --git a/flyway-core/src/main/java/org/flywaydb/core/internal/command/DbMigrate.java b/flyway-core/src/main/java/org/flywaydb/core/internal/command/DbMigrate.java index 51a14b7674..1d7af2f044 100644 --- a/flyway-core/src/main/java/org/flywaydb/core/internal/command/DbMigrate.java +++ b/flyway-core/src/main/java/org/flywaydb/core/internal/command/DbMigrate.java @@ -71,11 +71,6 @@ public class DbMigrate { */ private final Schema schema; - /** - * The list of schemas managed by Flyway. - */ - private final Schema[] schemas; - /** * The migration resolver. */ @@ -116,19 +111,18 @@ public class DbMigrate { * * @param database Database-specific functionality. * @param schemaHistory The database schema history table. - * @param schemas The list of schemas managed by Flyway. + * @param schema The schema containing the schema history table. * @param migrationResolver The migration resolver. * @param configuration The Flyway configuration. * @param callbackExecutor The callbacks executor. */ public DbMigrate(Database database, - SchemaHistory schemaHistory, Schema[] schemas, MigrationResolver migrationResolver, + SchemaHistory schemaHistory, Schema schema, MigrationResolver migrationResolver, Configuration configuration, CallbackExecutor callbackExecutor) { this.database = database; this.connectionUserObjects = database.getMigrationConnection(); this.schemaHistory = schemaHistory; - this.schema = schemas[0]; - this.schemas = schemas; + this.schema = schema; this.migrationResolver = migrationResolver; this.configuration = configuration; this.callbackExecutor = callbackExecutor; @@ -229,7 +223,7 @@ public Integer call() { */ private Integer migrateGroup(boolean firstRun) { MigrationInfoServiceImpl infoService = - new MigrationInfoServiceImpl(migrationResolver, schemaHistory, schemas, database, configuration, + new MigrationInfoServiceImpl(migrationResolver, schemaHistory, database, configuration, configuration.getTarget(), configuration.isOutOfOrder(), configuration.getCherryPick(), true, true, true, true); infoService.refresh(); diff --git a/flyway-core/src/main/java/org/flywaydb/core/internal/command/DbRepair.java b/flyway-core/src/main/java/org/flywaydb/core/internal/command/DbRepair.java index ae40dd3152..7eb224b558 100644 --- a/flyway-core/src/main/java/org/flywaydb/core/internal/command/DbRepair.java +++ b/flyway-core/src/main/java/org/flywaydb/core/internal/command/DbRepair.java @@ -30,7 +30,6 @@ import org.flywaydb.core.internal.callback.CallbackExecutor; import org.flywaydb.core.internal.database.base.Connection; import org.flywaydb.core.internal.database.base.Database; -import org.flywaydb.core.internal.database.base.Schema; import org.flywaydb.core.internal.info.MigrationInfoImpl; import org.flywaydb.core.internal.info.MigrationInfoServiceImpl; import org.flywaydb.core.internal.jdbc.ExecutionTemplateFactory; @@ -94,10 +93,9 @@ public class DbRepair { * @param database The database-specific support. * @param migrationResolver The migration resolver. * @param schemaHistory The schema history table. - * @param schemas The list of schemas managed by Flyway. * @param callbackExecutor The callback executor. */ - public DbRepair(Database database, MigrationResolver migrationResolver, SchemaHistory schemaHistory, Schema[] schemas, + public DbRepair(Database database, MigrationResolver migrationResolver, SchemaHistory schemaHistory, CallbackExecutor callbackExecutor, Configuration configuration) { this.database = database; this.connection = database.getMainConnection(); @@ -105,7 +103,7 @@ public DbRepair(Database database, MigrationResolver migrationResolver, SchemaHi this.callbackExecutor = callbackExecutor; this.configuration = configuration; - this.migrationInfoService = new MigrationInfoServiceImpl(migrationResolver, schemaHistory, schemas, database, configuration, + this.migrationInfoService = new MigrationInfoServiceImpl(migrationResolver, schemaHistory, database, configuration, MigrationVersion.LATEST, true, configuration.getCherryPick(), true, true, true, true); this.commandResultFactory = new CommandResultFactory(); diff --git a/flyway-core/src/main/java/org/flywaydb/core/internal/command/DbValidate.java b/flyway-core/src/main/java/org/flywaydb/core/internal/command/DbValidate.java index ccc14562c9..6c50761261 100644 --- a/flyway-core/src/main/java/org/flywaydb/core/internal/command/DbValidate.java +++ b/flyway-core/src/main/java/org/flywaydb/core/internal/command/DbValidate.java @@ -59,11 +59,6 @@ public class DbValidate { */ private final Schema schema; - /** - * The list of schemas managed by Flyway. - */ - private final Schema[] schemas; - /** * The migration resolver. */ @@ -99,19 +94,18 @@ public class DbValidate { * * @param database The DB support for the connection. * @param schemaHistory The database schema history table. - * @param schemas The list of schemas managed by Flyway. + * @param schema The schema containing the schema history table. * @param migrationResolver The migration resolver. * @param configuration The current configuration. * @param pending Whether pending migrations are allowed. * @param callbackExecutor The callback executor. */ - public DbValidate(Database database, SchemaHistory schemaHistory, Schema[] schemas, MigrationResolver migrationResolver, + public DbValidate(Database database, SchemaHistory schemaHistory, Schema schema, MigrationResolver migrationResolver, Configuration configuration, boolean pending, CallbackExecutor callbackExecutor) { this.database = database; this.connection = database.getMainConnection(); this.schemaHistory = schemaHistory; - this.schema = schemas[0]; - this.schemas = schemas; + this.schema = schema; this.migrationResolver = migrationResolver; this.configuration = configuration; this.pending = pending; @@ -152,7 +146,7 @@ public Configuration getConfiguration() { @Override public Pair> call() { MigrationInfoServiceImpl migrationInfoService = - new MigrationInfoServiceImpl(migrationResolver, schemaHistory, schemas, database, configuration, + new MigrationInfoServiceImpl(migrationResolver, schemaHistory, database, configuration, configuration.getTarget(), configuration.isOutOfOrder(), configuration.getCherryPick(), diff --git a/flyway-core/src/main/java/org/flywaydb/core/internal/info/MigrationInfoServiceImpl.java b/flyway-core/src/main/java/org/flywaydb/core/internal/info/MigrationInfoServiceImpl.java index 704251bc82..071aa97059 100644 --- a/flyway-core/src/main/java/org/flywaydb/core/internal/info/MigrationInfoServiceImpl.java +++ b/flyway-core/src/main/java/org/flywaydb/core/internal/info/MigrationInfoServiceImpl.java @@ -97,15 +97,10 @@ public class MigrationInfoServiceImpl implements MigrationInfoService, Operation */ private List migrationInfos; - /** - * The list of schemas managed by Flyway. - */ - private Schema[] schemas; - /** * Whether all of the specified schemas are empty or not. */ - private boolean allSchemasEmpty = true; + private Boolean allSchemasEmpty; /** * Creates a new MigrationInfoServiceImpl. @@ -122,7 +117,7 @@ public class MigrationInfoServiceImpl implements MigrationInfoService, Operation * @param future Whether future migrations are allowed. */ public MigrationInfoServiceImpl(MigrationResolver migrationResolver, - SchemaHistory schemaHistory, Schema[] schemas, Database database, final Configuration configuration, + SchemaHistory schemaHistory, Database database, final Configuration configuration, MigrationVersion target, boolean outOfOrder, MigrationPattern[] cherryPick, boolean pending, boolean missing, boolean ignored, boolean future) { this.migrationResolver = migrationResolver; @@ -141,7 +136,6 @@ public Configuration getConfiguration() { this.missing = missing; this.ignored = ignored || cherryPick != null; this.future = future; - this.schemas = schemas; } /** @@ -359,9 +353,6 @@ public void refresh() { )); } - // Update whether all managed schemas are empty or not - allSchemasEmpty = Arrays.stream(schemas).allMatch(Schema::empty); - // Set output Collections.sort(migrationInfos1); migrationInfos = migrationInfos1; @@ -616,6 +607,10 @@ public List validate() { return invalidMigrations; } + public void setAllSchemasEmpty(Schema[] schemas) { + allSchemasEmpty = Arrays.stream(schemas).allMatch(Schema::empty); + } + @Override public InfoResult getInfoResult() { return getInfoResult(this.all());