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 412b185a89f26..e7e963741f427 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 @@ -120,7 +120,9 @@ MigrationStateBuildItem build(BuildProducer featureProducer, Location applicationMigrationLocation = new Location(applicationMigration); String applicationMigrationPath = applicationMigrationLocation.getPath(); - if (applicationMigrationPath != null) { + if ((applicationMigrationPath != null) && + // we don't include .class files in the watched files because that messes up live reload + !applicationMigrationPath.endsWith(".class")) { hotDeploymentProducer.produce(new HotDeploymentWatchedFileBuildItem(applicationMigrationPath)); } } diff --git a/extensions/flyway/deployment/src/test/java/io/quarkus/flyway/test/FlywayExtensionWithJavaMigrationDevModeTest.java b/extensions/flyway/deployment/src/test/java/io/quarkus/flyway/test/FlywayExtensionWithJavaMigrationDevModeTest.java new file mode 100644 index 0000000000000..f011ca1c37f6c --- /dev/null +++ b/extensions/flyway/deployment/src/test/java/io/quarkus/flyway/test/FlywayExtensionWithJavaMigrationDevModeTest.java @@ -0,0 +1,40 @@ +package io.quarkus.flyway.test; + +import static io.restassured.RestAssured.get; +import static org.hamcrest.Matchers.is; + +import java.sql.SQLException; + +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.RegisterExtension; + +import db.migration.V1_0_1__Update; +import db.migration.V1_0_2__Update; +import io.quarkus.test.QuarkusDevModeTest; + +public class FlywayExtensionWithJavaMigrationDevModeTest { + + @RegisterExtension + static final QuarkusDevModeTest config = new QuarkusDevModeTest() + .withApplicationRoot((jar) -> jar + .addClasses(V1_0_1__Update.class, V1_0_2__Update.class, + FlywayExtensionWithJavaMigrationDevModeTestEndpoint.class) + .addAsResource("db/migration/V1.0.0__Quarkus.sql") + .addAsResource("clean-and-migrate-at-start-config.properties", "application.properties")); + + @Test + public void test() throws SQLException { + get("/fly") + .then() + .statusCode(200) + .body(is("2/1.0.2")); + + config.modifySourceFile(FlywayExtensionWithJavaMigrationDevModeTestEndpoint.class, s -> s.replace("/fly", "/flyway")); + + get("/flyway") + .then() + .statusCode(200) + .body(is("2/1.0.2")); + } + +} diff --git a/extensions/flyway/deployment/src/test/java/io/quarkus/flyway/test/FlywayExtensionWithJavaMigrationDevModeTestEndpoint.java b/extensions/flyway/deployment/src/test/java/io/quarkus/flyway/test/FlywayExtensionWithJavaMigrationDevModeTestEndpoint.java new file mode 100644 index 0000000000000..d30349f0ded52 --- /dev/null +++ b/extensions/flyway/deployment/src/test/java/io/quarkus/flyway/test/FlywayExtensionWithJavaMigrationDevModeTestEndpoint.java @@ -0,0 +1,37 @@ +package io.quarkus.flyway.test; + +import java.sql.Connection; +import java.sql.ResultSet; +import java.sql.Statement; + +import jakarta.inject.Inject; +import jakarta.ws.rs.GET; +import jakarta.ws.rs.Path; + +import org.flywaydb.core.Flyway; + +import io.agroal.api.AgroalDataSource; + +@Path("/fly") +public class FlywayExtensionWithJavaMigrationDevModeTestEndpoint { + + @Inject + AgroalDataSource defaultDataSource; + + @Inject + Flyway flyway; + + @GET + public String result() throws Exception { + int count = 0; + try (Connection connection = defaultDataSource.getConnection(); Statement stat = connection.createStatement()) { + try (ResultSet countQuery = stat.executeQuery("select count(1) from quarked_flyway")) { + countQuery.first(); + count = countQuery.getInt(1); + } + } + String currentVersion = flyway.info().current().getVersion().toString(); + + return count + "/" + currentVersion; + } +}