This is an automated email from the ASF dual-hosted git repository.
pefernan pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/incubator-kie.git
The following commit(s) were added to refs/heads/main by this push:
new 85f327f0d52 [Incubator-kie-issues:2415]Added outOfOrder property in
KieFlyway (#7193)
85f327f0d52 is described below
commit 85f327f0d52822f1a909cdc58dce753d30acccef
Author: Soniya Abraham <[email protected]>
AuthorDate: Fri Oct 16 12:36:17 2026 +0530
[Incubator-kie-issues:2415]Added outOfOrder property in KieFlyway (#7193)
* Added configurable outOfOrder property in KieFlyway
* Including test cases
* Removing unwanted changes and updated springboot test
* Made the outOfOrder property defaults to true
* Make outoforder default value to true
* CI Retrigger
---
kogito-addons/common/flyway/README.md | 9 +-
kogito-addons/common/flyway/pom.xml | 4 +
.../flyway/initializer/KieFlywayInitializer.java | 13 ++-
.../kie/flyway/integration/KieFlywayRunner.java | 1 +
.../integration/KieFlywayRunnerConfiguration.java | 21 +++++
.../initializer/KieFlywayInitializerTest.java | 64 +++++++++++++++
.../flyway/integration/KieFlywayRunnerTest.java | 45 ++++++++++
.../org/kie/flyway/test/AbstractKieFlywayTest.java | 14 ++++
.../kie-flyway.guitars_late.properties | 22 +++++
.../h2/V1.0.3__Insert_late_guitar_h2.sql} | 23 +-----
.../flyway/quarkus/KieFlywayQuarkusRecorder.java | 2 +-
.../quarkus/KieFlywayQuarkusRuntimeConfig.java | 7 ++
.../quarkus/KieFlywayQuarkusRuntimeConfigTest.java | 16 ++++
kogito-springboot/addons/flyway/pom.xml | 6 ++
.../springboot/KieFlywaySpringbootInitializer.java | 2 +-
.../springboot/KieFlywaySpringbootProperties.java | 10 +++
.../KieFlywaySpringbootPropertiesTest.java | 96 ++++++++++++++++++++++
17 files changed, 328 insertions(+), 27 deletions(-)
diff --git a/kogito-addons/common/flyway/README.md
b/kogito-addons/common/flyway/README.md
index 5efde7bf4f3..3f3d5b5e913 100644
--- a/kogito-addons/common/flyway/README.md
+++ b/kogito-addons/common/flyway/README.md
@@ -94,6 +94,11 @@ kie-persistence-jdbc
KIE Flyway is disabled by default (in Quarkus is enabled in `test`/`dev`
profiles) and can be enabled / disabled with
`kie.flyway.enabled` property in the `application.properties` (by default is
false)
+### Allowing out-of-order migrations
+By default, KIE Flyway allows out-of-order migrations
(`kie.flyway.out-of-order=true`): if a migration with a version lower than the
last applied one is found, it will be applied anyway.
+Set `kie.flyway.out-of-order=false` in the `application.properties` to enforce
strict version ordering — Flyway will then fail if such a migration is detected.
+This applies to all KIE modules.
+
### Excluding specific KIE Modules via configuration.
In some cases you may want to exclude the KIE Modules present in your
application from the KIE Flyway initialization, to do so you can use
`kie.flyway.modules.<module-name>.enabled` property in the
`application.properties`
@@ -128,7 +133,8 @@ import org.kie.flyway.initializer.KieFlywayInitializer;
Additional Parameters that can be used:
* Custom ClassLoader to load the `kie-flyway.properties` from.
-* Module Exclusions (`Collection<String>`) t
+* Module Exclusions (`Collection<String>`) to skip from the initialization.
+* Out-of-order (`boolean`, default `true`): allows Flyway to run migrations
with a version lower than the last applied one.
```java
import org.kie.flyway.initializer.KieFlywayInitializer;
@@ -138,6 +144,7 @@ import org.kie.flyway.initializer.KieFlywayInitializer;
.withDatasource(dataSource)
.withClassLoader(this.getClass().getClassLoader())
.withModuleExclusions(List.of("data-index", "jobs-service"))
+ .withOutOfOrder(outOfOrder)
.build()
.migrate();
```
diff --git a/kogito-addons/common/flyway/pom.xml
b/kogito-addons/common/flyway/pom.xml
index 4011c4832c0..ecb06575003 100644
--- a/kogito-addons/common/flyway/pom.xml
+++ b/kogito-addons/common/flyway/pom.xml
@@ -37,6 +37,10 @@
</properties>
<dependencies>
+ <dependency>
+ <groupId>org.kie</groupId>
+ <artifactId>kie-api</artifactId>
+ </dependency>
<dependency>
<groupId>org.flywaydb</groupId>
<artifactId>flyway-core</artifactId>
diff --git
a/kogito-addons/common/flyway/src/main/java/org/kie/flyway/initializer/KieFlywayInitializer.java
b/kogito-addons/common/flyway/src/main/java/org/kie/flyway/initializer/KieFlywayInitializer.java
index 20ed87864a5..bd4474c1b0e 100644
---
a/kogito-addons/common/flyway/src/main/java/org/kie/flyway/initializer/KieFlywayInitializer.java
+++
b/kogito-addons/common/flyway/src/main/java/org/kie/flyway/initializer/KieFlywayInitializer.java
@@ -48,12 +48,14 @@ public class KieFlywayInitializer {
private final DataSource dataSource;
private final DataBaseInfo databaseInfo;
private final List<String> moduleExclusions;
+ private final boolean outOfOrder;
- private KieFlywayInitializer(KieModuleFlywayConfigLoader configLoader,
DataSource dataSource, Collection<String> moduleExclusions) {
+ private KieFlywayInitializer(KieModuleFlywayConfigLoader configLoader,
DataSource dataSource, Collection<String> moduleExclusions, boolean outOfOrder)
{
this.configLoader = configLoader;
this.dataSource = dataSource;
this.databaseInfo = readDataBaseInfo(dataSource);
this.moduleExclusions = new ArrayList<>(moduleExclusions);
+ this.outOfOrder = outOfOrder;
}
public void migrate() {
@@ -103,6 +105,7 @@ public class KieFlywayInitializer {
.baselineOnMigrate(true)
.baselineVersion(KIE_FLYWAY_BASELINE_VERSION)
.baselineDescription(KIE_FLYWAY_BASELINE_MESSAGE_TEMPLATE.formatted(config.getModule()))
+ .outOfOrder(outOfOrder)
.locations(locations)
.load()
.migrate();
@@ -118,6 +121,7 @@ public class KieFlywayInitializer {
private KieModuleFlywayConfigLoader configLoader;
private DataSource dataSource;
private final List<String> moduleExclusions = new ArrayList<>();
+ private boolean outOfOrder = true;
public Builder withClassLoader(ClassLoader classLoader) {
this.configLoader = new
DefaultKieModuleFlywayConfigLoader(classLoader);
@@ -134,6 +138,11 @@ public class KieFlywayInitializer {
return this;
}
+ public Builder withOutOfOrder(boolean outOfOrder) {
+ this.outOfOrder = outOfOrder;
+ return this;
+ }
+
public KieFlywayInitializer build() {
if (Objects.isNull(dataSource)) {
throw new KieFlywayException("Cannot create
KieFlywayInitializer migration, dataSource is null.");
@@ -144,7 +153,7 @@ public class KieFlywayInitializer {
this.configLoader = new DefaultKieModuleFlywayConfigLoader();
}
- return new KieFlywayInitializer(configLoader, dataSource,
moduleExclusions);
+ return new KieFlywayInitializer(configLoader, dataSource,
moduleExclusions, outOfOrder);
}
}
diff --git
a/kogito-addons/common/flyway/src/main/java/org/kie/flyway/integration/KieFlywayRunner.java
b/kogito-addons/common/flyway/src/main/java/org/kie/flyway/integration/KieFlywayRunner.java
index ddc68b35d0b..5048a37d361 100644
---
a/kogito-addons/common/flyway/src/main/java/org/kie/flyway/integration/KieFlywayRunner.java
+++
b/kogito-addons/common/flyway/src/main/java/org/kie/flyway/integration/KieFlywayRunner.java
@@ -68,6 +68,7 @@ public class KieFlywayRunner {
.withDatasource(dataSource)
.withClassLoader(classLoader)
.withModuleExclusions(excludedModules)
+ .withOutOfOrder(configuration.isOutOfOrder())
.build().migrate();
}
diff --git
a/kogito-addons/common/flyway/src/main/java/org/kie/flyway/integration/KieFlywayRunnerConfiguration.java
b/kogito-addons/common/flyway/src/main/java/org/kie/flyway/integration/KieFlywayRunnerConfiguration.java
index 81ebbee4b99..c940a9924eb 100644
---
a/kogito-addons/common/flyway/src/main/java/org/kie/flyway/integration/KieFlywayRunnerConfiguration.java
+++
b/kogito-addons/common/flyway/src/main/java/org/kie/flyway/integration/KieFlywayRunnerConfiguration.java
@@ -21,14 +21,35 @@ package org.kie.flyway.integration;
import java.util.Collection;
+import org.kie.api.annotations.KieProperty;
+
public class KieFlywayRunnerConfiguration {
+ @KieProperty(type = "boolean", defaultValue = "false", allowedValues =
"true,false")
+ public static final String KIE_FLYWAY_ENABLED_PROPERTY =
"kie.flyway.enabled";
+
+ @KieProperty(type = "boolean", defaultValue = "true", allowedValues =
"true,false")
+ public static final String KIE_FLYWAY_OUT_OF_ORDER_PROPERTY =
"kie.flyway.out-of-order";
+
+ @KieProperty(type = "boolean", defaultValue = "true", allowedValues =
"true,false")
+ public static final String KIE_FLYWAY_MODULE_ENABLED_PROPERTY =
"kie.flyway.modules.<module-name>.enabled";
+
private final boolean enabled;
private final Collection<KieFlywayNamedModule> modules;
+ private final boolean outOfOrder;
public KieFlywayRunnerConfiguration(boolean enabled,
Collection<KieFlywayNamedModule> modules) {
+ this(enabled, modules, true);
+ }
+
+ public KieFlywayRunnerConfiguration(boolean enabled,
Collection<KieFlywayNamedModule> modules, boolean outOfOrder) {
this.enabled = enabled;
this.modules = modules;
+ this.outOfOrder = outOfOrder;
+ }
+
+ public boolean isOutOfOrder() {
+ return outOfOrder;
}
public boolean isEnabled() {
diff --git
a/kogito-addons/common/flyway/src/test/java/org/kie/flyway/initializer/KieFlywayInitializerTest.java
b/kogito-addons/common/flyway/src/test/java/org/kie/flyway/initializer/KieFlywayInitializerTest.java
index 16ca985ba04..4c8508889ca 100644
---
a/kogito-addons/common/flyway/src/test/java/org/kie/flyway/initializer/KieFlywayInitializerTest.java
+++
b/kogito-addons/common/flyway/src/test/java/org/kie/flyway/initializer/KieFlywayInitializerTest.java
@@ -31,6 +31,7 @@ import org.kie.flyway.test.AbstractKieFlywayTest;
import org.kie.flyway.test.dataSources.H2TestDataSource;
import org.kie.flyway.test.dataSources.PostgreSQLTestDataSource;
import org.kie.flyway.test.dataSources.TestDataSource;
+import org.kie.flyway.test.models.KieFlywayMigration;
import org.kie.flyway.test.utils.TestClassLoader;
import org.kie.kogito.testcontainers.KogitoPostgreSqlContainer;
import org.testcontainers.junit.jupiter.Container;
@@ -148,6 +149,69 @@ public class KieFlywayInitializerTest extends
AbstractKieFlywayTest {
validateGuitarsData(dataSource);
}
+ @Test
+ public void testFlywayMigrationOutOfOrderEnabled() {
+ // First run: apply all guitars migrations (V1.0.0 through V1.0.5)
+
classLoader.addKieFlywayModule("initializers/kie-flyway.guitars.properties");
+
+ H2TestDataSource dataSource = new H2TestDataSource();
+
+ KieFlywayInitializer.builder()
+ .withDatasource(dataSource.getDataSource())
+ .withClassLoader(classLoader)
+ .build()
+ .migrate();
+
+ // Second run: add late migration V1.0.3 (lower than already-applied
V1.0.5)
+ // with outOfOrder=true it must be applied successfully
+ TestClassLoader classLoader2 = new
TestClassLoader(this.getClass().getClassLoader());
+
classLoader2.addKieFlywayModule("initializers/kie-flyway.guitars_late.properties");
+
+ KieFlywayInitializer.builder()
+ .withDatasource(dataSource.getDataSource())
+ .withClassLoader(classLoader2)
+ .withOutOfOrder(true)
+ .build()
+ .migrate();
+
+ validateKieFlywayIndex("guitars",
+ List.of(new KieFlywayMigration("1.0.3", "Insert late guitar
h2")),
+ dataSource);
+
+ dataSource.shutDown();
+ }
+
+ @Test
+ public void testFlywayMigrationOutOfOrderDisabled() {
+ // First run: apply all guitars migrations (V1.0.0 through V1.0.5)
+
classLoader.addKieFlywayModule("initializers/kie-flyway.guitars.properties");
+
+ H2TestDataSource dataSource = new H2TestDataSource();
+
+ KieFlywayInitializer.builder()
+ .withDatasource(dataSource.getDataSource())
+ .withClassLoader(classLoader)
+ .build()
+ .migrate();
+
+ // Second run: add late migration V1.0.3 with outOfOrder=false
(default).
+ // Flyway detects V1.0.3 on the classpath but already past V1.0.5 in
the history,
+ // so it throws a validation exception rather than silently skipping
it.
+ TestClassLoader classLoader2 = new
TestClassLoader(this.getClass().getClassLoader());
+
classLoader2.addKieFlywayModule("initializers/kie-flyway.guitars_late.properties");
+
+ assertThatThrownBy(() -> KieFlywayInitializer.builder()
+ .withDatasource(dataSource.getDataSource())
+ .withClassLoader(classLoader2)
+ .withOutOfOrder(false)
+ .build()
+ .migrate())
+ .hasMessageContaining("1.0.3")
+ .hasMessageContaining("outOfOrder");
+
+ dataSource.shutDown();
+ }
+
@Test
public void testFlywayMigrationWithFallbackDBType() {
classLoader.addKieFlywayModule("initializers/kie-flyway.guitars_default.properties");
diff --git
a/kogito-addons/common/flyway/src/test/java/org/kie/flyway/integration/KieFlywayRunnerTest.java
b/kogito-addons/common/flyway/src/test/java/org/kie/flyway/integration/KieFlywayRunnerTest.java
index ae0109b6860..7af41c3151a 100644
---
a/kogito-addons/common/flyway/src/test/java/org/kie/flyway/integration/KieFlywayRunnerTest.java
+++
b/kogito-addons/common/flyway/src/test/java/org/kie/flyway/integration/KieFlywayRunnerTest.java
@@ -29,6 +29,7 @@ import org.kie.flyway.KieFlywayException;
import org.kie.flyway.test.AbstractKieFlywayTest;
import org.kie.flyway.test.dataSources.H2TestDataSource;
import org.kie.flyway.test.dataSources.TestDataSource;
+import org.kie.flyway.test.models.KieFlywayMigration;
import org.kie.flyway.test.utils.TestClassLoader;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
@@ -125,6 +126,50 @@ public class KieFlywayRunnerTest extends
AbstractKieFlywayTest {
validateGuitarsData(TEST_DATA_SOURCE);
}
+ @Test
+ public void testFlywayMigrationsWithOutOfOrderEnabled() {
+ // Fresh datasource: apply guitars up to V1.0.5, then add late V1.0.3
with outOfOrder=true.
+ H2TestDataSource dataSource = new H2TestDataSource();
+
+
testClassLoader.addKieFlywayModule("initializers/kie-flyway.guitars.properties");
+ TestKieFlywayRunner.get(new KieFlywayRunnerConfiguration(true, new
ArrayList<>()), testClassLoader)
+ .runFlyway(dataSource.getDataSource());
+
+ TestClassLoader classLoader2 = new
TestClassLoader(this.getClass().getClassLoader());
+
classLoader2.addKieFlywayModule("initializers/kie-flyway.guitars_late.properties");
+
+ TestKieFlywayRunner.get(new KieFlywayRunnerConfiguration(true, new
ArrayList<>(), true), classLoader2)
+ .runFlyway(dataSource.getDataSource());
+
+ validateKieFlywayIndex("guitars",
+ List.of(new KieFlywayMigration("1.0.3", "Insert late guitar
h2")),
+ dataSource);
+
+ dataSource.shutDown();
+ }
+
+ @Test
+ public void testFlywayMigrationsWithOutOfOrderDisabled() {
+ // Fresh datasource: apply guitars up to V1.0.5, then present late
V1.0.3 with outOfOrder=false.
+ // Flyway detects V1.0.3 on the classpath but past V1.0.5 in the
history,
+ // so it throws a validation exception rather than silently skipping
it.
+ H2TestDataSource dataSource = new H2TestDataSource();
+
+
testClassLoader.addKieFlywayModule("initializers/kie-flyway.guitars.properties");
+ TestKieFlywayRunner.get(new KieFlywayRunnerConfiguration(true, new
ArrayList<>()), testClassLoader)
+ .runFlyway(dataSource.getDataSource());
+
+ TestClassLoader classLoader2 = new
TestClassLoader(this.getClass().getClassLoader());
+
classLoader2.addKieFlywayModule("initializers/kie-flyway.guitars_late.properties");
+
+ assertThatThrownBy(() -> TestKieFlywayRunner.get(new
KieFlywayRunnerConfiguration(true, new ArrayList<>(), false), classLoader2)
+ .runFlyway(dataSource.getDataSource()))
+ .hasMessageContaining("1.0.3")
+ .hasMessageContaining("outOfOrder");
+
+ dataSource.shutDown();
+ }
+
@AfterAll
public static void shutdown() {
TEST_DATA_SOURCE.shutDown();
diff --git
a/kogito-addons/common/flyway/src/test/java/org/kie/flyway/test/AbstractKieFlywayTest.java
b/kogito-addons/common/flyway/src/test/java/org/kie/flyway/test/AbstractKieFlywayTest.java
index 1ee734a6839..e5f27d68af4 100644
---
a/kogito-addons/common/flyway/src/test/java/org/kie/flyway/test/AbstractKieFlywayTest.java
+++
b/kogito-addons/common/flyway/src/test/java/org/kie/flyway/test/AbstractKieFlywayTest.java
@@ -113,6 +113,20 @@ public abstract class AbstractKieFlywayTest {
}
}
+ protected void verifyMigrationAbsent(String moduleName, String version,
TestDataSource dataSource) {
+ try (Connection con = dataSource.getDataSource().getConnection();
+ PreparedStatement stmt =
con.prepareStatement(MODULE_MIGRATIONS_QUERY_TEMPLATE.formatted(moduleName))) {
+ stmt.setString(1, version);
+ try (ResultSet rs = stmt.executeQuery()) {
+ assertThat(rs.next())
+ .as("Migration version %s for module %s should not
have been applied", version, moduleName)
+ .isFalse();
+ }
+ } catch (Exception ex) {
+ throw new RuntimeException(ex);
+ }
+ }
+
protected void verifyTableDoesntExist(String tableName, TestDataSource
dataSource) {
try (Connection con = dataSource.getDataSource().getConnection();
PreparedStatement stmt =
con.prepareStatement(QUERY_QUERY_TABLE_EXISTS);) {
diff --git
a/kogito-addons/common/flyway/src/test/resources/initializers/kie-flyway.guitars_late.properties
b/kogito-addons/common/flyway/src/test/resources/initializers/kie-flyway.guitars_late.properties
new file mode 100644
index 00000000000..92d60e1a46d
--- /dev/null
+++
b/kogito-addons/common/flyway/src/test/resources/initializers/kie-flyway.guitars_late.properties
@@ -0,0 +1,22 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+
+module.name=guitars
+
+module.locations.h2=classpath:kie-flyway/db/guitars/h2,classpath:kie-flyway/db/guitars-late/h2
diff --git
a/kogito-addons/common/flyway/src/main/java/org/kie/flyway/integration/KieFlywayRunnerConfiguration.java
b/kogito-addons/common/flyway/src/test/resources/kie-flyway/db/guitars-late/h2/V1.0.3__Insert_late_guitar_h2.sql
similarity index 60%
copy from
kogito-addons/common/flyway/src/main/java/org/kie/flyway/integration/KieFlywayRunnerConfiguration.java
copy to
kogito-addons/common/flyway/src/test/resources/kie-flyway/db/guitars-late/h2/V1.0.3__Insert_late_guitar_h2.sql
index 81ebbee4b99..77c289eb413 100644
---
a/kogito-addons/common/flyway/src/main/java/org/kie/flyway/integration/KieFlywayRunnerConfiguration.java
+++
b/kogito-addons/common/flyway/src/test/resources/kie-flyway/db/guitars-late/h2/V1.0.3__Insert_late_guitar_h2.sql
@@ -17,25 +17,4 @@
* under the License.
*/
-package org.kie.flyway.integration;
-
-import java.util.Collection;
-
-public class KieFlywayRunnerConfiguration {
-
- private final boolean enabled;
- private final Collection<KieFlywayNamedModule> modules;
-
- public KieFlywayRunnerConfiguration(boolean enabled,
Collection<KieFlywayNamedModule> modules) {
- this.enabled = enabled;
- this.modules = modules;
- }
-
- public boolean isEnabled() {
- return enabled;
- }
-
- public Collection<KieFlywayNamedModule> getModules() {
- return modules;
- }
-}
+insert into guitars (id, brand, model, rating) values (7, 'PRS', 'Custom 24',
9);
diff --git
a/kogito-quarkus/addons/flyway/runtime/src/main/java/org/kie/flyway/quarkus/KieFlywayQuarkusRecorder.java
b/kogito-quarkus/addons/flyway/runtime/src/main/java/org/kie/flyway/quarkus/KieFlywayQuarkusRecorder.java
index 60814d9f40c..d0063b4cc5d 100644
---
a/kogito-quarkus/addons/flyway/runtime/src/main/java/org/kie/flyway/quarkus/KieFlywayQuarkusRecorder.java
+++
b/kogito-quarkus/addons/flyway/runtime/src/main/java/org/kie/flyway/quarkus/KieFlywayQuarkusRecorder.java
@@ -53,7 +53,7 @@ public class KieFlywayQuarkusRecorder {
.map(entry -> new KieFlywayNamedModule(entry.getKey(),
entry.getValue().enabled()))
.toList();
- KieFlywayRunnerConfiguration kieFlywayConfig = new
KieFlywayRunnerConfiguration(runtimeConfig.enabled(), kieFlywayNamedModules);
+ KieFlywayRunnerConfiguration kieFlywayConfig = new
KieFlywayRunnerConfiguration(runtimeConfig.enabled(), kieFlywayNamedModules,
runtimeConfig.outOfOrder());
KieFlywayRunner.get(kieFlywayConfig)
.runFlyway(dataSource);
}
diff --git
a/kogito-quarkus/addons/flyway/runtime/src/main/java/org/kie/flyway/quarkus/KieFlywayQuarkusRuntimeConfig.java
b/kogito-quarkus/addons/flyway/runtime/src/main/java/org/kie/flyway/quarkus/KieFlywayQuarkusRuntimeConfig.java
index d798724e71d..93383e141ec 100644
---
a/kogito-quarkus/addons/flyway/runtime/src/main/java/org/kie/flyway/quarkus/KieFlywayQuarkusRuntimeConfig.java
+++
b/kogito-quarkus/addons/flyway/runtime/src/main/java/org/kie/flyway/quarkus/KieFlywayQuarkusRuntimeConfig.java
@@ -38,6 +38,13 @@ public interface KieFlywayQuarkusRuntimeConfig {
@WithDefault("false")
boolean enabled();
+ /**
+ * Allows migrations to be run "out of order".
+ * If you already have versions 1 and 3 applied, and now a version 2 is
found, it will be applied too instead of being ignored.
+ */
+ @WithDefault("true")
+ boolean outOfOrder();
+
/**
* List of {@link KieQuarkusFlywayNamedModuleConfig} that allow to enable
or disable a given module
*/
diff --git
a/kogito-quarkus/addons/flyway/runtime/src/test/java/org/kie/flyway/quarkus/KieFlywayQuarkusRuntimeConfigTest.java
b/kogito-quarkus/addons/flyway/runtime/src/test/java/org/kie/flyway/quarkus/KieFlywayQuarkusRuntimeConfigTest.java
index 9507778207c..ba62fe0c077 100644
---
a/kogito-quarkus/addons/flyway/runtime/src/test/java/org/kie/flyway/quarkus/KieFlywayQuarkusRuntimeConfigTest.java
+++
b/kogito-quarkus/addons/flyway/runtime/src/test/java/org/kie/flyway/quarkus/KieFlywayQuarkusRuntimeConfigTest.java
@@ -57,6 +57,22 @@ class KieFlywayQuarkusRuntimeConfigTest {
assertThat(runtimeConfig.enabled()).isTrue();
}
+ @Test
+ void outOfOrderDefaultsToTrue() {
+ KieFlywayQuarkusRuntimeConfig runtimeConfig = buildConfig()
+ .getConfigMapping(KieFlywayQuarkusRuntimeConfig.class);
+
+ assertThat(runtimeConfig.outOfOrder()).isTrue();
+ }
+
+ @Test
+ void outOfOrderCanBeSetToFalse() {
+ KieFlywayQuarkusRuntimeConfig runtimeConfig =
buildConfig("kie.flyway.out-of-order", "false")
+ .getConfigMapping(KieFlywayQuarkusRuntimeConfig.class);
+
+ assertThat(runtimeConfig.outOfOrder()).isFalse();
+ }
+
@Test
void moduleEnabledTrue() {
KieFlywayQuarkusRuntimeConfig runtimeConfig =
buildConfig("kie.flyway.modules.\"test-module\".enabled", "true")
diff --git a/kogito-springboot/addons/flyway/pom.xml
b/kogito-springboot/addons/flyway/pom.xml
index 9662f69c3af..c5b7368e7fd 100644
--- a/kogito-springboot/addons/flyway/pom.xml
+++ b/kogito-springboot/addons/flyway/pom.xml
@@ -56,6 +56,12 @@
</dependency>
<!-- test dependencies -->
+ <dependency>
+ <groupId>org.springframework.boot</groupId>
+ <artifactId>spring-boot-test</artifactId>
+ <scope>test</scope>
+ </dependency>
+
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
diff --git
a/kogito-springboot/addons/flyway/src/main/java/org/kie/flyway/springboot/KieFlywaySpringbootInitializer.java
b/kogito-springboot/addons/flyway/src/main/java/org/kie/flyway/springboot/KieFlywaySpringbootInitializer.java
index 184a7f8c3f6..985e18b2e88 100644
---
a/kogito-springboot/addons/flyway/src/main/java/org/kie/flyway/springboot/KieFlywaySpringbootInitializer.java
+++
b/kogito-springboot/addons/flyway/src/main/java/org/kie/flyway/springboot/KieFlywaySpringbootInitializer.java
@@ -50,7 +50,7 @@ public class KieFlywaySpringbootInitializer implements
InitializingBean, Ordered
.map(entry -> new KieFlywayNamedModule(entry.getKey(),
entry.getValue().isEnabled()))
.toList();
- KieFlywayRunner.get(new
KieFlywayRunnerConfiguration(properties.isEnabled(), kieFlywayNamedModules))
+ KieFlywayRunner.get(new
KieFlywayRunnerConfiguration(properties.isEnabled(), kieFlywayNamedModules,
properties.isOutOfOrder()))
.runFlyway(dataSource);
}
diff --git
a/kogito-springboot/addons/flyway/src/main/java/org/kie/flyway/springboot/KieFlywaySpringbootProperties.java
b/kogito-springboot/addons/flyway/src/main/java/org/kie/flyway/springboot/KieFlywaySpringbootProperties.java
index c65da4a34bb..22a99fbc74e 100644
---
a/kogito-springboot/addons/flyway/src/main/java/org/kie/flyway/springboot/KieFlywaySpringbootProperties.java
+++
b/kogito-springboot/addons/flyway/src/main/java/org/kie/flyway/springboot/KieFlywaySpringbootProperties.java
@@ -28,6 +28,8 @@ import
org.springframework.boot.context.properties.ConfigurationProperties;
public class KieFlywaySpringbootProperties {
private boolean enabled = false;
+ private boolean outOfOrder = true;
+
private Map<String, KieFlywaySpringbootNamedModule> modules = new
HashMap<>();
public boolean isEnabled() {
@@ -38,6 +40,14 @@ public class KieFlywaySpringbootProperties {
this.enabled = enabled;
}
+ public boolean isOutOfOrder() {
+ return outOfOrder;
+ }
+
+ public void setOutOfOrder(boolean outOfOrder) {
+ this.outOfOrder = outOfOrder;
+ }
+
public Map<String, KieFlywaySpringbootNamedModule> getModules() {
return modules;
}
diff --git
a/kogito-springboot/addons/flyway/src/test/java/org/kie/flyway/springboot/KieFlywaySpringbootPropertiesTest.java
b/kogito-springboot/addons/flyway/src/test/java/org/kie/flyway/springboot/KieFlywaySpringbootPropertiesTest.java
new file mode 100644
index 00000000000..f14e3ef5f42
--- /dev/null
+++
b/kogito-springboot/addons/flyway/src/test/java/org/kie/flyway/springboot/KieFlywaySpringbootPropertiesTest.java
@@ -0,0 +1,96 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.kie.flyway.springboot;
+
+import org.junit.jupiter.api.Test;
+import
org.springframework.boot.context.properties.EnableConfigurationProperties;
+import org.springframework.boot.test.context.runner.ApplicationContextRunner;
+import org.springframework.context.annotation.Configuration;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+class KieFlywaySpringbootPropertiesTest {
+
+ private final ApplicationContextRunner contextRunner = new
ApplicationContextRunner()
+ .withUserConfiguration(TestConfig.class);
+
+ @Configuration
+ @EnableConfigurationProperties(KieFlywaySpringbootProperties.class)
+ static class TestConfig {
+ }
+
+ @Test
+ void enabledDefaultsToFalse() {
+ contextRunner.run(ctx ->
assertThat(ctx.getBean(KieFlywaySpringbootProperties.class).isEnabled()).isFalse());
+ }
+
+ @Test
+ void enabledCanBeSetToTrue() {
+ contextRunner
+ .withPropertyValues("kie.flyway.enabled=true")
+ .run(ctx ->
assertThat(ctx.getBean(KieFlywaySpringbootProperties.class).isEnabled()).isTrue());
+ }
+
+ @Test
+ void enabledCanBeSetToFalse() {
+ contextRunner
+ .withPropertyValues("kie.flyway.enabled=false")
+ .run(ctx ->
assertThat(ctx.getBean(KieFlywaySpringbootProperties.class).isEnabled()).isFalse());
+ }
+
+ @Test
+ void outOfOrderDefaultsToTrue() {
+ contextRunner.run(ctx ->
assertThat(ctx.getBean(KieFlywaySpringbootProperties.class).isOutOfOrder()).isTrue());
+ }
+
+ @Test
+ void outOfOrderCanBeSetToTrue() {
+ contextRunner
+ .withPropertyValues("kie.flyway.out-of-order=true")
+ .run(ctx ->
assertThat(ctx.getBean(KieFlywaySpringbootProperties.class).isOutOfOrder()).isTrue());
+ }
+
+ @Test
+ void outOfOrderCanBeSetToFalse() {
+ contextRunner
+ .withPropertyValues("kie.flyway.out-of-order=false")
+ .run(ctx ->
assertThat(ctx.getBean(KieFlywaySpringbootProperties.class).isOutOfOrder()).isFalse());
+ }
+
+ @Test
+ void modulesDefaultsToEmpty() {
+ contextRunner.run(ctx ->
assertThat(ctx.getBean(KieFlywaySpringbootProperties.class).getModules()).isEmpty());
+ }
+
+ @Test
+ void moduleEnabledCanBeSetToFalse() {
+ contextRunner
+
.withPropertyValues("kie.flyway.modules.data-index.enabled=false")
+ .run(ctx ->
assertThat(ctx.getBean(KieFlywaySpringbootProperties.class)
+
.getModules().get("data-index").isEnabled()).isFalse());
+ }
+
+ @Test
+ void moduleEnabledDefaultsToTrue() {
+ contextRunner
+
.withPropertyValues("kie.flyway.modules.data-index.enabled=true")
+ .run(ctx ->
assertThat(ctx.getBean(KieFlywaySpringbootProperties.class)
+ .getModules().get("data-index").isEnabled()).isTrue());
+ }
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]