From e3a1aaa7b032b4b5ad52fbf3b876150a9ceccce2 Mon Sep 17 00:00:00 2001 From: Georgios Andrianakis Date: Tue, 18 Jan 2022 08:44:11 +0200 Subject: [PATCH] Support Flyway's defaultSchema configuration option Originally reported at: https://stackoverflow.com/q/70744765/2504224 --- .../resources/clean-at-start-config.properties | 4 +++- .../io/quarkus/flyway/runtime/FlywayCreator.java | 3 +++ .../runtime/FlywayDataSourceRuntimeConfig.java | 15 +++++++++++++++ 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/extensions/flyway/deployment/src/test/resources/clean-at-start-config.properties b/extensions/flyway/deployment/src/test/resources/clean-at-start-config.properties index 6f477ccf03444..35ab099fc98f0 100644 --- a/extensions/flyway/deployment/src/test/resources/clean-at-start-config.properties +++ b/extensions/flyway/deployment/src/test/resources/clean-at-start-config.properties @@ -1,12 +1,14 @@ quarkus.datasource.db-kind=h2 quarkus.datasource.username=sa quarkus.datasource.password=sa -quarkus.datasource.jdbc.url=jdbc:h2:tcp://localhost/mem:test-quarkus-clean-at-start;DB_CLOSE_DELAY=-1; +quarkus.datasource.jdbc.url=jdbc:h2:tcp://localhost/mem:test-quarkus-clean-at-start;DB_CLOSE_DELAY=-1;INIT=CREATE SCHEMA IF NOT EXISTS TEST # Flyway config properties quarkus.flyway.clean-at-start=true quarkus.flyway.migrate-at-start=false quarkus.flyway.table=test_flyway_history +quarkus.flyway.default-schema=PUBLIC +quarkus.flyway.schemas=TEST,PUBLIC quarkus.flyway.baseline-on-migrate=false quarkus.flyway.baseline-version=0.0.1 quarkus.flyway.baseline-description=Initial description for test diff --git a/extensions/flyway/runtime/src/main/java/io/quarkus/flyway/runtime/FlywayCreator.java b/extensions/flyway/runtime/src/main/java/io/quarkus/flyway/runtime/FlywayCreator.java index d1df4c3f7c435..bd8edd6289c5a 100644 --- a/extensions/flyway/runtime/src/main/java/io/quarkus/flyway/runtime/FlywayCreator.java +++ b/extensions/flyway/runtime/src/main/java/io/quarkus/flyway/runtime/FlywayCreator.java @@ -38,6 +38,9 @@ public Flyway createFlyway(DataSource dataSource) { if (flywayRuntimeConfig.connectRetries.isPresent()) { configure.connectRetries(flywayRuntimeConfig.connectRetries.getAsInt()); } + if (flywayRuntimeConfig.defaultSchema.isPresent()) { + configure.defaultSchema(flywayRuntimeConfig.defaultSchema.get()); + } if (flywayRuntimeConfig.schemas.isPresent()) { configure.schemas(flywayRuntimeConfig.schemas.get().toArray(EMPTY_ARRAY)); } diff --git a/extensions/flyway/runtime/src/main/java/io/quarkus/flyway/runtime/FlywayDataSourceRuntimeConfig.java b/extensions/flyway/runtime/src/main/java/io/quarkus/flyway/runtime/FlywayDataSourceRuntimeConfig.java index ba121db50e010..8afa0e0781b68 100644 --- a/extensions/flyway/runtime/src/main/java/io/quarkus/flyway/runtime/FlywayDataSourceRuntimeConfig.java +++ b/extensions/flyway/runtime/src/main/java/io/quarkus/flyway/runtime/FlywayDataSourceRuntimeConfig.java @@ -28,6 +28,21 @@ public static final FlywayDataSourceRuntimeConfig defaultConfig() { @ConfigItem public OptionalInt connectRetries = OptionalInt.empty(); + /** + * Sets the default schema managed by Flyway. This schema name is case-sensitive. If not specified, but schemas + * is, Flyway uses the first schema in that list. If that is also not specified, Flyway uses the default schema for the + * database connection. + *

+ * Consequences: + *

+ * + */ + @ConfigItem + public Optional defaultSchema = Optional.empty(); + /** * Comma-separated case-sensitive list of schemas managed by Flyway. * The first schema in the list will be automatically set as the default one during the migration.