-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Take Java migration classes into account in Flyway extension
- Loading branch information
Showing
4 changed files
with
150 additions
and
7 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
101 changes: 101 additions & 0 deletions
101
...va/io/quarkus/flyway/test/FlywayExtensionCleanAndMigrateAtStartWithJavaMigrationTest.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,101 @@ | ||
package io.quarkus.flyway.test; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
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.MigrationVersion; | ||
import org.flywaydb.core.api.migration.BaseJavaMigration; | ||
import org.flywaydb.core.api.migration.Context; | ||
import org.flywaydb.core.api.migration.JavaMigration; | ||
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 FlywayExtensionCleanAndMigrateAtStartWithJavaMigrationTest { | ||
|
||
@Inject | ||
Flyway flyway; | ||
|
||
@Inject | ||
AgroalDataSource defaultDataSource; | ||
|
||
@RegisterExtension | ||
static final QuarkusUnitTest config = new QuarkusUnitTest() | ||
.setArchiveProducer(() -> ShrinkWrap.create(JavaArchive.class) | ||
.addClasses(V1_0_1__Update.class, V1_0_2__Update.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 { | ||
|
||
try (Connection connection = defaultDataSource.getConnection(); Statement stat = connection.createStatement()) { | ||
try (ResultSet countQuery = stat.executeQuery("select count(1) from quarked_flyway")) { | ||
assertTrue(countQuery.first()); | ||
assertEquals(2, | ||
countQuery.getInt(1), | ||
"Table 'quarked_flyway' does not contain the expected number of rows"); | ||
} | ||
} | ||
String currentVersion = flyway.info().current().getVersion().toString(); | ||
assertEquals("1.0.2", currentVersion, "Expected to be 1.0.2 as there is a SQL and two Java migration scripts"); | ||
} | ||
|
||
public static class V1_0_1__Update extends BaseJavaMigration { | ||
@Override | ||
public void migrate(Context context) throws Exception { | ||
try (Statement statement = context.getConnection().createStatement()) { | ||
statement.executeUpdate("INSERT INTO quarked_flyway VALUES (1001, 'test')"); | ||
} | ||
} | ||
} | ||
|
||
public static class V1_0_2__Update implements JavaMigration { | ||
@Override | ||
public MigrationVersion getVersion() { | ||
return MigrationVersion.fromVersion("1.0.2"); | ||
} | ||
|
||
@Override | ||
public String getDescription() { | ||
return getClass().getSimpleName(); | ||
} | ||
|
||
@Override | ||
public Integer getChecksum() { | ||
return null; | ||
} | ||
|
||
@Override | ||
public boolean isUndo() { | ||
return false; | ||
} | ||
|
||
@Override | ||
public boolean canExecuteInTransaction() { | ||
return true; | ||
} | ||
|
||
@Override | ||
public void migrate(Context context) throws Exception { | ||
try (Statement statement = context.getConnection().createStatement()) { | ||
statement.executeUpdate("INSERT INTO quarked_flyway VALUES (1002, 'test')"); | ||
} | ||
} | ||
} | ||
|
||
} |
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