Skip to content

Commit

Permalink
Fix issue in Java migration in dev-mode
Browse files Browse the repository at this point in the history
  • Loading branch information
geoand committed Oct 10, 2023
1 parent f64aaf4 commit 7e23cf5
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,9 @@ MigrationStateBuildItem build(BuildProducer<NativeImageResourceBuildItem> 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));
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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"));
}

}
Original file line number Diff line number Diff line change
@@ -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;
}
}

0 comments on commit 7e23cf5

Please sign in to comment.