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#35732 from gsmet/flyway-enabled
Rework how to enable/activate Flyway
- Loading branch information
Showing
14 changed files
with
301 additions
and
83 deletions.
There are no files selected for viewing
44 changes: 44 additions & 0 deletions
44
...y/deployment/src/main/java/io/quarkus/flyway/deployment/FlywayAlwaysEnabledProcessor.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,44 @@ | ||
package io.quarkus.flyway.deployment; | ||
|
||
import org.flywaydb.core.extensibility.Plugin; | ||
|
||
import io.quarkus.deployment.Feature; | ||
import io.quarkus.deployment.annotations.BuildProducer; | ||
import io.quarkus.deployment.annotations.BuildStep; | ||
import io.quarkus.deployment.builditem.FeatureBuildItem; | ||
import io.quarkus.deployment.builditem.IndexDependencyBuildItem; | ||
import io.quarkus.deployment.builditem.nativeimage.NativeImageResourceBuildItem; | ||
import io.quarkus.deployment.builditem.nativeimage.RuntimeReinitializedClassBuildItem; | ||
import io.quarkus.deployment.builditem.nativeimage.ServiceProviderBuildItem; | ||
|
||
public class FlywayAlwaysEnabledProcessor { | ||
|
||
@BuildStep | ||
void build(BuildProducer<FeatureBuildItem> featureProducer) { | ||
featureProducer.produce(new FeatureBuildItem(Feature.FLYWAY)); | ||
} | ||
|
||
/** | ||
* Reinitialize {@code InsertRowLock} to avoid using a cached seed when invoking {@code getNextRandomString} | ||
*/ | ||
@BuildStep | ||
public RuntimeReinitializedClassBuildItem reinitInsertRowLock() { | ||
return new RuntimeReinitializedClassBuildItem( | ||
"org.flywaydb.core.internal.database.InsertRowLock"); | ||
} | ||
|
||
@BuildStep | ||
public NativeImageResourceBuildItem resources() { | ||
return new NativeImageResourceBuildItem("org/flywaydb/database/version.txt"); | ||
} | ||
|
||
@BuildStep | ||
IndexDependencyBuildItem indexFlyway() { | ||
return new IndexDependencyBuildItem("org.flywaydb", "flyway-core"); | ||
} | ||
|
||
@BuildStep | ||
public ServiceProviderBuildItem flywayPlugins() { | ||
return ServiceProviderBuildItem.allProvidersFromClassPath(Plugin.class.getName()); | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
...uarkus/flyway/FlywayCallbacksLocator.java → ...ay/deployment/FlywayCallbacksLocator.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
24 changes: 24 additions & 0 deletions
24
extensions/flyway/deployment/src/main/java/io/quarkus/flyway/deployment/FlywayEnabled.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,24 @@ | ||
package io.quarkus.flyway.deployment; | ||
|
||
import java.util.function.BooleanSupplier; | ||
|
||
import io.quarkus.flyway.runtime.FlywayBuildTimeConfig; | ||
|
||
/** | ||
* Supplier that can be used to only run build steps | ||
* if the Flyway extension is enabled. | ||
*/ | ||
public class FlywayEnabled implements BooleanSupplier { | ||
|
||
private final FlywayBuildTimeConfig config; | ||
|
||
FlywayEnabled(FlywayBuildTimeConfig config) { | ||
this.config = config; | ||
} | ||
|
||
@Override | ||
public boolean getAsBoolean() { | ||
return config.enabled; | ||
} | ||
|
||
} |
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
2 changes: 1 addition & 1 deletion
2
...us/flyway/devui/FlywayDevUIProcessor.java → ...eployment/devui/FlywayDevUIProcessor.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
70 changes: 70 additions & 0 deletions
70
.../io/quarkus/flyway/test/FlywayExtensionBaselineOnMigrateNamedDataSourcesInactiveTest.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,70 @@ | ||
package io.quarkus.flyway.test; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
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.flyway.FlywayDataSource; | ||
import io.quarkus.test.QuarkusUnitTest; | ||
|
||
public class FlywayExtensionBaselineOnMigrateNamedDataSourcesInactiveTest { | ||
|
||
@Inject | ||
@FlywayDataSource("users") | ||
Flyway flywayUsers; | ||
|
||
@Inject | ||
@FlywayDataSource("laptops") | ||
Flyway flywayLaptops; | ||
|
||
static final FlywayH2TestCustomizer customizerUsers = FlywayH2TestCustomizer | ||
.withDbName("quarkus-flyway-baseline-on-named-ds-users") | ||
.withPort(11302) | ||
.withInitSqlFile("src/test/resources/h2-init-data.sql"); | ||
|
||
static final FlywayH2TestCustomizer customizerLaptops = FlywayH2TestCustomizer | ||
.withDbName("quarkus-flyway-baseline-on-named-ds-laptops") | ||
.withPort(11303) | ||
.withInitSqlFile("src/test/resources/h2-init-data.sql"); | ||
|
||
@RegisterExtension | ||
static final QuarkusUnitTest config = new QuarkusUnitTest() | ||
.setBeforeAllCustomizer(new Runnable() { | ||
@Override | ||
public void run() { | ||
customizerUsers.startH2(); | ||
customizerLaptops.startH2(); | ||
} | ||
}) | ||
.setAfterAllCustomizer(new Runnable() { | ||
@Override | ||
public void run() { | ||
customizerUsers.stopH2(); | ||
customizerLaptops.stopH2(); | ||
} | ||
}) | ||
.withApplicationRoot((jar) -> jar | ||
.addClass(FlywayH2TestCustomizer.class) | ||
.addAsResource("baseline-on-migrate-named-datasources-inactive.properties", "application.properties")); | ||
|
||
@Test | ||
@DisplayName("Create history table correctly") | ||
public void testFlywayInitialBaselineInfo() { | ||
MigrationInfo baselineInfo = flywayUsers.info().applied()[0]; | ||
|
||
assertEquals("0.0.1", baselineInfo.getVersion().getVersion()); | ||
assertEquals("Initial description for test", baselineInfo.getDescription()); | ||
} | ||
|
||
@Test | ||
@DisplayName("History table not created if inactive") | ||
public void testFlywayInitialBaselineInfoInactive() { | ||
assertEquals(0, flywayLaptops.info().applied().length); | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
...s/flyway/deployment/src/test/java/io/quarkus/flyway/test/FlywayExtensionDisabledTest.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,31 @@ | ||
package io.quarkus.flyway.test; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
import jakarta.enterprise.inject.Instance; | ||
import jakarta.inject.Inject; | ||
|
||
import org.flywaydb.core.Flyway; | ||
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 FlywayExtensionDisabledTest { | ||
|
||
@Inject | ||
Instance<Flyway> flyway; | ||
|
||
@RegisterExtension | ||
static final QuarkusUnitTest config = new QuarkusUnitTest() | ||
.withApplicationRoot((jar) -> jar | ||
.addAsResource("db/migration/V1.0.0__Quarkus.sql") | ||
.addAsResource("disabled-config.properties", "application.properties")); | ||
|
||
@Test | ||
@DisplayName("No Flyway instance available if disabled") | ||
public void testFlywayConfigInjection() { | ||
assertTrue(flyway.isUnsatisfied()); | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
...y/deployment/src/test/resources/baseline-on-migrate-named-datasources-inactive.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,24 @@ | ||
quarkus.datasource.users.db-kind=h2 | ||
quarkus.datasource.users.username=sa | ||
quarkus.datasource.users.password=sa | ||
quarkus.datasource.users.jdbc.url=jdbc:h2:tcp://localhost:11302/mem:quarkus-flyway-baseline-on-named-ds-users | ||
|
||
# Flyway config properties | ||
quarkus.flyway.users.migrate-at-start=true | ||
quarkus.flyway.users.table=test_flyway_history | ||
quarkus.flyway.users.baseline-on-migrate=true | ||
quarkus.flyway.users.baseline-version=0.0.1 | ||
quarkus.flyway.users.baseline-description=Initial description for test | ||
|
||
quarkus.datasource.laptops.db-kind=h2 | ||
quarkus.datasource.laptops.username=sa | ||
quarkus.datasource.laptops.password=sa | ||
quarkus.datasource.laptops.jdbc.url=jdbc:h2:tcp://localhost:11302/mem:quarkus-flyway-baseline-on-named-ds-laptops | ||
|
||
# Flyway config properties | ||
quarkus.flyway.laptops.active=false | ||
quarkus.flyway.laptops.migrate-at-start=true | ||
quarkus.flyway.laptops.table=test_flyway_history | ||
quarkus.flyway.laptops.baseline-on-migrate=true | ||
quarkus.flyway.laptops.baseline-version=0.0.1 | ||
quarkus.flyway.laptops.baseline-description=Initial description for test |
8 changes: 8 additions & 0 deletions
8
extensions/flyway/deployment/src/test/resources/disabled-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.enabled=false | ||
quarkus.flyway.migrate-at-start=true |
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
Oops, something went wrong.