Skip to content

Commit

Permalink
add new ignoreRepeatableMigrations and ignoreVersionedMigrations
Browse files Browse the repository at this point in the history
…params
  • Loading branch information
James Johnston committed Apr 15, 2021
1 parent c60e0b3 commit 80e2006
Show file tree
Hide file tree
Showing 16 changed files with 257 additions and 766 deletions.
7 changes: 7 additions & 0 deletions flyway-commandline/src/main/assembly/flyway.conf
Expand Up @@ -289,6 +289,13 @@ flyway.locations=filesystem:sql
# true to continue normally and log a warning, false to fail fast with an exception. (default: true)
# flyway.ignoreFutureMigrations=

# Ignore migrations that match this comma-separated list of patterns when validating migrations.
# Each pattern is of the form <migration_type>:<migration_state>
# See https://flywaydb.org/documentation/configuration/parameters/ignoreMigrationPatterns for full details
# Example: repeatable:missing,versioned:pending,*:failed
# Flyway Teams only
# flyway.ignoreMigrationPatterns=

# Whether to validate migrations and callbacks whose scripts do not obey the correct naming convention. A failure can be
# useful to check that errors such as case sensitivity in migration prefixes have been corrected.
# false to continue normally, true to fail fast with an exception (default: false)
Expand Down
Expand Up @@ -199,18 +199,18 @@ private static Map<String, String> overrideConfiguration(Map<String, String> exi
}

static String getMessagesFromException(Throwable e) {
String condensedMessages = "";
StringBuilder condensedMessages = new StringBuilder();
String preamble = "";
while (e != null) {
if (e instanceof FlywayException) {
condensedMessages += preamble + e.getMessage();
condensedMessages.append(preamble).append(e.getMessage());
} else {
condensedMessages += preamble + e.toString();
condensedMessages.append(preamble).append(e);
}
preamble = "\r\nCaused by: ";
e = e.getCause();
}
return condensedMessages;
return condensedMessages.toString();
}

