diff --git a/extensions/flyway/runtime/src/main/java/io/quarkus/flyway/runtime/FlywayCreator.java b/extensions/flyway/runtime/src/main/java/io/quarkus/flyway/runtime/FlywayCreator.java index 779b5394279bf2..47dc567decbafa 100644 --- a/extensions/flyway/runtime/src/main/java/io/quarkus/flyway/runtime/FlywayCreator.java +++ b/extensions/flyway/runtime/src/main/java/io/quarkus/flyway/runtime/FlywayCreator.java @@ -60,16 +60,23 @@ public Flyway createFlyway(DataSource dataSource) { configure.baselineOnMigrate(flywayRuntimeConfig.baselineOnMigrate); configure.validateOnMigrate(flywayRuntimeConfig.validateOnMigrate); configure.validateMigrationNaming(flywayRuntimeConfig.validateMigrationNaming); - List 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 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()) { diff --git a/extensions/flyway/runtime/src/main/java/io/quarkus/flyway/runtime/FlywayDataSourceRuntimeConfig.java b/extensions/flyway/runtime/src/main/java/io/quarkus/flyway/runtime/FlywayDataSourceRuntimeConfig.java index 721093f3360994..1382a586ac9708 100644 --- a/extensions/flyway/runtime/src/main/java/io/quarkus/flyway/runtime/FlywayDataSourceRuntimeConfig.java +++ b/extensions/flyway/runtime/src/main/java/io/quarkus/flyway/runtime/FlywayDataSourceRuntimeConfig.java @@ -187,4 +187,11 @@ public static final FlywayDataSourceRuntimeConfig defaultConfig() { */ @ConfigItem public boolean validateMigrationNaming; + + /** + * Ignore migrations during validate and repair according to a given list of patterns. + * Patterns are comma separated. + */ + @ConfigItem + public Optional ignoreMigrationPatterns; } diff --git a/extensions/flyway/runtime/src/test/java/io/quarkus/flyway/runtime/FlywayCreatorTest.java b/extensions/flyway/runtime/src/test/java/io/quarkus/flyway/runtime/FlywayCreatorTest.java index 21decf5b03779f..17764887791ed8 100644 --- a/extensions/flyway/runtime/src/test/java/io/quarkus/flyway/runtime/FlywayCreatorTest.java +++ b/extensions/flyway/runtime/src/test/java/io/quarkus/flyway/runtime/FlywayCreatorTest.java @@ -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; @@ -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; @@ -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 pathList(Location[] locations) { return Stream.of(locations).map(Location::getPath).collect(Collectors.toList()); }