From 7e23cf507d30cbd32e5aa65102d0fc519ab6264f Mon Sep 17 00:00:00 2001 From: Georgios Andrianakis Date: Tue, 10 Oct 2023 10:00:58 +0300 Subject: [PATCH] Fix issue in Java migration in dev-mode Fixes: #36299 --- .../flyway/deployment/FlywayProcessor.java | 4 +- ...ExtensionWithJavaMigrationDevModeTest.java | 40 +++++++++++++++++++ ...nWithJavaMigrationDevModeTestEndpoint.java | 37 +++++++++++++++++ 3 files changed, 80 insertions(+), 1 deletion(-) create mode 100644 extensions/flyway/deployment/src/test/java/io/quarkus/flyway/test/FlywayExtensionWithJavaMigrationDevModeTest.java create mode 100644 extensions/flyway/deployment/src/test/java/io/quarkus/flyway/test/FlywayExtensionWithJavaMigrationDevModeTestEndpoint.java diff --git a/extensions/flyway/deployment/src/main/java/io/quarkus/flyway/deployment/FlywayProcessor.java b/extensions/flyway/deployment/src/main/java/io/quarkus/flyway/deployment/FlywayProcessor.java index ecd2439175b89..91e602ab8bc5a 100644 --- a/extensions/flyway/deployment/src/main/java/io/quarkus/flyway/deployment/FlywayProcessor.java +++ b/extensions/flyway/deployment/src/main/java/io/quarkus/flyway/deployment/FlywayProcessor.java @@ -117,7 +117,9 @@ MigrationStateBuildItem build(BuildProducer resour 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; + } +}