private static OperationResultBase executeOperation(Flyway flyway, String operation, CommandLineArguments commandLineArguments) {
Expand Down Expand Up @@ -378,6 +378,7 @@ private static void printUsage() {
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("ignoreMigrationPatterns : [" + "teams] Patterns of migrations and states to ignore during validate");
LOG.info("cleanOnValidationError : Automatically clean on a validation error");
LOG.info("cleanDisabled : Whether to disable clean");
LOG.info("baselineVersion : Version to tag schema with when executing baseline");
Expand Down Expand Up @@ -414,11 +415,7 @@ private static void printUsage() {

private static List<File> getJdbcDriverJarFiles() {
File driversDir = new File(getInstallationDir(), "drivers");
File[] files = driversDir.listFiles(new FilenameFilter() {
public boolean accept(File dir, String name) {
return name.endsWith(".jar");
}
});
File[] files = driversDir.listFiles((dir, name) -> name.endsWith(".jar"));

// see javadoc of listFiles(): null if given path is not a real directory
if (files == null) {
Expand All @@ -441,11 +438,7 @@ private static List<File> getJavaMigrationJarFiles(Map<String, String> config) {
List<File> jarFiles = new ArrayList<>();
for (String dirName : dirs) {
File dir = new File(dirName);
File[] files = dir.listFiles(new FilenameFilter() {
public boolean accept(File dir, String name) {
return name.endsWith(".jar");
}
});
File[] files = dir.listFiles((dir1, name) -> name.endsWith(".jar"));

// see javadoc of listFiles(): null if given path is not a real directory
if (files == null) {
Expand Down
9 changes: 3 additions & 6 deletions flyway-core/src/main/java/org/flywaydb/core/Flyway.java
Expand Up @@ -570,14 +570,11 @@ public void initialize(JdbcConnectionFactory jdbcConnectionFactory, Connection c

result = command.execute(
createMigrationResolver(resourceProvider, classProvider, sqlScriptExecutorFactory, sqlScriptFactory, parsingContext),
SchemaHistoryFactory.getSchemaHistory(configuration, noCallbackSqlScriptExecutorFactory, sqlScriptFactory,
database, defaultSchema,
statementInterceptor
),
SchemaHistoryFactory.getSchemaHistory(configuration, noCallbackSqlScriptExecutorFactory, sqlScriptFactory, database, defaultSchema, statementInterceptor),
database,
schemas.getRight().toArray(new Schema[0]),
callbackExecutor, statementInterceptor
);
callbackExecutor,
statementInterceptor);
} finally {
IOUtils.close(database);

Expand Down
95 changes: 22 additions & 73 deletions flyway-core/src/main/java/org/flywaydb/core/api/MigrationState.java
Expand Up @@ -23,175 +23,124 @@ public enum MigrationState {
* This migration has not been applied yet.
*/
PENDING("Pending", true, false, false),

/**
* This migration has not been applied yet, and won't be applied because target is set to a lower version.
*/
ABOVE_TARGET("Above Target", true, false, false),

/**
* This migration was not applied against this DB, because the schema history table was baselined with a higher version.
*/
BELOW_BASELINE("Below Baseline", true, false, false),

/**
* This migration has baselined this DB.
*/
BASELINE("Baseline", true, true, false),

/**
* <p>When using cherryPick, this indicates a migration that was not in the cherry picked list.</p>
* <p>When not using cherryPick, this usually indicates a problem.</p>
* <p>
* When using cherryPick, this indicates a migration that was not in the cherry picked list.
* When not using cherryPick, this usually indicates a problem.
*
* This migration was not applied against this DB, because a migration with a higher version has already been
* applied. This probably means some checkins happened out of order.
* </p>
* <p>Fix by increasing the version number, run clean and migrate again or rerun migration with outOfOrder enabled.</p>
*
* Fix by increasing the version number, run clean and migrate again or rerun migration with outOfOrder enabled.
*/
IGNORED("Ignored", true, false, false),

/**
* <p>This migration succeeded.</p>
* <p>
* This migration succeeded.
*
* This migration was applied against this DB, but it is not available locally.
* This usually results from multiple older migration files being consolidated into a single one.
* </p>
*
*/
MISSING_SUCCESS("Missing", false, true, false),

/**
* <p>This migration failed.</p>
* <p>
* This migration failed.
*
* This migration was applied against this DB, but it is not available locally.
* This usually results from multiple older migration files being consolidated into a single one.
* </p>
* <p>This should rarely, if ever, occur in practice.</p>
*
* This should rarely, if ever, occur in practice.
*/
MISSING_FAILED("Failed (Missing)", false, true, true),

/**
* This migration succeeded.
*/
SUCCESS("Success", true, true, false),

/**
* This versioned migration succeeded, but has since been undone.
*/
UNDONE("Undone", true, true, false),

/**
* This undo migration is ready to be applied if desired.
*/
AVAILABLE("Available", true, false, false),

/**
* This migration failed.
*/
FAILED("Failed", true, true, true),

/**
* <p>This migration succeeded.</p>
* <p>
* This migration succeeded.
*
* This migration succeeded, but it was applied out of order.
* Rerunning the entire migration history might produce different results!
* </p>
*
*/
OUT_OF_ORDER("Out of Order", true, true, false),

/**
* <p>This migration succeeded.</p>
* <p>
* This migration succeeded.
*
* This migration has been applied against the DB, but it is not available locally.
* Its version is higher than the highest version available locally.
* It was most likely successfully installed by a future version of this deployable.
* </p>
*
*/
FUTURE_SUCCESS("Future", false, true, false),

/**
* <p>This migration failed.</p>
* <p>
* This migration failed.
*
* This migration has been applied against the DB, but it is not available locally.
* Its version is higher than the highest version available locally.
* It most likely failed during the installation of a future version of this deployable.
* </p>
*
*/
FUTURE_FAILED("Failed (Future)", false, true, true),

/**
* This is a repeatable migration that is outdated and should be re-applied.
*/
OUTDATED("Outdated", true, true, false),

/**
* This is a repeatable migration that is outdated and has already been superseded by a newer run.
*/
SUPERSEDED("Superseded", true, true, false),

/**
* This is a migration that has been marked as deleted
* This is a migration that has been marked as deleted.
*/
DELETED("Deleted", false, true, false);

/**
* The name suitable for display to the end-user.
*/
private final String displayName;

/**
* Flag indicating if this migration is available on the classpath or not.
*/
private final boolean resolved;

/**
* Flag indicating if this migration has been applied or not.
*/
private final boolean applied;

/**
* Flag indicating if this migration has failed when it was applied or not.
*/
private final boolean failed;

/**
* Creates a new MigrationState.
*
* @param displayName The name suitable for display to the end-user.
* @param resolved Flag indicating if this migration is available on the classpath or not.
* @param applied Flag indicating if this migration has been applied or not.
* @param failed Flag indicating if this migration has failed when it was applied or not.
*/
MigrationState(String displayName, boolean resolved, boolean applied, boolean failed) {
this.displayName = displayName;
this.resolved = resolved;
this.applied = applied;
this.failed = failed;
}

/**
* @return The name suitable for display to the end-user.
*/
public String getDisplayName() {
return displayName;
}

/**
* @return Flag indicating if this migration has been applied or not.
*/
public boolean isApplied() {
return applied;
}

/**
* @return Flag indicating if this migration has been resolved or not.
*/
public boolean isResolved() {
return resolved;
}

/**
* @return Flag indicating if this migration has failed or not.
*/
public boolean isFailed() {
return failed;
}
Expand Down

0 comments on commit 80e2006

Please sign in to comment.