diff --git a/flyway-commandline/src/main/assembly/flyway.conf b/flyway-commandline/src/main/assembly/flyway.conf index ea50fb00d5..ccf0d416cb 100644 --- a/flyway-commandline/src/main/assembly/flyway.conf +++ b/flyway-commandline/src/main/assembly/flyway.conf @@ -210,6 +210,13 @@ flyway.url= # true to continue normally, false to fail fast with an exception. (default: false) # flyway.ignoreIgnoredMigrations= +# Ignore pending migrations when reading the schema history table. These are migrations that are available on the +# classpath but have not yet been performed by an application deployment. +# This can be useful for verifying that in-development migration changes don't contain any validation-breaking changes +# of migrations that have already been applied to a production environment, e.g. as part of a CI/CD process, without +# failing because of the existence of new migration versions. (default: false) +# flyway.ignorePendingMigrations= + # Ignore future migrations when reading the schema history table. These are migrations that were performed by a # newer deployment of the application that are not yet available in this version. For example: we have migrations # available on the classpath up to version 3.0. The schema history table indicates that a migration to version 4.0 diff --git a/flyway-commandline/src/main/java/org/flywaydb/commandline/Main.java b/flyway-commandline/src/main/java/org/flywaydb/commandline/Main.java index 422c9501af..b04efc1354 100644 --- a/flyway-commandline/src/main/java/org/flywaydb/commandline/Main.java +++ b/flyway-commandline/src/main/java/org/flywaydb/commandline/Main.java @@ -283,6 +283,7 @@ private static void printUsage() { LOG.info("validateOnMigrate : Validate when running migrate"); LOG.info("ignoreMissingMigrations : Allow missing migrations when validating"); LOG.info("ignoreIgnoredMigrations : Allow ignored migrations when validating"); + LOG.info("ignorePendingMigrations : Allow pending migrations when validating"); LOG.info("ignoreFutureMigrations : Allow future migrations when validating"); LOG.info("cleanOnValidationError : Automatically clean on a validation error"); LOG.info("cleanDisabled : Whether to disable clean"); 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 af3a726682..6f99574bf1 100644 --- a/flyway-core/src/main/java/org/flywaydb/core/Flyway.java +++ b/flyway-core/src/main/java/org/flywaydb/core/Flyway.java @@ -311,6 +311,15 @@ public boolean isIgnoreIgnoredMigrations() { return configuration.isIgnoreIgnoredMigrations(); } + /** + * @deprecated Direct configuration of the Flyway object has been deprecated and will be removed in Flyway 6.0. Use Flyway.configure() instead. + */ + @Deprecated + @Override + public boolean isIgnorePendingMigrations() { + return configuration.isIgnorePendingMigrations(); + } + /** * @deprecated Direct configuration of the Flyway object has been deprecated and will be removed in Flyway 6.0. Use Flyway.configure() instead. */ @@ -672,6 +681,22 @@ public void setIgnoreIgnoredMigrations(boolean ignoreIgnoredMigrations) { configuration.setIgnoreIgnoredMigrations(ignoreIgnoredMigrations); } + /** + * Ignore pending migrations when reading the schema history table. These are migrations that are available on the + * classpath but have not yet been performed by an application deployment. This can be useful for verifying + * that in-development migration changes don't contain any validation-breaking changes of migrations that have + * already been applied to a production environment, e.g. as part of a CI/CD process, without failing because of the + * existence of new migration versions. + * + * @param ignorePendingMigrations {@code true} to continue normally, {@code false} to fail fast with an exception. + * (default: {@code false}) + * @deprecated Direct configuration of the Flyway object has been deprecated and will be removed in Flyway 6.0. Use Flyway.configure() instead. + */ + @Deprecated + public void setIgnorePendingMigrations(boolean ignorePendingMigrations) { + configuration.setIgnorePendingMigrations(ignorePendingMigrations); + } + /** * Whether to ignore future migrations when reading the schema history table. These are migrations that were performed by a * newer deployment of the application that are not yet available in this version. For example: we have migrations @@ -1329,13 +1354,15 @@ public Void execute(MigrationResolver migrationResolver, SchemaHistory schemaHis * @param schemaHistory The schema history table. * @param schemas The schemas managed by Flyway. * @param callbackExecutor The callback executor. - * @param pending Whether pending migrations are ok. + * @param aboutToMigrate Whether migrations are about to be run (and therefore to ignore pending migrations + * regardless of the ignorePendingMigrations configuration property) */ private void doValidate(Database database, MigrationResolver migrationResolver, - SchemaHistory schemaHistory, Schema[] schemas, CallbackExecutor callbackExecutor, boolean pending) { + SchemaHistory schemaHistory, Schema[] schemas, CallbackExecutor callbackExecutor, boolean aboutToMigrate) { String validationError = new DbValidate(database, schemaHistory, schemas[0], migrationResolver, - configuration.getTarget(), configuration.isOutOfOrder(), pending, + configuration.getTarget(), configuration.isOutOfOrder(), + aboutToMigrate || configuration.isIgnorePendingMigrations(), configuration.isIgnoreMissingMigrations(), configuration.isIgnoreIgnoredMigrations(), configuration.isIgnoreFutureMigrations(), diff --git a/flyway-core/src/main/java/org/flywaydb/core/api/configuration/ClassicConfiguration.java b/flyway-core/src/main/java/org/flywaydb/core/api/configuration/ClassicConfiguration.java index b411f32665..ea8adfceae 100644 --- a/flyway-core/src/main/java/org/flywaydb/core/api/configuration/ClassicConfiguration.java +++ b/flyway-core/src/main/java/org/flywaydb/core/api/configuration/ClassicConfiguration.java @@ -207,6 +207,18 @@ public class ClassicConfiguration implements Configuration { */ private boolean ignoreIgnoredMigrations; + /** + * Ignore pending migrations when reading the schema history table. These are migrations that are available on the + * classpath but have not yet been performed by an application deployment. + * This can be useful for verifying that in-development migration changes don't contain any validation-breaking changes + * of migrations that have already been applied to a production environment, e.g. as part of a CI/CD process, without + * failing because of the existence of new migration versions. + *
+ * {@code true} to continue normally, {@code false} to fail fast with an exception.
+ * (default: {@code false})
+ */
+ private boolean ignorePendingMigrations;
+
/**
* Ignore future migrations when reading the schema history table. These are migrations that were performed by a
* newer deployment of the application that are not yet available in this version. For example: we have migrations
@@ -484,6 +496,11 @@ public boolean isIgnoreIgnoredMigrations() {
return ignoreIgnoredMigrations;
}
+ @Override
+ public boolean isIgnorePendingMigrations() {
+ return ignorePendingMigrations;
+ }
+
@Override
public boolean isIgnoreFutureMigrations() {
return ignoreFutureMigrations;
@@ -828,6 +845,20 @@ public void setIgnoreMissingMigrations(boolean ignoreMissingMigrations) {
public void setIgnoreIgnoredMigrations(boolean ignoreIgnoredMigrations) {
this.ignoreIgnoredMigrations = ignoreIgnoredMigrations;
}
+
+ /**
+ * Ignore pending migrations when reading the schema history table. These are migrations that are available on the
+ * classpath but have not yet been performed by an application deployment. This can be useful for verifying
+ * that in-development migration changes don't contain any validation-breaking changes of migrations that have
+ * already been applied to a production environment, e.g. as part of a CI/CD process, without failing because of the
+ * existence of new migration versions.
+ *
+ * @param ignorePendingMigrations {@code true} to continue normally, {@code false} to fail fast with an exception.
+ * (default: {@code false})
+ */
+ public void setIgnorePendingMigrations(boolean ignorePendingMigrations) {
+ this.ignorePendingMigrations = ignorePendingMigrations;
+ }
/**
* Whether to ignore future migrations when reading the schema history table. These are migrations that were performed by a
@@ -1396,6 +1427,7 @@ public void configure(Configuration configuration) {
setIgnoreFutureMigrations(configuration.isIgnoreFutureMigrations());
setIgnoreMissingMigrations(configuration.isIgnoreMissingMigrations());
setIgnoreIgnoredMigrations(configuration.isIgnoreIgnoredMigrations());
+ setIgnorePendingMigrations(configuration.isIgnorePendingMigrations());
setInstalledBy(configuration.getInstalledBy());
setLocations(configuration.getLocations());
setMixed(configuration.isMixed());
@@ -1552,6 +1584,10 @@ public void configure(Map
+ * {@code true} to continue normally, {@code false} to fail fast with an exception.
+ * (default: {@code false})
+ */
+ public Boolean ignorePendingMigrations;
+
/**
* Ignore future migrations when reading the schema history table. These are migrations that were performed by a
* newer deployment of the application that are not yet available in this version. For example: we have migrations
diff --git a/flyway-gradle-plugin/src/main/java/org/flywaydb/gradle/task/AbstractFlywayTask.java b/flyway-gradle-plugin/src/main/java/org/flywaydb/gradle/task/AbstractFlywayTask.java
index 9811c0fc75..363f368b22 100644
--- a/flyway-gradle-plugin/src/main/java/org/flywaydb/gradle/task/AbstractFlywayTask.java
+++ b/flyway-gradle-plugin/src/main/java/org/flywaydb/gradle/task/AbstractFlywayTask.java
@@ -273,6 +273,18 @@ public abstract class AbstractFlywayTask extends DefaultTask {
*/
public Boolean ignoreIgnoredMigrations;
+ /**
+ * Ignore pending migrations when reading the schema history table. These are migrations that are available on the
+ * classpath but have not yet been performed by an application deployment. This can be useful for verifying
+ * that in-development migration changes don't contain any validation-breaking changes of migrations that have
+ * already been applied to a production environment, e.g. as part of a CI/CD process, without failing because of the
+ * existence of new migration versions.
+ *
+ * {@code true} to continue normally, {@code false} to fail fast with an exception.
+ * (default: {@code false})
+ */
+ public Boolean ignorePendingMigrations;
+
/**
* Ignore future migrations when reading the schema history table. These are migrations that were performed by a
* newer deployment of the application that are not yet available in this version. For example: we have migrations
@@ -551,6 +563,7 @@ private Map
+ * {@code true} to continue normally, {@code false} to fail fast with an exception.
+ * (default: {@code false})
+ */
+ @Parameter(property = ConfigUtils.IGNORE_PENDING_MIGRATIONS)
+ private Boolean ignorePendingMigrations;
+
/**
* Ignore future migrations when reading the schema history table. These are migrations that were performed by a
* newer deployment of the application that are not yet available in this version. For example: we have migrations