Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #16405 from gastaldi/init_sql
Support Flyway's initSql property to specify SQL to run
- Loading branch information
Showing
7 changed files
with
88 additions
and
0 deletions.
There are no files selected for viewing
45 changes: 45 additions & 0 deletions
45
...ns/flyway/deployment/src/test/java/io/quarkus/flyway/test/FlywayExtensionInitSqlTest.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,45 @@ | ||
package io.quarkus.flyway.test; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
import java.sql.Connection; | ||
import java.sql.PreparedStatement; | ||
import java.sql.ResultSet; | ||
import java.sql.SQLException; | ||
|
||
import javax.inject.Inject; | ||
import javax.sql.DataSource; | ||
|
||
import org.jboss.shrinkwrap.api.ShrinkWrap; | ||
import org.jboss.shrinkwrap.api.spec.JavaArchive; | ||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import io.quarkus.test.QuarkusUnitTest; | ||
|
||
public class FlywayExtensionInitSqlTest { | ||
// Quarkus built object | ||
@Inject | ||
DataSource datasource; | ||
|
||
@RegisterExtension | ||
static final QuarkusUnitTest config = new QuarkusUnitTest() | ||
.setArchiveProducer(() -> ShrinkWrap.create(JavaArchive.class) | ||
.addAsResource("db/migration/V1.0.0__Quarkus.sql") | ||
.addAsResource("init-sql-config.properties", "application.properties")); | ||
|
||
@Test | ||
@DisplayName("Check if initSql is invoked") | ||
public void testFlywayInitSql() throws SQLException { | ||
int var = 0; | ||
try (Connection con = datasource.getConnection(); | ||
PreparedStatement ps = con.prepareStatement("SELECT ONE_HUNDRED"); | ||
ResultSet rs = ps.executeQuery()) { | ||
if (rs.next()) { | ||
var = rs.getInt(1); | ||
} | ||
} | ||
assertEquals(100, var, "Init SQL was not executed"); | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
extensions/flyway/deployment/src/test/resources/init-sql-config.properties
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,8 @@ | ||
quarkus.datasource.db-kind=h2 | ||
quarkus.datasource.username=sa | ||
quarkus.datasource.password=sa | ||
quarkus.datasource.jdbc.url=jdbc:h2:tcp://localhost/mem:test-quarkus-migrate-at-start;DB_CLOSE_DELAY=-1 | ||
|
||
# Flyway config properties | ||
quarkus.flyway.migrate-at-start=true | ||
quarkus.flyway.init-sql=CREATE CONSTANT IF NOT EXISTS ONE_HUNDRED VALUE 100 |
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
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