forked from quarkusio/quarkus
-
Notifications
You must be signed in to change notification settings - Fork 0
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 quarkusio#27744 from rmanibus/flyway_baseline_at_s…
…tart Add a config option to enable Flyway baseline feature
- Loading branch information
Showing
9 changed files
with
160 additions
and
4 deletions.
There are no files selected for viewing
40 changes: 40 additions & 0 deletions
40
.../io/quarkus/flyway/test/FlywayExtensionBaselineAtStartExistingSchemaHistoryTableTest.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,40 @@ | ||
package io.quarkus.flyway.test; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertNull; | ||
|
||
import jakarta.inject.Inject; | ||
|
||
import org.flywaydb.core.Flyway; | ||
import org.flywaydb.core.api.MigrationInfo; | ||
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 FlywayExtensionBaselineAtStartExistingSchemaHistoryTableTest { | ||
@Inject | ||
Flyway flyway; | ||
|
||
static final FlywayH2TestCustomizer customizer = FlywayH2TestCustomizer | ||
.withDbName("quarkus-baseline-at-start-existing-schema-history") | ||
.withPort(11309) | ||
.withInitSqlFile("src/test/resources/h2-init-schema-history-table.sql"); | ||
|
||
@RegisterExtension | ||
static final QuarkusUnitTest config = new QuarkusUnitTest() | ||
.setBeforeAllCustomizer(customizer::startH2) | ||
.setAfterAllCustomizer(customizer::stopH2) | ||
.withApplicationRoot((jar) -> jar | ||
.addClass(FlywayH2TestCustomizer.class) | ||
.addAsResource("db/migration/V1.0.0__Quarkus.sql") | ||
.addAsResource("baseline-at-start-existing-schema-history-table-config.properties", | ||
"application.properties")); | ||
|
||
@Test | ||
@DisplayName("Baseline at start is not executed against existing schema-history-table") | ||
public void testFlywayConfigInjection() { | ||
MigrationInfo migrationInfo = flyway.info().current(); | ||
assertNull(migrationInfo, "Flyway baseline was executed on existing schema history table"); | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
...y/deployment/src/test/java/io/quarkus/flyway/test/FlywayExtensionBaselineAtStartTest.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,39 @@ | ||
package io.quarkus.flyway.test; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
import jakarta.inject.Inject; | ||
|
||
import org.flywaydb.core.Flyway; | ||
import org.flywaydb.core.api.MigrationInfo; | ||
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 FlywayExtensionBaselineAtStartTest { | ||
@Inject | ||
Flyway flyway; | ||
|
||
@RegisterExtension | ||
static final QuarkusUnitTest config = new QuarkusUnitTest() | ||
.withApplicationRoot((jar) -> jar | ||
.addAsResource("db/migration/V1.0.0__Quarkus.sql") | ||
.addAsResource("baseline-at-start-config.properties", "application.properties")); | ||
|
||
@Test | ||
@DisplayName("Baseline at start is executed against empty schema") | ||
public void testFlywayConfigInjection() { | ||
MigrationInfo migrationInfo = flyway.info().current(); | ||
assertNotNull(migrationInfo, "No Flyway migration was executed"); | ||
assertTrue(migrationInfo.getType().isBaseline(), "Flyway migration is not a baseline"); | ||
String currentVersion = migrationInfo | ||
.getVersion() | ||
.toString(); | ||
|
||
assertEquals("1.0.1", currentVersion); | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
extensions/flyway/deployment/src/test/resources/baseline-at-start-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:quarkus-baseline-at-start;DB_CLOSE_DELAY=-1 | ||
|
||
# Flyway config properties | ||
quarkus.flyway.baseline-at-start=true | ||
quarkus.flyway.baseline-version=1.0.1 |
8 changes: 8 additions & 0 deletions
8
...ment/src/test/resources/baseline-at-start-existing-schema-history-table-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:11309/mem:quarkus-baseline-at-start-existing-schema-history;DB_CLOSE_DELAY=-1 | ||
|
||
# Flyway config properties | ||
quarkus.flyway.baseline-at-start=true | ||
quarkus.flyway.baseline-version=1.0.1 |
13 changes: 13 additions & 0 deletions
13
extensions/flyway/deployment/src/test/resources/h2-init-schema-history-table.sql
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,13 @@ | ||
CREATE TABLE "flyway_schema_history" ( | ||
"installed_rank" integer NOT NULL, | ||
"version" character varying(50), | ||
"description" character varying(200) NOT NULL, | ||
"type" character varying(20) NOT NULL, | ||
"script" character varying(1000) NOT NULL, | ||
"checksum" integer, | ||
"installed_by" character varying(100) NOT NULL, | ||
"installed_on" timestamp without time zone DEFAULT now() NOT NULL, | ||
"execution_time" integer NOT NULL, | ||
"success" boolean NOT NULL, | ||
CONSTRAINT flyway_schema_history_pk PRIMARY KEY ("installed_rank") | ||
); |
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