Skip to content

Commit

Permalink
Merge pull request #2129 from yjo/ignore-pending-migrations-option
Browse files Browse the repository at this point in the history
Add an 'ignorePendingMigrations' configuration option
  • Loading branch information
Axel Fontaine committed Sep 19, 2018
2 parents eb00b3a + 9031c92 commit 498fba7
Show file tree
Hide file tree
Showing 10 changed files with 150 additions and 3 deletions.
7 changes: 7 additions & 0 deletions flyway-commandline/src/main/assembly/flyway.conf
Expand Up @@ -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
Expand Down
Expand Up @@ -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");
Expand Down
33 changes: 30 additions & 3 deletions flyway-core/src/main/java/org/flywaydb/core/Flyway.java
Expand Up @@ -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.
*/
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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(),
Expand Down
Expand Up @@ -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.
* <p>
* {@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
Expand Down Expand Up @@ -484,6 +496,11 @@ public boolean isIgnoreIgnoredMigrations() {
return ignoreIgnoredMigrations;
}

@Override
public boolean isIgnorePendingMigrations() {
return ignorePendingMigrations;
}

@Override
public boolean isIgnoreFutureMigrations() {
return ignoreFutureMigrations;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -1552,6 +1584,10 @@ public void configure(Map<String, String> props) {
if (ignoreIgnoredMigrationsProp != null) {
setIgnoreIgnoredMigrations(ignoreIgnoredMigrationsProp);
}
Boolean ignorePendingMigrationsProp = getBooleanProp(props, ConfigUtils.IGNORE_PENDING_MIGRATIONS);
if (ignorePendingMigrationsProp != null) {
setIgnorePendingMigrations(ignorePendingMigrationsProp);
}
Boolean ignoreFutureMigrationsProp = getBooleanProp(props, ConfigUtils.IGNORE_FUTURE_MIGRATIONS);
if (ignoreFutureMigrationsProp != null) {
setIgnoreFutureMigrations(ignoreFutureMigrationsProp);
Expand Down
Expand Up @@ -273,6 +273,18 @@ public interface Configuration {
*/
boolean isIgnoreIgnoredMigrations();

/**
* 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.
*
* @return {@code true} to continue normally, {@code false} to fail fast with an exception.
* (default: {@code false})
*/
boolean isIgnorePendingMigrations();

/**
* 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
Expand Down
Expand Up @@ -149,6 +149,11 @@ public boolean isIgnoreIgnoredMigrations() {
return config.isIgnoreIgnoredMigrations();
}

@Override
public boolean isIgnorePendingMigrations() {
return config.isIgnorePendingMigrations();
}

@Override
public boolean isIgnoreFutureMigrations() {
return config.isIgnoreFutureMigrations();
Expand Down Expand Up @@ -415,6 +420,21 @@ public FluentConfiguration ignoreIgnoredMigrations(boolean ignoreIgnoredMigratio
return this;
}

/**
* 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 FluentConfiguration ignorePendingMigrations(boolean ignorePendingMigrations) {
config.setIgnorePendingMigrations(ignorePendingMigrations);
return this;
}

/**
* 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
Expand Down
Expand Up @@ -78,6 +78,7 @@ public class ConfigUtils {
public static final String IGNORE_FUTURE_MIGRATIONS = "flyway.ignoreFutureMigrations";
public static final String IGNORE_MISSING_MIGRATIONS = "flyway.ignoreMissingMigrations";
public static final String IGNORE_IGNORED_MIGRATIONS = "flyway.ignoreIgnoredMigrations";
public static final String IGNORE_PENDING_MIGRATIONS = "flyway.ignorePendingMigrations";
public static final String INSTALLED_BY = "flyway.installedBy";
public static final String LICENSE_KEY = "flyway.licenseKey";
public static final String LOCATIONS = "flyway.locations";
Expand Down Expand Up @@ -266,6 +267,11 @@ public boolean isIgnoreIgnoredMigrations() {
return configuration.isIgnoreIgnoredMigrations();
}

@Override
public boolean isIgnorePendingMigrations() {
return configuration.isIgnorePendingMigrations();
}

@Override
public boolean isIgnoreFutureMigrations() {
return configuration.isIgnoreFutureMigrations();
Expand Down
Expand Up @@ -233,6 +233,18 @@ public class FlywayExtension {
*/
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.
* <p>
* {@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
Expand Down
Expand Up @@ -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.
* <p>
* {@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
Expand Down Expand Up @@ -551,6 +563,7 @@ private Map<String, String> createFlywayConfig(Map<String, String> envVars) {
putIfSet(conf, ConfigUtils.CLEAN_ON_VALIDATION_ERROR, cleanOnValidationError, extension.cleanOnValidationError);
putIfSet(conf, ConfigUtils.IGNORE_MISSING_MIGRATIONS, ignoreMissingMigrations, extension.ignoreMissingMigrations);
putIfSet(conf, ConfigUtils.IGNORE_IGNORED_MIGRATIONS, ignoreIgnoredMigrations, extension.ignoreIgnoredMigrations);
putIfSet(conf, ConfigUtils.IGNORE_PENDING_MIGRATIONS, ignorePendingMigrations, extension.ignorePendingMigrations);
putIfSet(conf, ConfigUtils.IGNORE_FUTURE_MIGRATIONS, ignoreFutureMigrations, extension.ignoreFutureMigrations);
putIfSet(conf, ConfigUtils.CLEAN_DISABLED, cleanDisabled, extension.cleanDisabled);
putIfSet(conf, ConfigUtils.BASELINE_ON_MIGRATE, baselineOnMigrate, extension.baselineOnMigrate);
Expand Down
Expand Up @@ -304,6 +304,19 @@ abstract class AbstractFlywayMojo extends AbstractMojo {
@Parameter(property = ConfigUtils.IGNORE_IGNORED_MIGRATIONS)
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.
* <p>
* {@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
Expand Down

0 comments on commit 498fba7

Please sign in to comment.