Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for ignoreMigrationPatterns config in Flyway #27181

Merged
merged 1 commit into from
Aug 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -60,16 +60,23 @@ public Flyway createFlyway(DataSource dataSource) {
configure.baselineOnMigrate(flywayRuntimeConfig.baselineOnMigrate);
configure.validateOnMigrate(flywayRuntimeConfig.validateOnMigrate);
configure.validateMigrationNaming(flywayRuntimeConfig.validateMigrationNaming);
List<String> patterns = new ArrayList<>(2);
//https://flywaydb.org/documentation/configuration/parameters/ignoreMigrationPatterns
if (flywayRuntimeConfig.ignoreMissingMigrations) {
patterns.add("*:Missing");
}
if (flywayRuntimeConfig.ignoreFutureMigrations) {
patterns.add("*:Future");

final String[] ignoreMigrationPatterns;
if (flywayRuntimeConfig.ignoreMigrationPatterns.isPresent()) {
ignoreMigrationPatterns = flywayRuntimeConfig.ignoreMigrationPatterns.get();
} else {
List<String> patterns = new ArrayList<>(2);
if (flywayRuntimeConfig.ignoreMissingMigrations) {
patterns.add("*:Missing");
}
if (flywayRuntimeConfig.ignoreFutureMigrations) {
patterns.add("*:Future");
}
// Default is *:Future
ignoreMigrationPatterns = patterns.toArray(new String[0]);
}
// Default is *:Future
configure.ignoreMigrationPatterns(patterns.toArray(new String[0]));

configure.ignoreMigrationPatterns(ignoreMigrationPatterns);
configure.cleanOnValidationError(flywayRuntimeConfig.cleanOnValidationError);
configure.outOfOrder(flywayRuntimeConfig.outOfOrder);
if (flywayRuntimeConfig.baselineVersion.isPresent()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,4 +187,13 @@ public static final FlywayDataSourceRuntimeConfig defaultConfig() {
*/
@ConfigItem
public boolean validateMigrationNaming;

/**
* Ignore migrations during validate and repair according to a given list of patterns (see
* https://flywaydb.org/documentation/configuration/parameters/ignoreMigrationPatterns for more information).
* When this configuration is set, the ignoreFutureMigrations and ignoreMissingMigrations settings are ignored. Patterns are
* comma separated.
*/
@ConfigItem
public Optional<String[]> ignoreMigrationPatterns = Optional.empty();
tmihalac marked this conversation as resolved.
Show resolved Hide resolved
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package io.quarkus.flyway.runtime;

import static java.util.Arrays.asList;
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
Expand All @@ -15,6 +16,7 @@
import org.flywaydb.core.Flyway;
import org.flywaydb.core.api.Location;
import org.flywaydb.core.api.configuration.Configuration;
import org.flywaydb.core.api.pattern.ValidatePattern;
import org.flywaydb.core.internal.util.ValidatePatternUtils;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
Expand Down Expand Up @@ -258,6 +260,23 @@ void testValidateMigrationNaming() {
assertTrue(createdFlywayConfig().isValidateMigrationNaming());
}

@Test
@DisplayName("validateIgnoreMigrationPatterns defaults to false and it is correctly set")
void testIgnoreMigrationPatterns() {
creator = new FlywayCreator(runtimeConfig, buildConfig);
assertEquals(0, createdFlywayConfig().getIgnoreMigrationPatterns().length);
assertFalse(runtimeConfig.ignoreMigrationPatterns.isPresent());

runtimeConfig.ignoreMigrationPatterns = Optional.of(new String[] { "*:missing" });
creator = new FlywayCreator(runtimeConfig, buildConfig);
final ValidatePattern[] existingIgnoreMigrationPatterns = createdFlywayConfig().getIgnoreMigrationPatterns();
assertEquals(1, existingIgnoreMigrationPatterns.length);
final String[] ignoreMigrationPatterns = runtimeConfig.ignoreMigrationPatterns.get();
final ValidatePattern[] validatePatterns = Arrays.stream(ignoreMigrationPatterns)
.map(ValidatePattern::fromPattern).toArray(ValidatePattern[]::new);
assertArrayEquals(validatePatterns, existingIgnoreMigrationPatterns);
}

private static List<String> pathList(Location[] locations) {
return Stream.of(locations).map(Location::getPath).collect(Collectors.toList());
}
Expand Down