-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make Quarkus restart when a change to Flyway scripts is made
Adds watches to any existing Flyway migration scripts. This doesn't yet fully address #25256 (as this issue primarily is about the use case of adding new migration scripts), but at least the developer can now continue editing existing migration scripts. Related issue: #25256 (cherry picked from commit 913308b)
- Loading branch information
1 parent
72e8481
commit 083e22b
Showing
4 changed files
with
80 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
...way/deployment/src/test/java/io/quarkus/flyway/test/FlywayDevModeModifyMigrationTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package io.quarkus.flyway.test; | ||
|
||
import static org.hamcrest.Matchers.is; | ||
|
||
import java.sql.Connection; | ||
import java.sql.ResultSet; | ||
import java.sql.SQLException; | ||
import java.sql.Statement; | ||
import java.util.function.Function; | ||
|
||
import javax.inject.Inject; | ||
import javax.ws.rs.GET; | ||
import javax.ws.rs.Path; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import io.agroal.api.AgroalDataSource; | ||
import io.quarkus.test.QuarkusDevModeTest; | ||
import io.restassured.RestAssured; | ||
|
||
public class FlywayDevModeModifyMigrationTest { | ||
|
||
@RegisterExtension | ||
static final QuarkusDevModeTest config = new QuarkusDevModeTest() | ||
.withApplicationRoot((jar) -> jar | ||
.addClasses(RowCountEndpoint.class) | ||
.addAsResource("db/migration/V1.0.0__Quarkus.sql") | ||
.addAsResource("clean-and-migrate-at-start-config.properties", "application.properties")); | ||
|
||
@Test | ||
public void testModifyingExistingMigrationScriptCausesRestart() { | ||
RestAssured.get("/row-count").then().statusCode(200).body(is("0")); | ||
config.modifyResourceFile("db/migration/V1.0.0__Quarkus.sql", new Function<String, String>() { | ||
@Override | ||
public String apply(String s) { | ||
return s + '\n' + "INSERT INTO quarked_flyway VALUES (1001, 'test')"; | ||
} | ||
}); | ||
RestAssured.get("/row-count").then().statusCode(200).body(is("1")); | ||
} | ||
|
||
@Path("/row-count") | ||
public static class RowCountEndpoint { | ||
|
||
@Inject | ||
AgroalDataSource dataSource; | ||
|
||
@GET | ||
public int rowCount() throws SQLException { | ||
try (Connection connection = dataSource.getConnection(); Statement stat = connection.createStatement()) { | ||
try (ResultSet countQuery = stat.executeQuery("select count(1) from quarked_flyway")) { | ||
return countQuery.first() ? countQuery.getInt(1) : 0; | ||
} | ||
} | ||
} | ||
} | ||
} |