diff --git a/bom/application/pom.xml b/bom/application/pom.xml index fbbf4e3f737e9..d8341e4647167 100644 --- a/bom/application/pom.xml +++ b/bom/application/pom.xml @@ -156,7 +156,7 @@ 3.2.0 4.2.0 1.0.10 - 8.5.13 + 9.1.0 1.0.11 4.14.0 1.30 diff --git a/extensions/flyway/deployment/src/main/java/io/quarkus/flyway/FlywayProcessor.java b/extensions/flyway/deployment/src/main/java/io/quarkus/flyway/FlywayProcessor.java index f622167746dba..3593fa1c8bcc1 100644 --- a/extensions/flyway/deployment/src/main/java/io/quarkus/flyway/FlywayProcessor.java +++ b/extensions/flyway/deployment/src/main/java/io/quarkus/flyway/FlywayProcessor.java @@ -25,6 +25,7 @@ import org.flywaydb.core.api.Location; import org.flywaydb.core.api.callback.Callback; import org.flywaydb.core.api.migration.JavaMigration; +import org.flywaydb.core.extensibility.Plugin; import org.jboss.jandex.ClassInfo; import org.jboss.jandex.DotName; import org.jboss.logging.Logger; @@ -51,6 +52,7 @@ import io.quarkus.deployment.builditem.nativeimage.NativeImageResourceBuildItem; import io.quarkus.deployment.builditem.nativeimage.ReflectiveClassBuildItem; import io.quarkus.deployment.builditem.nativeimage.RuntimeReinitializedClassBuildItem; +import io.quarkus.deployment.builditem.nativeimage.ServiceProviderBuildItem; import io.quarkus.deployment.logging.LoggingSetupBuildItem; import io.quarkus.deployment.recording.RecorderContext; import io.quarkus.flyway.runtime.FlywayBuildTimeConfig; @@ -289,6 +291,11 @@ public NativeImageResourceBuildItem resources() { return new NativeImageResourceBuildItem("org/flywaydb/database/version.txt"); } + @BuildStep + public ServiceProviderBuildItem flywayPlugins() { + return ServiceProviderBuildItem.allProvidersFromClassPath(Plugin.class.getName()); + } + public static final class MigrationStateBuildItem extends SimpleBuildItem { final Set hasMigrations; diff --git a/extensions/flyway/deployment/src/test/java/io/quarkus/flyway/test/FlywayExtensionCleanAndMigrateAtStartWithJavaMigrationTest.java b/extensions/flyway/deployment/src/test/java/io/quarkus/flyway/test/FlywayExtensionCleanAndMigrateAtStartWithJavaMigrationTest.java index 0426a945334dc..b491b69b54d91 100644 --- a/extensions/flyway/deployment/src/test/java/io/quarkus/flyway/test/FlywayExtensionCleanAndMigrateAtStartWithJavaMigrationTest.java +++ b/extensions/flyway/deployment/src/test/java/io/quarkus/flyway/test/FlywayExtensionCleanAndMigrateAtStartWithJavaMigrationTest.java @@ -78,11 +78,6 @@ public Integer getChecksum() { return null; } - @Override - public boolean isUndo() { - return false; - } - @Override public boolean canExecuteInTransaction() { return true; @@ -94,11 +89,6 @@ public void migrate(Context context) throws Exception { statement.executeUpdate("INSERT INTO quarked_flyway VALUES (1002, 'test')"); } } - - @Override - public boolean isBaselineMigration() { - return false; - } } } diff --git a/extensions/flyway/deployment/src/test/java/io/quarkus/flyway/test/FlywayExtensionFilesystemResourceTest.java b/extensions/flyway/deployment/src/test/java/io/quarkus/flyway/test/FlywayExtensionFilesystemResourceTest.java index e81138661eeaa..49d761832b0ae 100644 --- a/extensions/flyway/deployment/src/test/java/io/quarkus/flyway/test/FlywayExtensionFilesystemResourceTest.java +++ b/extensions/flyway/deployment/src/test/java/io/quarkus/flyway/test/FlywayExtensionFilesystemResourceTest.java @@ -84,11 +84,6 @@ public Integer getChecksum() { return null; } - @Override - public boolean isUndo() { - return false; - } - @Override public boolean canExecuteInTransaction() { return true; @@ -100,11 +95,6 @@ public void migrate(Context context) throws Exception { statement.executeUpdate("INSERT INTO quarked_flyway VALUES (1002, 'test')"); } } - - @Override - public boolean isBaselineMigration() { - return false; - } } } 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 328a05a03487f..779b5394279bf 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 @@ -1,8 +1,10 @@ package io.quarkus.flyway.runtime; +import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; import java.util.Collections; +import java.util.List; import javax.sql.DataSource; @@ -57,8 +59,17 @@ public Flyway createFlyway(DataSource dataSource) { configure.cleanDisabled(flywayRuntimeConfig.cleanDisabled); configure.baselineOnMigrate(flywayRuntimeConfig.baselineOnMigrate); configure.validateOnMigrate(flywayRuntimeConfig.validateOnMigrate); - configure.ignoreMissingMigrations(flywayRuntimeConfig.ignoreMissingMigrations); - configure.ignoreFutureMigrations(flywayRuntimeConfig.ignoreFutureMigrations); + 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"); + } + // Default is *:Future + configure.ignoreMigrationPatterns(patterns.toArray(new String[0])); 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 1b49e442622c0..721093f336099 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 @@ -180,4 +180,11 @@ public static final FlywayDataSourceRuntimeConfig defaultConfig() { */ @ConfigItem public Optional initSql = Optional.empty(); + + /** + * 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. + */ + @ConfigItem + public boolean validateMigrationNaming; } 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 825f3b84ee360..21decf5b03779 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 @@ -15,6 +15,7 @@ import org.flywaydb.core.Flyway; import org.flywaydb.core.api.Location; import org.flywaydb.core.api.configuration.Configuration; +import org.flywaydb.core.internal.util.ValidatePatternUtils; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; @@ -200,11 +201,11 @@ void testOutOfOrder() { void testIgnoreMissingMigrations() { runtimeConfig.ignoreMissingMigrations = false; creator = new FlywayCreator(runtimeConfig, buildConfig); - assertFalse(createdFlywayConfig().isIgnoreMissingMigrations()); + assertFalse(ValidatePatternUtils.isMissingIgnored(createdFlywayConfig().getIgnoreMigrationPatterns())); runtimeConfig.ignoreMissingMigrations = true; creator = new FlywayCreator(runtimeConfig, buildConfig); - assertTrue(createdFlywayConfig().isIgnoreMissingMigrations()); + assertTrue(ValidatePatternUtils.isMissingIgnored(createdFlywayConfig().getIgnoreMigrationPatterns())); } @Test @@ -212,11 +213,11 @@ void testIgnoreMissingMigrations() { void testIgnoreFutureMigrations() { runtimeConfig.ignoreFutureMigrations = false; creator = new FlywayCreator(runtimeConfig, buildConfig); - assertFalse(createdFlywayConfig().isIgnoreFutureMigrations()); + assertFalse(ValidatePatternUtils.isFutureIgnored(createdFlywayConfig().getIgnoreMigrationPatterns())); runtimeConfig.ignoreFutureMigrations = true; creator = new FlywayCreator(runtimeConfig, buildConfig); - assertTrue(createdFlywayConfig().isIgnoreFutureMigrations()); + assertTrue(ValidatePatternUtils.isFutureIgnored(createdFlywayConfig().getIgnoreMigrationPatterns())); } @Test @@ -245,6 +246,18 @@ void testValidateOnMigrateOverwritten(final boolean input, final boolean expecte assertEquals(runtimeConfig.validateOnMigrate, expected); } + @Test + @DisplayName("validateMigrationNaming defaults to false and it is correctly set") + void testValidateMigrationNaming() { + creator = new FlywayCreator(runtimeConfig, buildConfig); + assertEquals(runtimeConfig.validateMigrationNaming, createdFlywayConfig().isValidateMigrationNaming()); + assertFalse(runtimeConfig.validateMigrationNaming); + + runtimeConfig.validateMigrationNaming = true; + creator = new FlywayCreator(runtimeConfig, buildConfig); + assertTrue(createdFlywayConfig().isValidateMigrationNaming()); + } + private static List pathList(Location[] locations) { return Stream.of(locations).map(Location::getPath).collect(Collectors.toList()); }