-
Notifications
You must be signed in to change notification settings - Fork 3k
New flyway start property: quarkus.flyway.clean-at-start #5697
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+147
−0
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
51 changes: 51 additions & 0 deletions
51
...yment/src/test/java/io/quarkus/flyway/test/FlywayExtensionCleanAndMigrateAtStartTest.java
This file contains hidden or 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,51 @@ | ||
package io.quarkus.flyway.test; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertFalse; | ||
|
||
import java.sql.Connection; | ||
import java.sql.ResultSet; | ||
import java.sql.SQLException; | ||
import java.sql.Statement; | ||
|
||
import javax.inject.Inject; | ||
|
||
import org.flywaydb.core.Flyway; | ||
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.agroal.api.AgroalDataSource; | ||
import io.quarkus.test.QuarkusUnitTest; | ||
|
||
public class FlywayExtensionCleanAndMigrateAtStartTest { | ||
// Quarkus built object | ||
@Inject | ||
Flyway flyway; | ||
|
||
@Inject | ||
AgroalDataSource defaultDataSource; | ||
|
||
@RegisterExtension | ||
static final QuarkusUnitTest config = new QuarkusUnitTest() | ||
.setArchiveProducer(() -> ShrinkWrap.create(JavaArchive.class) | ||
.addAsResource("db/migration/V1.0.0__Quarkus.sql") | ||
.addAsResource("clean-and-migrate-at-start-config.properties", "application.properties")); | ||
|
||
@Test | ||
@DisplayName("Clean and migrate at start correctly") | ||
public void testFlywayConfigInjection() throws SQLException { | ||
|
||
Connection connection = defaultDataSource.getConnection(); | ||
|
||
try (Statement stat = connection.createStatement()) { | ||
try (ResultSet executeQuery = stat.executeQuery("select * from fake_existing_tbl")) { | ||
assertFalse(executeQuery.next(), "Table exists but is not empty"); | ||
} | ||
} | ||
String currentVersion = flyway.info().current().getVersion().toString(); | ||
assertEquals("1.0.0", currentVersion, "Expected to be 1.0.0 as migration runs at start"); | ||
} | ||
} |
55 changes: 55 additions & 0 deletions
55
...yway/deployment/src/test/java/io/quarkus/flyway/test/FlywayExtensionCleanAtStartTest.java
This file contains hidden or 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,55 @@ | ||
package io.quarkus.flyway.test; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertNull; | ||
import static org.junit.jupiter.api.Assertions.fail; | ||
|
||
import java.sql.Connection; | ||
import java.sql.ResultSet; | ||
import java.sql.SQLException; | ||
import java.sql.Statement; | ||
|
||
import javax.inject.Inject; | ||
|
||
import org.flywaydb.core.Flyway; | ||
import org.flywaydb.core.api.MigrationInfo; | ||
import org.h2.jdbc.JdbcSQLException; | ||
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.agroal.api.AgroalDataSource; | ||
import io.quarkus.test.QuarkusUnitTest; | ||
|
||
public class FlywayExtensionCleanAtStartTest { | ||
// Quarkus built object | ||
@Inject | ||
Flyway flyway; | ||
|
||
@Inject | ||
AgroalDataSource defaultDataSource; | ||
|
||
@RegisterExtension | ||
static final QuarkusUnitTest config = new QuarkusUnitTest() | ||
.setArchiveProducer(() -> ShrinkWrap.create(JavaArchive.class) | ||
.addAsResource("db/migration/V1.0.0__Quarkus.sql") | ||
.addAsResource("clean-at-start-config.properties", "application.properties")); | ||
|
||
@Test | ||
@DisplayName("Clean at start correctly") | ||
public void testFlywayConfigInjection() throws SQLException { | ||
|
||
Connection connection = defaultDataSource.getConnection(); | ||
|
||
try (Statement stat = connection.createStatement()) { | ||
try (ResultSet executeQuery = stat.executeQuery("select * from fake_existing_tbl")) { | ||
fail("fake_existing_tbl should not exist"); | ||
} catch (JdbcSQLException e) { | ||
// expected fake_existing_tbl does not exist | ||
} | ||
} | ||
MigrationInfo current = flyway.info().current(); | ||
assertNull(current, "Info is not null"); | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
extensions/flyway/deployment/src/test/resources/clean-and-migrate-at-start-config.properties
This file contains hidden or 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,12 @@ | ||
quarkus.datasource.url=jdbc:h2:tcp://localhost/mem:test-quarkus-clean-at-start;DB_CLOSE_DELAY=-1;INIT=RUNSCRIPT FROM 'src/test/resources/h2-init-data.sql' | ||
quarkus.datasource.driver=org.h2.Driver | ||
quarkus.datasource.username=sa | ||
quarkus.datasource.password=sa | ||
|
||
# Flyway config properties | ||
quarkus.flyway.clean-at-start=true | ||
quarkus.flyway.migrate-at-start=true | ||
quarkus.flyway.table=test_flyway_history | ||
quarkus.flyway.baseline-on-migrate=true | ||
quarkus.flyway.baseline-version=0.0.1 | ||
quarkus.flyway.baseline-description=Initial description for test |
12 changes: 12 additions & 0 deletions
12
extensions/flyway/deployment/src/test/resources/clean-at-start-config.properties
This file contains hidden or 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,12 @@ | ||
quarkus.datasource.url=jdbc:h2:tcp://localhost/mem:test-quarkus-clean-at-start;DB_CLOSE_DELAY=-1;INIT=RUNSCRIPT FROM 'src/test/resources/h2-init-data.sql' | ||
quarkus.datasource.driver=org.h2.Driver | ||
quarkus.datasource.username=sa | ||
quarkus.datasource.password=sa | ||
|
||
# Flyway config properties | ||
quarkus.flyway.clean-at-start=true | ||
quarkus.flyway.migrate-at-start=false | ||
quarkus.flyway.table=test_flyway_history | ||
quarkus.flyway.baseline-on-migrate=true | ||
quarkus.flyway.baseline-version=0.0.1 | ||
quarkus.flyway.baseline-description=Initial description for test |
This file contains hidden or 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 hidden or 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 hidden or 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 |
---|---|---|
|
@@ -27,4 +27,5 @@ public String doMigrateAuto() { | |
"Version is null! Migration was not applied"); | ||
return version.toString(); | ||
} | ||
|
||
} |
This file contains hidden or 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 |
---|---|---|
|
@@ -17,4 +17,5 @@ public class FlywayFunctionalityTest { | |
public void testFlywayQuarkusFunctionality() { | ||
when().get("/flyway/migrate").then().body(is("1.0.1")); | ||
} | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this line break necessary? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm using Quarkus Code Style and before Commit, I run "mvn clean install" comands to format the code corretly |
||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this line break necessary?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm using Quarkus Code Style and before Commit, I run "mvn clean install" comands to format the code corretly