You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@kie.apache.org by gi...@apache.org on 2024/10/01 06:57:07 UTC
(incubator-kie-kogito-runtimes) branch main updated: incubator-kie-issues#1483: Create a common Kie Flyway initializer for Kie Modules (#3672)
This is an automated email from the ASF dual-hosted git repository.
gitgabrio pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/incubator-kie-kogito-runtimes.git
The following commit(s) were added to refs/heads/main by this push:
new b096bf296f incubator-kie-issues#1483: Create a common Kie Flyway initializer for Kie Modules (#3672)
b096bf296f is described below
commit b096bf296f16343a39de07c84897e62dbf752a6e
Author: Pere Fernández <pe...@users.noreply.github.com>
AuthorDate: Tue Oct 1 08:57:02 2024 +0200
incubator-kie-issues#1483: Create a common Kie Flyway initializer for Kie Modules (#3672)
* incubator-kie-issues#1483: Create a common Kie Flyway initializer for Kie Modules
* - cleanup
* - cleanup
* - ddls
* - runtime configuration changes
* - changing script locations
* - Improved testing
- README.md
* - README.md
- Api improvements
* - minor changes
---
addons/common/flyway/README.md | 151 ++++++++++++++++++
addons/common/{persistence/jdbc => flyway}/pom.xml | 82 ++++------
.../java/org/kie/flyway/KieFlywayException.java | 31 ++++
.../flyway/initializer/KieFlywayInitializer.java | 159 +++++++++++++++++++
.../initializer/KieModuleFlywayConfigLoader.java | 29 ++++
.../impl/DefaultKieModuleFlywayConfigLoader.java | 110 +++++++++++++
.../flyway/integration/KieFlywayConfiguration.java | 29 ++++
.../flyway/integration/KieFlywayNamedModule.java | 25 +++
.../kie/flyway/integration/KieFlywayRunner.java | 81 ++++++++++
.../kie/flyway/model/KieFlywayModuleConfig.java | 38 ++---
.../initializer/KieFlywayInitializerTest.java | 174 +++++++++++++++++++++
.../DefaultKieModuleFlywayConfigLoaderTest.java | 94 +++++++++++
.../flyway/integration/KieFlywayRunnerTest.java | 141 +++++++++++++++++
.../integration/TestKieFlywayConfiguration.java | 36 ++---
.../integration/TestKieFlywayNamedModule.java | 34 ++++
.../org/kie/flyway/test/AbstractKieFlywayTest.java | 128 +++++++++++++++
.../flyway/test/dataSources/H2TestDataSource.java | 62 ++++++++
.../dataSources/PostgreSQLTestDataSource.java} | 41 +++--
.../flyway/test/dataSources/TestDataSource.java | 33 ++++
.../java/org/kie/flyway/test/models/Customer.java | 23 +++
.../java/org/kie/flyway/test/models/Guitar.java | 23 +++
.../kie/flyway/test/models/KieFlywayMigration.java | 23 +++
.../org/kie/flyway/test/models/TestModels.java | 50 ++++++
.../org/kie/flyway/test/utils/TestClassLoader.java | 42 ++---
.../test/resources/META-INF/kie-flyway.properties | 9 +-
.../initializers/kie-flyway.customers.properties | 9 +-
.../initializers/kie-flyway.customers2.properties | 9 +-
.../initializers/kie-flyway.duplicated1.properties | 9 +-
.../initializers/kie-flyway.duplicated2.properties | 9 +-
.../initializers/kie-flyway.empty.properties | 1 -
.../initializers/kie-flyway.guitars.properties | 9 +-
.../kie-flyway.guitars_default.properties | 7 +-
.../kie-flyway.no.locations.properties} | 6 +-
.../kie-flyway.wrong.format.properties} | 8 +-
.../ansi/V1.0.5__Insert_game_characters_ansi.sql | 21 +++
.../h2/V1.0.5__Insert_game_characters_h2.sql | 21 +++
.../V1.0.5__Insert_game_characters_postgresql.sql | 21 +++
.../customers/ansi/V1.0.0__Create_table_ansi.sql | 26 +++
.../db/customers/ansi/V1.0.1__Alter_table_ansi.sql | 20 +++
.../ansi/V1.0.2__Insert_book_characters_ansi.sql | 21 +++
.../db/customers/h2/V1.0.0__Create_table_h2.sql | 26 +++
.../db/customers/h2/V1.0.1__Alter_table_h2.sql | 20 +++
.../h2/V1.0.2__Insert_book_characters_h2.sql | 21 +++
.../postgresql/V1.0.0__Create_table_postgresql.sql | 26 +++
.../postgresql/V1.0.1__Alter_table_postgresql.sql | 20 +++
.../V1.0.2__Insert_book_characters_postgresql.sql | 21 +++
.../ansi/V1.0.0__Create_guitars_table_ansi.sql | 26 +++
.../ansi/V1.0.1__Alter_guitars_table_ansi.sql | 20 +++
.../ansi/V1.0.2__Insert_fender_guitars_ansi.sql | 22 +++
.../ansi/V1.0.5__Insert_gibson_guitars_ansi.sql | 22 +++
.../guitars/h2/V1.0.0__Create_guitars_table_h2.sql | 26 +++
.../guitars/h2/V1.0.1__Alter_guitars_table_h2.sql | 20 +++
.../h2/V1.0.2__Insert_fender_guitars_h2.sql | 22 +++
.../h2/V1.0.5__Insert_gibson_guitars_h2.sql | 22 +++
.../V1.0.0__Create_guitars_table_postgresql.sql | 26 +++
.../V1.0.1__Alter_guitars_table_postgresql.sql | 20 +++
.../V1.0.2__Insert_fender_guitars_postgresql.sql | 22 +++
.../V1.0.5__Insert_gibson_guitars_postgresql.sql | 22 +++
.../db/test/ansi/V1.0.0__Create_table.sql | 25 +++
.../db/test/ansi/V1.0.1__Alter_table.sql | 20 +++
.../db/test/ansi/V1.0.2__Insert_data.sql | 21 +++
.../kie-flyway/db/test/h2/V1.0.0__Create_table.sql | 25 +++
.../kie-flyway/db/test/h2/V1.0.1__Alter_table.sql | 20 +++
.../kie-flyway/db/test/h2/V1.0.2__Insert_data.sql | 21 +++
.../db/test/postgresql/V1.0.0__Create_table.sql | 25 +++
.../db/test/postgresql/V1.0.1__Alter_table.sql | 20 +++
.../db/test/postgresql/V1.0.2__Insert_data.sql | 21 +++
.../persistence/ddl/src/assembly/db-scripts.xml | 11 +-
.../ddl/src/assembly/productized-db-scripts.xml | 2 +-
addons/common/persistence/jdbc/pom.xml | 5 +-
.../main/resources/META-INF/kie-flyway.properties | 9 +-
.../ansi/V1.35.0__create_runtime_ansi.sql | 0
.../ansi/V10.0.0__add_business_key_ansi.sql | 0
.../ansi/V10.0.1__create_correlation_ansi.sql | 0
.../V1.35.0__create_runtime_PostgreSQL.sql | 0
.../V10.0.0__add_business_key_PostgreSQL.sql | 0
.../V10.0.1__alter_correlation_PostgreSQL.sql | 0
.../jdbc/AbstractProcessInstancesIT.java | 16 +-
.../jdbc/PostgreSqlProcessInstancesIT.java | 2 +-
.../jdbc/correlation/JDBCCorrelationServiceIT.java | 20 ++-
addons/common/persistence/postgresql/.gitignore | 2 +-
addons/common/persistence/postgresql/pom.xml | 13 +-
.../main/resources/META-INF/kie-flyway.properties | 8 +-
.../postgresql/PostgresqlProcessInstancesIT.java | 16 +-
addons/common/pom.xml | 1 +
kogito-bom/pom.xml | 48 ++++++
kogito-build/kogito-dependencies-bom/pom.xml | 13 ++
.../testcontainers/KogitoPostgreSqlContainer.java | 11 ++
quarkus/addons/flyway/deployment/pom.xml | 81 ++++++++++
.../deployment/KieFlywayExtensionProcessor.java | 66 ++++++++
quarkus/addons/flyway/pom.xml | 39 +++++
quarkus/addons/flyway/runtime/pom.xml | 93 +++++++++++
.../flyway/quarkus/KieFlywayQuarkusRecorder.java | 48 ++++++
.../quarkus/KieFlywayQuarkusRuntimeConfig.java | 71 +++++++++
.../resources/META-INF/quarkus-extension.yaml} | 22 ++-
.../src/main/resources/application.properties | 6 +-
quarkus/addons/persistence/jdbc/deployment/pom.xml | 6 +-
quarkus/addons/persistence/jdbc/runtime/pom.xml | 4 +-
...itoAddOnPersistenceJDBCConfigSourceFactory.java | 83 ----------
...ddOnPersistenceJDBCConfigSourceFactoryTest.java | 85 ----------
.../persistence/postgresql/deployment/pom.xml | 8 +-
.../addons/persistence/postgresql/runtime/pom.xml | 4 +-
quarkus/addons/pom.xml | 1 +
.../src/main/resources/application.properties | 3 +-
.../src/main/resources/application.properties | 4 +-
.../src/main/resources/application.properties | 4 +-
springboot/addons/flyway/pom.xml | 73 +++++++++
.../KieFlywaySpringbootAutoConfiguration.java | 50 ++++++
.../springboot/KieFlywaySpringbootInitializer.java | 51 ++++++
.../springboot/KieFlywaySpringbootProperties.java | 63 ++++++++
.../KieFlywaySpringbootInitializerDetector.java | 37 ++---
.../flyway/src/main/resources/META-INF/beans.xml | 0
.../src/main/resources/META-INF/spring.factories | 8 +-
...rk.boot.autoconfigure.AutoConfiguration.imports | 6 +-
springboot/addons/persistence/jdbc/pom.xml | 4 +
springboot/addons/persistence/postgresql/pom.xml | 4 +
springboot/addons/pom.xml | 1 +
.../src/main/resources/application.properties | 5 +-
.../src/main/resources/application.properties | 2 +
.../PostgreSqlSpringBootTestResource.java | 6 -
120 files changed, 3084 insertions(+), 478 deletions(-)
diff --git a/addons/common/flyway/README.md b/addons/common/flyway/README.md
new file mode 100644
index 0000000000..5efde7bf4f
--- /dev/null
+++ b/addons/common/flyway/README.md
@@ -0,0 +1,151 @@
+<!--
+ 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.
+ -->
+
+# KIE Flyway Add-On
+
+## Goal
+
+This add-on is a utility intended to help bootstrapping the application Data Base when running in a `compact` setup,
+when more than one`extension` or `add-on` that require persistence co-exist in the same application.
+
+This add-on will be using a managed Flyway to initialize and upgrade each `extension`/`add-on` DB
+instead of using the Platform (Quarkus/Springboot) specific Flyway integration, by this we achieve:
+* Simple setups in the `application.properties`. No need to configure Flyway unless the customer requires for its
+ own needs.
+* Component-Based DB Management: the DB management (via Flyway `migrations`) will be executed independently by component
+ (not globally), keeping a separate index for each component to avoid collisions and conflict between different component versions.
+* Multi DB Support: a single module can provide SQL scripts for different DB vendors (and default as a fallback) that
+ will be loaded depending on the application configuration
+
+> *IMPORTANT*: The usage of this add-on should be reserved only for development/test/examples purposes, and it is not recommended
+> using it in productive environments.
+
+
+
+## KIE Flyway Module Configuration
+
+In order to allow the *KIE Flyway Initializer* identify the DB needs of a specific component (`extensions` or `add-on`)
+the component has to meet the following requirements:
+
+* Provide a `kie-flyway.properties` descriptor file in `/src/main/resources/META-INF/kie-flyway.properties`. The file
+ should provide the following information:
+ * `module.name`: logic name that identifies the module. This identifier will be used during the Data Base initialization process
+ to generate the index table (`kie_flyway_history_<module_name>`) that will keep track of the modules table changes.
+ If there are multiple implementations of the same module (ej: `kie-addons-persistence-jdbc` / `kie-addons-persistence-postgresql`)
+ they should use the same name.
+ * `module.locations.<db>`: map containing the module `.sql` scripts location paths organized by database type (`postgresql`, `h2`...) to initialize the DB
+ (ej: `module.locations.postgresql=classpath:kie-flyway/db/test-module/postgresql`), the locations can be a comma-separated list to use multiple `.sql` locations in a single migration.
+ It's also possible using a `default` locations (`module.locations.default=...`) as a fallback to provide a default initialization
+ if no vendor-specific isn't available. It is important to avoid using the default flyway location (`src/main/resourcs/db/migrations`) to avoid
+ collisions with the Platform Flyway integration.
+
+Example of `kie-flyway.properties` file:
+```properties
+# Name that identifies the module
+module.name=runtime-persistence
+
+# Script locations for the current module
+module.locations.h2=classpath:kie-flyway/db/persistence-jdbc/h2
+module.locations.postgresql=classpath:kie-flyway/db/persistence-jdbc/postgresql
+# Default sql locations if the application db type isn't none of the above (ej: oracle)
+module.locations.default=classpath:kie-flyway/db/persistence-jdbc/ansi
+```
+
+* SQL Migration files: the needed SQL files to initialize the module DB. They should be stored in a unique path for the
+ component inside `src/main/resources` (ej: `src/main/resources/kie-flyway/db/<module_name>`), and grouped by database type.
+
+Example of folder structure:
+
+```
+kie-persistence-jdbc
+└─── src/main/resources
+ └─── META-INF
+ │ └─── kie-flyway.properties
+ └─── kie-flyway/db/persistence-jdbc
+ └─── ansi
+ │ V1.35.0__create_runtime_ansi.sql
+ │ V10.0.0__add_business_key_ansi.sql
+ │ V10.0.1__create_correlation_ansi.sql
+ └─── postgresql
+ V1.35.0__create_runtime_PostgreSQL.sql
+ V10.0.0__add_business_key_PostgreSQL.sql
+ V10.0.1__create_correlation_PostgreSQL.sql
+```
+
+## Application configurations
+
+### Enabling Kie Flyway Migration
+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)
+
+### 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`
+
+Example of `application.properties`
+```properties
+...
+
+# KIE Flyway setup
+kie.flyway.enabled=true
+kie.flyway.modules."data-index".enabled=false
+kie.flyway.modules."jobs-service".enabled=false
+```
+
+## Usage
+KIE Flyway exposes the `KieFlywayInitializer` as entry point of the add-on and exposes a Fluent Api to configure it
+and run it. This component will be in charge of loading all the `kie-flyway.properties` available in the application and run
+migrations for each of them.
+
+The required information that must be provided to the initializer is:
+* DataSource (`java.sql.DataSource`) where the initialization should be executed. It should be the default application Data Source
+
+```java
+import org.kie.flyway.initializer.KieFlywayInitializer;
+
+...
+ KieFlywayInitializer.builder()
+ .withDatasource(dataSource)
+ .build()
+ .migrate();
+```
+
+Additional Parameters that can be used:
+* Custom ClassLoader to load the `kie-flyway.properties` from.
+* Module Exclusions (`Collection<String>`) t
+
+```java
+import org.kie.flyway.initializer.KieFlywayInitializer;
+
+...
+ KieFlywayInitializer.builder()
+ .withDatasource(dataSource)
+ .withClassLoader(this.getClass().getClassLoader())
+ .withModuleExclusions(List.of("data-index", "jobs-service"))
+ .build()
+ .migrate();
+```
+
+> NOTE: The platform-specific add-ons (Quarkus/Spring-Boot) will be in charge to obtain the DataSource and DataBase type
+> and correctly configure the `KieFlywayInitializer` according to the `application.properties` and use it on during the application startup.
+
+
+
+
+
diff --git a/addons/common/persistence/jdbc/pom.xml b/addons/common/flyway/pom.xml
similarity index 61%
copy from addons/common/persistence/jdbc/pom.xml
copy to addons/common/flyway/pom.xml
index aac9886605..6a79414f19 100644
--- a/addons/common/persistence/jdbc/pom.xml
+++ b/addons/common/flyway/pom.xml
@@ -1,3 +1,4 @@
+<?xml version="1.0" encoding="UTF-8"?>
<!--
Licensed to the Apache Software Foundation (ASF) under one
@@ -18,49 +19,34 @@
under the License.
-->
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
- <modelVersion>4.0.0</modelVersion>
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
+ <artifactId>kogito-addons-common-parent</artifactId>
<groupId>org.kie</groupId>
- <artifactId>kie-addons-persistence-parent</artifactId>
<version>999-SNAPSHOT</version>
</parent>
- <artifactId>kie-addons-persistence-jdbc</artifactId>
- <name>KIE :: Add-Ons :: Persistence :: JDBC</name>
+ <modelVersion>4.0.0</modelVersion>
- <description>JDBC based persistence for KIE</description>
+ <artifactId>kie-addons-flyway</artifactId>
+ <name>KIE :: Add-Ons :: Flyway</name>
<properties>
- <java.module.name>org.kie.kogito.persistence.jdbc</java.module.name>
+ <java.module.name>org.kie.flyway</java.module.name>
</properties>
<dependencies>
<dependency>
- <groupId>org.kie.kogito</groupId>
- <artifactId>kogito-api</artifactId>
- </dependency>
- <dependency>
- <groupId>org.kie.kogito</groupId>
- <artifactId>jbpm-deps-group-engine</artifactId>
- <type>pom</type>
- </dependency>
- <!-- test dependencies -->
- <dependency>
- <groupId>org.kie.kogito</groupId>
- <artifactId>jbpm-deps-group-bpmn2-compiler</artifactId>
- <type>pom</type>
- <scope>test</scope>
+ <groupId>org.flywaydb</groupId>
+ <artifactId>flyway-core</artifactId>
</dependency>
+
<dependency>
- <groupId>org.postgresql</groupId>
- <artifactId>postgresql</artifactId>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.kie.kogito</groupId>
- <artifactId>kogito-test-utils</artifactId>
- <scope>test</scope>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-api</artifactId>
</dependency>
+
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
@@ -71,39 +57,31 @@
<artifactId>junit-jupiter-params</artifactId>
<scope>test</scope>
</dependency>
-
+ <dependency>
+ <groupId>org.mockito</groupId>
+ <artifactId>mockito-core</artifactId>
+ <scope>test</scope>
+ </dependency>
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<scope>test</scope>
</dependency>
<dependency>
- <groupId>org.mockito</groupId>
- <artifactId>mockito-core</artifactId>
+ <groupId>org.postgresql</groupId>
+ <artifactId>postgresql</artifactId>
<scope>test</scope>
</dependency>
<dependency>
- <groupId>org.flywaydb</groupId>
- <artifactId>flyway-core</artifactId>
- <version>${version.org.flywaydb}</version>
+ <groupId>org.kie.kogito</groupId>
+ <artifactId>kogito-test-utils</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>com.h2database</groupId>
+ <artifactId>h2</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
- <build>
- <plugins>
- <plugin>
- <groupId>io.smallrye</groupId>
- <artifactId>jandex-maven-plugin</artifactId>
- <executions>
- <execution>
- <id>make-index</id>
- <goals>
- <goal>jandex</goal>
- </goals>
- </execution>
- </executions>
- </plugin>
- </plugins>
- </build>
-</project>
+</project>
\ No newline at end of file
diff --git a/addons/common/flyway/src/main/java/org/kie/flyway/KieFlywayException.java b/addons/common/flyway/src/main/java/org/kie/flyway/KieFlywayException.java
new file mode 100644
index 0000000000..becf0325f1
--- /dev/null
+++ b/addons/common/flyway/src/main/java/org/kie/flyway/KieFlywayException.java
@@ -0,0 +1,31 @@
+/*
+ * 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;
+
+public class KieFlywayException extends RuntimeException {
+
+ public KieFlywayException(String message) {
+ super(message);
+ }
+
+ public KieFlywayException(String message, Throwable cause) {
+ super(message, cause);
+ }
+}
diff --git a/addons/common/flyway/src/main/java/org/kie/flyway/initializer/KieFlywayInitializer.java b/addons/common/flyway/src/main/java/org/kie/flyway/initializer/KieFlywayInitializer.java
new file mode 100644
index 0000000000..8986b7a428
--- /dev/null
+++ b/addons/common/flyway/src/main/java/org/kie/flyway/initializer/KieFlywayInitializer.java
@@ -0,0 +1,159 @@
+/*
+ * 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.initializer;
+
+import java.sql.Connection;
+import java.util.*;
+import java.util.stream.Collectors;
+
+import javax.sql.DataSource;
+
+import org.flywaydb.core.Flyway;
+import org.kie.flyway.KieFlywayException;
+import org.kie.flyway.initializer.impl.DefaultKieModuleFlywayConfigLoader;
+import org.kie.flyway.model.KieFlywayModuleConfig;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import static java.util.stream.Collectors.groupingBy;
+
+public class KieFlywayInitializer {
+ private static final String KIE_FLYWAY_BASELINE_VERSION = "0.0";
+
+ private static final String KIE_FLYWAY_BASELINE_MESSAGE_TEMPLATE = "Kie Flyway Baseline - %s";
+
+ private static final String KIE_FLYWAY_INDEX_TABLE_INDEX_TEMPLATE = "kie_flyway_history_%s";
+
+ private static final Logger LOGGER = LoggerFactory.getLogger(KieFlywayInitializer.class);
+
+ private final KieModuleFlywayConfigLoader configLoader;
+ private final DataSource dataSource;
+ private final String databaseType;
+ private final List<String> moduleExclusions;
+
+ private KieFlywayInitializer(KieModuleFlywayConfigLoader configLoader, DataSource dataSource, Collection<String> moduleExclusions) {
+ this.configLoader = configLoader;
+ this.dataSource = dataSource;
+ this.databaseType = getDataSourceType(dataSource);
+ this.moduleExclusions = new ArrayList<>(moduleExclusions);
+ }
+
+ public void migrate() {
+ LOGGER.debug("Starting Kie Flyway migration.");
+ Collection<KieFlywayModuleConfig> configs = configLoader.loadModuleConfigs();
+
+ checkDuplicatedModuleConfigs(configs);
+
+ LOGGER.debug("Found {} configured Kie Flyway modules.", configs.size());
+
+ configs.forEach(this::runFlyway);
+ }
+
+ private void checkDuplicatedModuleConfigs(Collection<KieFlywayModuleConfig> configs) {
+ List<String> duplicatedModules = configs.stream()
+ .collect(groupingBy(kieFlywayModuleConfig -> kieFlywayModuleConfig.getModule().toLowerCase(), Collectors.counting()))
+ .entrySet()
+ .stream().filter(entry -> entry.getValue() > 1)
+ .map(Map.Entry::getKey)
+ .toList();
+
+ if (!duplicatedModules.isEmpty()) {
+ LOGGER.warn("Cannot run Kie Flyway migration: Duplicated modules found `{}`", String.join(", ", duplicatedModules));
+ throw new KieFlywayException("Cannot run Kie Flyway migration: Duplicated Modules found " + String.join(", ", duplicatedModules));
+ }
+ }
+
+ private String getDataSourceType(DataSource dataSource) {
+ try (Connection con = dataSource.getConnection()) {
+ return con.getMetaData().getDatabaseProductName().toLowerCase();
+ } catch (Exception e) {
+ LOGGER.error("Kie Flyway: Couldn't extract database product name from datasource ", e);
+ throw new KieFlywayException("Kie Flyway: Couldn't extract database product name from datasource.", e);
+ }
+ }
+
+ private void runFlyway(KieFlywayModuleConfig config) {
+ LOGGER.debug("Running Flyway for module: {}", config.getModule());
+
+ if (moduleExclusions.contains(config.getModule())) {
+ LOGGER.debug("Skipping module: {}", config.getModule());
+ return;
+ }
+
+ String[] locations = config.getDBScriptLocations(databaseType);
+
+ if (Objects.isNull(locations)) {
+ LOGGER.warn("Cannot run Flyway migration for module `{}`, cannot find SQL Script locations for db `{}`", config.getModule(), databaseType);
+ throw new KieFlywayException("Cannot run Flyway migration for module `" + config.getModule() + "`, cannot find SQL Script locations for db `" + databaseType + "`");
+ }
+
+ Flyway.configure()
+ .table(KIE_FLYWAY_INDEX_TABLE_INDEX_TEMPLATE.formatted(config.getModule().replaceAll("[^A-Za-z0-9]", "_")).toLowerCase())
+ .dataSource(dataSource)
+ .createSchemas(true)
+ .baselineOnMigrate(true)
+ .baselineVersion(KIE_FLYWAY_BASELINE_VERSION)
+ .baselineDescription(KIE_FLYWAY_BASELINE_MESSAGE_TEMPLATE.formatted(config.getModule()))
+ .locations(locations)
+ .load()
+ .migrate();
+
+ LOGGER.debug("Flyway migration complete.");
+ }
+
+ public static Builder builder() {
+ return new Builder();
+ }
+
+ public static class Builder {
+ private KieModuleFlywayConfigLoader configLoader;
+ private DataSource dataSource;
+ private final List<String> moduleExclusions = new ArrayList<>();
+
+ public Builder withClassLoader(ClassLoader classLoader) {
+ this.configLoader = new DefaultKieModuleFlywayConfigLoader(classLoader);
+ return this;
+ }
+
+ public Builder withDatasource(DataSource dataSource) {
+ this.dataSource = dataSource;
+ return this;
+ }
+
+ public Builder withModuleExclusions(Collection<String> moduleExclusions) {
+ this.moduleExclusions.addAll(moduleExclusions);
+ return this;
+ }
+
+ public KieFlywayInitializer build() {
+ if (Objects.isNull(dataSource)) {
+ throw new KieFlywayException("Cannot create KieFlywayInitializer migration, dataSource is null.");
+ }
+
+ if (Objects.isNull(configLoader)) {
+ LOGGER.warn("ModuleConfigLoader not configured, falling back to default.");
+ this.configLoader = new DefaultKieModuleFlywayConfigLoader();
+ }
+
+ return new KieFlywayInitializer(configLoader, dataSource, moduleExclusions);
+ }
+ }
+
+}
diff --git a/addons/common/flyway/src/main/java/org/kie/flyway/initializer/KieModuleFlywayConfigLoader.java b/addons/common/flyway/src/main/java/org/kie/flyway/initializer/KieModuleFlywayConfigLoader.java
new file mode 100644
index 0000000000..cc3f15b914
--- /dev/null
+++ b/addons/common/flyway/src/main/java/org/kie/flyway/initializer/KieModuleFlywayConfigLoader.java
@@ -0,0 +1,29 @@
+/*
+ * 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.initializer;
+
+import java.util.Collection;
+
+import org.kie.flyway.model.KieFlywayModuleConfig;
+
+public interface KieModuleFlywayConfigLoader {
+
+ Collection<KieFlywayModuleConfig> loadModuleConfigs();
+}
diff --git a/addons/common/flyway/src/main/java/org/kie/flyway/initializer/impl/DefaultKieModuleFlywayConfigLoader.java b/addons/common/flyway/src/main/java/org/kie/flyway/initializer/impl/DefaultKieModuleFlywayConfigLoader.java
new file mode 100644
index 0000000000..71665bc63d
--- /dev/null
+++ b/addons/common/flyway/src/main/java/org/kie/flyway/initializer/impl/DefaultKieModuleFlywayConfigLoader.java
@@ -0,0 +1,110 @@
+/*
+ * 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.initializer.impl;
+
+import java.io.File;
+import java.io.InputStream;
+import java.net.URL;
+import java.util.*;
+import java.util.stream.Collectors;
+
+import org.kie.flyway.KieFlywayException;
+import org.kie.flyway.initializer.KieModuleFlywayConfigLoader;
+import org.kie.flyway.model.KieFlywayModuleConfig;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class DefaultKieModuleFlywayConfigLoader implements KieModuleFlywayConfigLoader {
+
+ public static String KIE_FLYWAY_DESCRIPTOR_FILE_NAME = "kie-flyway.properties";
+
+ public static String KIE_FLYWAY_DESCRIPTOR_FILE_LOCATION = "META-INF" + File.separator + KIE_FLYWAY_DESCRIPTOR_FILE_NAME;
+
+ public static final String MODULE_PREFIX = "module.";
+ public static final String MODULE_NAME_KEY = MODULE_PREFIX + "name";
+ public static final String MODULE_LOCATIONS_KEY = MODULE_PREFIX + "locations";
+
+ private static final Logger LOGGER = LoggerFactory.getLogger(DefaultKieModuleFlywayConfigLoader.class);
+
+ private final ClassLoader classLoader;
+
+ public DefaultKieModuleFlywayConfigLoader() {
+ this(Thread.currentThread().getContextClassLoader());
+ }
+
+ public DefaultKieModuleFlywayConfigLoader(ClassLoader classLoader) {
+ this.classLoader = classLoader;
+ }
+
+ @Override
+ public Collection<KieFlywayModuleConfig> loadModuleConfigs() {
+ return Optional.ofNullable(this.classLoader).orElse(this.getClass().getClassLoader())
+ .resources(KIE_FLYWAY_DESCRIPTOR_FILE_LOCATION)
+ .map(this::toModuleFlywayConfig)
+ .toList();
+ }
+
+ private KieFlywayModuleConfig toModuleFlywayConfig(URL resourceUrl) {
+ LOGGER.debug("Loading configuration from {}", resourceUrl);
+
+ try (InputStream inputStream = resourceUrl.openStream()) {
+ Properties properties = new Properties();
+ properties.load(inputStream);
+
+ String moduleName = properties.getProperty(MODULE_NAME_KEY);
+
+ if (Objects.isNull(moduleName)) {
+ LOGGER.warn("Could not load module name from file `{}`", resourceUrl);
+ throw new KieFlywayException("Could not load module name from `" + resourceUrl + "`");
+ }
+
+ LOGGER.debug("Loading Kie Flyway Module {}", moduleName);
+
+ Map<String, String[]> locations = properties.keySet()
+ .stream()
+ .map(String::valueOf)
+ .filter(moduleProperty -> moduleProperty.startsWith(MODULE_LOCATIONS_KEY))
+ .map(dbLocationsProperty -> {
+ LOGGER.debug("Loading location: {}", dbLocationsProperty);
+ // Splitting the key (`module.locations.<dbType>`) to obtain the dbType
+ String[] dbLocationsPropertyArray = dbLocationsProperty.split("\\.");
+ if (dbLocationsPropertyArray.length != 3) {
+ throw new KieFlywayException("Cannot load module `" + moduleName + "` config, file has wrong format");
+ }
+ String[] locationsArray = properties.getProperty(dbLocationsProperty).split(",");
+
+ return Map.entry(dbLocationsPropertyArray[2], locationsArray);
+ }).collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
+
+ if (locations.isEmpty()) {
+ LOGGER.warn("Kie Flyway module `{}` has no locations ", moduleName);
+ }
+
+ KieFlywayModuleConfig module = new KieFlywayModuleConfig(moduleName, locations);
+
+ LOGGER.debug("Successfully loaded configuration for module {}", module.getModule());
+
+ return module;
+ } catch (Exception e) {
+ LOGGER.warn("Could not load configuration from {}", resourceUrl, e);
+ throw new KieFlywayException("Could not load ModuleFlywayConfig", e);
+ }
+ }
+}
diff --git a/addons/common/flyway/src/main/java/org/kie/flyway/integration/KieFlywayConfiguration.java b/addons/common/flyway/src/main/java/org/kie/flyway/integration/KieFlywayConfiguration.java
new file mode 100644
index 0000000000..c99dba53b8
--- /dev/null
+++ b/addons/common/flyway/src/main/java/org/kie/flyway/integration/KieFlywayConfiguration.java
@@ -0,0 +1,29 @@
+/*
+ * 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.integration;
+
+import java.util.Map;
+
+public interface KieFlywayConfiguration<T extends KieFlywayNamedModule> {
+
+ boolean isEnabled();
+
+ Map<String, T> getModules();
+}
diff --git a/addons/common/flyway/src/main/java/org/kie/flyway/integration/KieFlywayNamedModule.java b/addons/common/flyway/src/main/java/org/kie/flyway/integration/KieFlywayNamedModule.java
new file mode 100644
index 0000000000..e3ebe1b6a0
--- /dev/null
+++ b/addons/common/flyway/src/main/java/org/kie/flyway/integration/KieFlywayNamedModule.java
@@ -0,0 +1,25 @@
+/*
+ * 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.integration;
+
+public interface KieFlywayNamedModule {
+
+ boolean isEnabled();
+}
diff --git a/addons/common/flyway/src/main/java/org/kie/flyway/integration/KieFlywayRunner.java b/addons/common/flyway/src/main/java/org/kie/flyway/integration/KieFlywayRunner.java
new file mode 100644
index 0000000000..47d55a96e6
--- /dev/null
+++ b/addons/common/flyway/src/main/java/org/kie/flyway/integration/KieFlywayRunner.java
@@ -0,0 +1,81 @@
+/*
+ * 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.integration;
+
+import java.util.Collection;
+import java.util.Map;
+import java.util.Objects;
+
+import javax.sql.DataSource;
+
+import org.kie.flyway.KieFlywayException;
+import org.kie.flyway.initializer.KieFlywayInitializer;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class KieFlywayRunner {
+ private static final Logger LOGGER = LoggerFactory.getLogger(KieFlywayRunner.class);
+
+ private final ClassLoader classLoader;
+ private final KieFlywayConfiguration<? extends KieFlywayNamedModule> configuration;
+
+ private KieFlywayRunner(KieFlywayConfiguration<? extends KieFlywayNamedModule> configuration) {
+ this(configuration, Thread.currentThread().getContextClassLoader());
+ }
+
+ protected KieFlywayRunner(KieFlywayConfiguration<? extends KieFlywayNamedModule> configuration, ClassLoader classLoader) {
+ this.configuration = configuration;
+ this.classLoader = classLoader;
+ }
+
+ public static KieFlywayRunner get(KieFlywayConfiguration<? extends KieFlywayNamedModule> configuration) {
+ return new KieFlywayRunner(configuration);
+ }
+
+ public void runFlyway(DataSource dataSource) {
+ assertValue(configuration, "Kie Flyway: Cannot run Kie Flyway migration configuration is null.");
+
+ if (!configuration.isEnabled()) {
+ LOGGER.warn("Kie Flyway is disabled, skipping initialization.");
+ return;
+ }
+
+ assertValue(dataSource, "Kie Flyway: Cannot run Kie Flyway migration default datasource is null");
+
+ Collection<String> excludedModules = configuration.getModules()
+ .entrySet()
+ .stream().filter(entry -> !entry.getValue().isEnabled())
+ .map(Map.Entry::getKey)
+ .toList();
+
+ KieFlywayInitializer.builder()
+ .withDatasource(dataSource)
+ .withClassLoader(classLoader)
+ .withModuleExclusions(excludedModules)
+ .build().migrate();
+ }
+
+ private void assertValue(Object value, String message) {
+ if (Objects.isNull(value)) {
+ LOGGER.warn(message);
+ throw new KieFlywayException(message);
+ }
+ }
+}
diff --git a/quarkus/addons/persistence/jdbc/runtime/src/main/java/org/kie/kogito/persistence/quarkus/KogitoAddOnPersistenceJDBCConfigSource.java b/addons/common/flyway/src/main/java/org/kie/flyway/model/KieFlywayModuleConfig.java
similarity index 50%
copy from quarkus/addons/persistence/jdbc/runtime/src/main/java/org/kie/kogito/persistence/quarkus/KogitoAddOnPersistenceJDBCConfigSource.java
copy to addons/common/flyway/src/main/java/org/kie/flyway/model/KieFlywayModuleConfig.java
index 9e0a7e8791..16321a618e 100644
--- a/quarkus/addons/persistence/jdbc/runtime/src/main/java/org/kie/kogito/persistence/quarkus/KogitoAddOnPersistenceJDBCConfigSource.java
+++ b/addons/common/flyway/src/main/java/org/kie/flyway/model/KieFlywayModuleConfig.java
@@ -16,40 +16,30 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.kie.kogito.persistence.quarkus;
-import java.util.Map;
-import java.util.Set;
+package org.kie.flyway.model;
-import org.eclipse.microprofile.config.spi.ConfigSource;
+import java.util.Map;
+import java.util.TreeMap;
-public class KogitoAddOnPersistenceJDBCConfigSource implements ConfigSource {
+public class KieFlywayModuleConfig {
- static final Integer ORDINAL = 500;
+ public static final String DEFAULT_DB = "default";
- private final Map<String, String> configuration;
+ private final String module;
+ private final Map<String, String[]> locations = new TreeMap<>(String.CASE_INSENSITIVE_ORDER);
- public KogitoAddOnPersistenceJDBCConfigSource(Map<String, String> configuration) {
- this.configuration = configuration;
+ public KieFlywayModuleConfig(String module, Map<String, String[]> locations) {
+ this.module = module;
+ this.locations.putAll(locations);
}
- @Override
- public Set<String> getPropertyNames() {
- return configuration.keySet();
+ public String getModule() {
+ return module;
}
- @Override
- public int getOrdinal() {
- return ORDINAL;
+ public String[] getDBScriptLocations(String dbType) {
+ return this.locations.getOrDefault(dbType, locations.get(DEFAULT_DB));
}
- @Override
- public String getValue(String propertyName) {
- return configuration.get(propertyName);
- }
-
- @Override
- public String getName() {
- return KogitoAddOnPersistenceJDBCConfigSource.class.getSimpleName();
- }
}
diff --git a/addons/common/flyway/src/test/java/org/kie/flyway/initializer/KieFlywayInitializerTest.java b/addons/common/flyway/src/test/java/org/kie/flyway/initializer/KieFlywayInitializerTest.java
new file mode 100644
index 0000000000..425c3b32c9
--- /dev/null
+++ b/addons/common/flyway/src/test/java/org/kie/flyway/initializer/KieFlywayInitializerTest.java
@@ -0,0 +1,174 @@
+/*
+ * 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.initializer;
+
+import java.util.*;
+import java.util.stream.Stream;
+
+import org.assertj.core.api.Assertions;
+import org.junit.jupiter.api.*;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.Arguments;
+import org.junit.jupiter.params.provider.MethodSource;
+import org.kie.flyway.KieFlywayException;
+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.utils.TestClassLoader;
+import org.kie.kogito.testcontainers.KogitoPostgreSqlContainer;
+import org.testcontainers.junit.jupiter.Container;
+import org.testcontainers.junit.jupiter.Testcontainers;
+
+import static org.kie.flyway.test.models.TestModels.*;
+
+@Testcontainers
+@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
+public class KieFlywayInitializerTest extends AbstractKieFlywayTest {
+
+ @Container
+ private static final KogitoPostgreSqlContainer PG_CONTAINER = new KogitoPostgreSqlContainer();
+
+ private static PostgreSQLTestDataSource PG_DATA_SOURCE;
+ private static H2TestDataSource H2_DATA_SOURCE;
+
+ private TestClassLoader classLoader;
+
+ @BeforeAll
+ public static void start() {
+ PG_CONTAINER.start();
+ PG_DATA_SOURCE = new PostgreSQLTestDataSource(PG_CONTAINER);
+ H2_DATA_SOURCE = new H2TestDataSource();
+ }
+
+ public static Stream<Arguments> getDataSources() {
+ return Stream.of(Arguments.of(PG_DATA_SOURCE),
+ Arguments.of(H2_DATA_SOURCE));
+ }
+
+ @BeforeEach
+ public void init() {
+ classLoader = new TestClassLoader(this.getClass().getClassLoader());
+ }
+
+ @ParameterizedTest
+ @MethodSource("getDataSources")
+ public void testTestKieFlywayInitializerBuilderValidations(TestDataSource dataSource) {
+ Assertions.assertThatThrownBy(() -> KieFlywayInitializer.builder()
+ .build()).isInstanceOf(KieFlywayException.class)
+ .hasMessage("Cannot create KieFlywayInitializer migration, dataSource is null.");
+
+ classLoader.addKieFlywayModule("initializers/kie-flyway.no.locations.properties");
+
+ Assertions.assertThatThrownBy(() -> KieFlywayInitializer.builder()
+ .withDatasource(dataSource.getDataSource())
+ .withClassLoader(classLoader).build().migrate())
+ .isInstanceOf(KieFlywayException.class)
+ .hasMessageContaining("Cannot run Flyway migration for module `no-locations`, cannot find SQL Script locations for db");
+ }
+
+ @ParameterizedTest
+ @MethodSource("getDataSources")
+ public void testKieFlywayInitializerValidations(TestDataSource dataSource) {
+ classLoader.addKieFlywayModule("initializers/kie-flyway.duplicated1.properties");
+ classLoader.addKieFlywayModule("initializers/kie-flyway.duplicated1.properties");
+ classLoader.addKieFlywayModule("initializers/kie-flyway.duplicated2.properties");
+ classLoader.addKieFlywayModule("initializers/kie-flyway.duplicated2.properties");
+
+ Assertions.assertThatThrownBy(() -> {
+ KieFlywayInitializer.builder()
+ .withDatasource(dataSource.getDataSource())
+ .withClassLoader(classLoader)
+ .build()
+ .migrate();
+ }).isInstanceOf(KieFlywayException.class)
+ .hasMessage("Cannot run Kie Flyway migration: Duplicated Modules found test-duplicated-1, test-duplicated-2");
+
+ }
+
+ @Order(1)
+ @ParameterizedTest
+ @MethodSource("getDataSources")
+ public void testFlywayMigrationsWithExclusions(TestDataSource dataSource) {
+
+ classLoader.addKieFlywayModule("initializers/kie-flyway.customers.properties");
+ classLoader.addKieFlywayModule("initializers/kie-flyway.guitars.properties");
+
+ KieFlywayInitializer.builder()
+ .withDatasource(dataSource.getDataSource())
+ .withClassLoader(classLoader)
+ .withModuleExclusions(List.of("guitars"))
+ .build()
+ .migrate();
+
+ validateKieFlywayIndex("customers", EXPECTED_CUSTOMERS_MIGRATIONS.stream().limit(3).toList(), dataSource);
+ validateCustomersData(EXPECTED_CUSTOMERS.stream().limit(2).toList(), dataSource);
+
+ // Guitars module has been excluded, so it shouldn't be installed. Verifying that tables don't exist
+ verifyTableDoesntExist("guitars", dataSource);
+ verifyTableDoesntExist("kie_flyway_history_guitars", dataSource);
+ }
+
+ @Order(2)
+ @ParameterizedTest
+ @MethodSource("getDataSources")
+ public void testFlywayMigrationsUpgrade(TestDataSource dataSource) {
+
+ classLoader.addKieFlywayModule("initializers/kie-flyway.customers2.properties");
+ classLoader.addKieFlywayModule("initializers/kie-flyway.guitars.properties");
+
+ KieFlywayInitializer.builder()
+ .withDatasource(dataSource.getDataSource())
+ .withClassLoader(classLoader)
+ .withModuleExclusions(List.of("test-3"))
+ .build()
+ .migrate();
+
+ validateKieFlywayIndex("customers", EXPECTED_CUSTOMERS_MIGRATIONS, dataSource);
+ validateCustomersData(EXPECTED_CUSTOMERS, dataSource);
+
+ validateKieFlywayIndex("guitars", EXPECTED_GUITARS_MIGRATIONS, dataSource);
+ validateGuitarsData(dataSource);
+ }
+
+ @Test
+ public void testFlywayMigrationWithFallbackDBType() {
+ classLoader.addKieFlywayModule("initializers/kie-flyway.guitars_default.properties");
+
+ H2TestDataSource dataSource = new H2TestDataSource();
+
+ KieFlywayInitializer.builder()
+ .withDatasource(dataSource.getDataSource())
+ .withClassLoader(classLoader)
+ .build()
+ .migrate();
+
+ validateKieFlywayIndex("guitars", EXPECTED_GUITARS_MIGRATIONS, dataSource);
+ validateGuitarsData(dataSource);
+
+ dataSource.shutDown();
+ }
+
+ @AfterAll
+ public static void shutdown() {
+ H2_DATA_SOURCE.shutDown();
+ }
+
+}
diff --git a/addons/common/flyway/src/test/java/org/kie/flyway/initializer/impl/DefaultKieModuleFlywayConfigLoaderTest.java b/addons/common/flyway/src/test/java/org/kie/flyway/initializer/impl/DefaultKieModuleFlywayConfigLoaderTest.java
new file mode 100644
index 0000000000..139f48c649
--- /dev/null
+++ b/addons/common/flyway/src/test/java/org/kie/flyway/initializer/impl/DefaultKieModuleFlywayConfigLoaderTest.java
@@ -0,0 +1,94 @@
+/*
+ * 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.initializer.impl;
+
+import java.util.Collection;
+
+import org.assertj.core.api.Assertions;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.kie.flyway.KieFlywayException;
+import org.kie.flyway.model.KieFlywayModuleConfig;
+import org.kie.flyway.test.utils.TestClassLoader;
+
+public class DefaultKieModuleFlywayConfigLoaderTest {
+
+ private static final String H2_LOCATIONS = "classpath:kie-flyway/db/test/h2";
+ private static final String PGSQL_LOCATIONS = "classpath:kie-flyway/db/test/postgresql";
+ private static final String DEFAULT_LOCATIONS = "classpath:kie-flyway/db/test/ansi";
+
+ private TestClassLoader testClassLoader;
+ private DefaultKieModuleFlywayConfigLoader flywayConfigLoader;
+
+ @BeforeEach
+ public void init() {
+ this.testClassLoader = new TestClassLoader(this.getClass().getClassLoader());
+ this.flywayConfigLoader = new DefaultKieModuleFlywayConfigLoader(testClassLoader);
+ }
+
+ @Test
+ public void testDefaultLoading() {
+
+ Collection<KieFlywayModuleConfig> configs = flywayConfigLoader.loadModuleConfigs();
+
+ Assertions.assertThat(configs)
+ .hasSize(1);
+
+ Assertions.assertThat(configs.iterator().next())
+ .isNotNull()
+ .hasFieldOrPropertyWithValue("module", "test")
+ .returns(H2_LOCATIONS, kieFlywayModuleConfig -> kieFlywayModuleConfig.getDBScriptLocations("h2")[0])
+ .returns(PGSQL_LOCATIONS, kieFlywayModuleConfig -> kieFlywayModuleConfig.getDBScriptLocations("postgresql")[0])
+ .returns(DEFAULT_LOCATIONS, kieFlywayModuleConfig -> kieFlywayModuleConfig.getDBScriptLocations("db2")[0]);
+ }
+
+ @Test
+ public void testEmptyConfigFile() {
+ testClassLoader.addKieFlywayModule("initializers/kie-flyway.empty.properties");
+
+ Assertions.assertThatThrownBy(() -> flywayConfigLoader.loadModuleConfigs())
+ .isInstanceOf(KieFlywayException.class)
+ .hasMessage("Could not load ModuleFlywayConfig")
+ .cause()
+ .isInstanceOf(KieFlywayException.class)
+ .hasMessageStartingWith("Could not load module name from");
+ }
+
+ @Test
+ public void testWrongLocationsFormat() {
+ testClassLoader.addKieFlywayModule("initializers/kie-flyway.wrong.format.properties");
+
+ Assertions.assertThatThrownBy(() -> flywayConfigLoader.loadModuleConfigs())
+ .isInstanceOf(KieFlywayException.class)
+ .hasMessage("Could not load ModuleFlywayConfig")
+ .cause()
+ .isInstanceOf(KieFlywayException.class)
+ .hasMessage("Cannot load module `test-wrong-format` config, file has wrong format");
+ }
+
+ @Test
+ public void testWrongResourceFile() {
+ testClassLoader.addKieFlywayModule("wrong content");
+
+ Assertions.assertThatThrownBy(() -> flywayConfigLoader.loadModuleConfigs())
+ .isInstanceOf(KieFlywayException.class)
+ .hasMessage("Could not load ModuleFlywayConfig");
+ }
+}
diff --git a/addons/common/flyway/src/test/java/org/kie/flyway/integration/KieFlywayRunnerTest.java b/addons/common/flyway/src/test/java/org/kie/flyway/integration/KieFlywayRunnerTest.java
new file mode 100644
index 0000000000..bd510d9994
--- /dev/null
+++ b/addons/common/flyway/src/test/java/org/kie/flyway/integration/KieFlywayRunnerTest.java
@@ -0,0 +1,141 @@
+/*
+ * 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.integration;
+
+import java.util.HashMap;
+
+import javax.sql.DataSource;
+
+import org.assertj.core.api.Assertions;
+import org.junit.jupiter.api.*;
+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.utils.TestClassLoader;
+
+import static org.kie.flyway.test.models.TestModels.*;
+import static org.mockito.Mockito.mock;
+
+@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
+public class KieFlywayRunnerTest extends AbstractKieFlywayTest {
+
+ private static final TestDataSource TEST_DATA_SOURCE;
+
+ static {
+ TEST_DATA_SOURCE = new H2TestDataSource();
+ }
+
+ private TestClassLoader testClassLoader;
+ private TestKieFlywayConfiguration testConfiguration;
+
+ @BeforeEach
+ public void init() {
+ testClassLoader = new TestClassLoader(this.getClass().getClassLoader());
+ testConfiguration = new TestKieFlywayConfiguration(true, new HashMap<>());
+ }
+
+ @Test
+ public void testValidations() {
+ Assertions.assertThatThrownBy(() -> KieFlywayRunner.get(null).runFlyway(null))
+ .isInstanceOf(KieFlywayException.class)
+ .hasMessage("Kie Flyway: Cannot run Kie Flyway migration configuration is null.");
+
+ Assertions.assertThatThrownBy(() -> KieFlywayRunner.get(testConfiguration).runFlyway(null)).isInstanceOf(KieFlywayException.class)
+ .hasMessage("Kie Flyway: Cannot run Kie Flyway migration default datasource is null");
+
+ // Mocking DataSource to make sure we cannot resolve dbType.
+ DataSource mockedDS = mock(DataSource.class);
+
+ Assertions.assertThatThrownBy(() -> KieFlywayRunner.get(testConfiguration).runFlyway(mockedDS))
+ .isInstanceOf(KieFlywayException.class)
+ .hasMessage("Kie Flyway: Couldn't extract database product name from datasource.");
+ }
+
+ @Test
+ @Order(0)
+ public void testFlywayMigrationsWithDisabledConfig() {
+ testClassLoader.addKieFlywayModule("initializers/kie-flyway.customers.properties");
+ testClassLoader.addKieFlywayModule("initializers/kie-flyway.guitars.properties");
+
+ testConfiguration.setEnabled(false);
+
+ TestKieFlywayRunner.get(testConfiguration, testClassLoader)
+ .runFlyway(TEST_DATA_SOURCE.getDataSource());
+
+ verifyTableDoesntExist("customers", TEST_DATA_SOURCE);
+ verifyTableDoesntExist("kie_flyway_history_customers", TEST_DATA_SOURCE);
+ verifyTableDoesntExist("guitars", TEST_DATA_SOURCE);
+ verifyTableDoesntExist("kie_flyway_history_guitars", TEST_DATA_SOURCE);
+ }
+
+ @Test
+ @Order(1)
+ public void testFlywayMigrationsWithExclusions() {
+
+ testConfiguration.getModules().put("guitars", new TestKieFlywayNamedModule(false));
+
+ testClassLoader.addKieFlywayModule("initializers/kie-flyway.customers.properties");
+ testClassLoader.addKieFlywayModule("initializers/kie-flyway.guitars.properties");
+
+ TestKieFlywayRunner.get(testConfiguration, testClassLoader)
+ .runFlyway(TEST_DATA_SOURCE.getDataSource());
+
+ validateKieFlywayIndex("customers", EXPECTED_CUSTOMERS_MIGRATIONS.stream().limit(3).toList(), TEST_DATA_SOURCE);
+ validateCustomersData(EXPECTED_CUSTOMERS.stream().limit(2).toList(), TEST_DATA_SOURCE);
+
+ // Guitars module has been excluded, so it shouldn't be installed. Verifying that tables don't exist
+ verifyTableDoesntExist("guitars", TEST_DATA_SOURCE);
+ verifyTableDoesntExist("kie_flyway_history_guitars", TEST_DATA_SOURCE);
+ }
+
+ @Test
+ @Order(2)
+ public void testFlywayMigrationsUpgrade() {
+
+ testClassLoader.addKieFlywayModule("initializers/kie-flyway.customers2.properties");
+ testClassLoader.addKieFlywayModule("initializers/kie-flyway.guitars.properties");
+
+ TestKieFlywayRunner.get(testConfiguration, testClassLoader)
+ .runFlyway(TEST_DATA_SOURCE.getDataSource());
+
+ validateKieFlywayIndex("customers", EXPECTED_CUSTOMERS_MIGRATIONS, TEST_DATA_SOURCE);
+ validateCustomersData(EXPECTED_CUSTOMERS, TEST_DATA_SOURCE);
+
+ validateKieFlywayIndex("guitars", EXPECTED_GUITARS_MIGRATIONS, TEST_DATA_SOURCE);
+ validateGuitarsData(TEST_DATA_SOURCE);
+ }
+
+ @AfterAll
+ public static void shutdown() {
+ TEST_DATA_SOURCE.shutDown();
+ }
+
+ public static class TestKieFlywayRunner extends KieFlywayRunner {
+
+ protected TestKieFlywayRunner(KieFlywayConfiguration<? extends KieFlywayNamedModule> configuration, ClassLoader classLoader) {
+ super(configuration, classLoader);
+ }
+
+ public static KieFlywayRunner get(TestKieFlywayConfiguration configuration, ClassLoader classLoader) {
+ return new TestKieFlywayRunner(configuration, classLoader);
+ }
+ }
+}
diff --git a/quarkus/addons/persistence/jdbc/runtime/src/main/java/org/kie/kogito/persistence/quarkus/KogitoAddOnPersistenceJDBCConfigSource.java b/addons/common/flyway/src/test/java/org/kie/flyway/integration/TestKieFlywayConfiguration.java
similarity index 52%
copy from quarkus/addons/persistence/jdbc/runtime/src/main/java/org/kie/kogito/persistence/quarkus/KogitoAddOnPersistenceJDBCConfigSource.java
copy to addons/common/flyway/src/test/java/org/kie/flyway/integration/TestKieFlywayConfiguration.java
index 9e0a7e8791..1d20272a08 100644
--- a/quarkus/addons/persistence/jdbc/runtime/src/main/java/org/kie/kogito/persistence/quarkus/KogitoAddOnPersistenceJDBCConfigSource.java
+++ b/addons/common/flyway/src/test/java/org/kie/flyway/integration/TestKieFlywayConfiguration.java
@@ -16,40 +16,32 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.kie.kogito.persistence.quarkus;
-import java.util.Map;
-import java.util.Set;
-
-import org.eclipse.microprofile.config.spi.ConfigSource;
+package org.kie.flyway.integration;
-public class KogitoAddOnPersistenceJDBCConfigSource implements ConfigSource {
+import java.util.Map;
- static final Integer ORDINAL = 500;
+public class TestKieFlywayConfiguration implements KieFlywayConfiguration<TestKieFlywayNamedModule> {
- private final Map<String, String> configuration;
+ private boolean enabled;
+ private Map<String, TestKieFlywayNamedModule> modules;
- public KogitoAddOnPersistenceJDBCConfigSource(Map<String, String> configuration) {
- this.configuration = configuration;
+ public TestKieFlywayConfiguration(boolean enabled, Map<String, TestKieFlywayNamedModule> modules) {
+ this.enabled = enabled;
+ this.modules = modules;
}
- @Override
- public Set<String> getPropertyNames() {
- return configuration.keySet();
- }
-
- @Override
- public int getOrdinal() {
- return ORDINAL;
+ public void setEnabled(boolean enabled) {
+ this.enabled = enabled;
}
@Override
- public String getValue(String propertyName) {
- return configuration.get(propertyName);
+ public boolean isEnabled() {
+ return enabled;
}
@Override
- public String getName() {
- return KogitoAddOnPersistenceJDBCConfigSource.class.getSimpleName();
+ public Map<String, TestKieFlywayNamedModule> getModules() {
+ return modules;
}
}
diff --git a/addons/common/flyway/src/test/java/org/kie/flyway/integration/TestKieFlywayNamedModule.java b/addons/common/flyway/src/test/java/org/kie/flyway/integration/TestKieFlywayNamedModule.java
new file mode 100644
index 0000000000..8eea404acc
--- /dev/null
+++ b/addons/common/flyway/src/test/java/org/kie/flyway/integration/TestKieFlywayNamedModule.java
@@ -0,0 +1,34 @@
+/*
+ * 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.integration;
+
+public class TestKieFlywayNamedModule implements KieFlywayNamedModule {
+
+ private boolean enabled;
+
+ public TestKieFlywayNamedModule(boolean enabled) {
+ this.enabled = enabled;
+ }
+
+ @Override
+ public boolean isEnabled() {
+ return enabled;
+ }
+}
diff --git a/addons/common/flyway/src/test/java/org/kie/flyway/test/AbstractKieFlywayTest.java b/addons/common/flyway/src/test/java/org/kie/flyway/test/AbstractKieFlywayTest.java
new file mode 100644
index 0000000000..3a6ff7fa3f
--- /dev/null
+++ b/addons/common/flyway/src/test/java/org/kie/flyway/test/AbstractKieFlywayTest.java
@@ -0,0 +1,128 @@
+/*
+ * 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.test;
+
+import java.sql.Connection;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.util.Collection;
+
+import org.assertj.core.api.Assertions;
+import org.kie.flyway.initializer.KieFlywayInitializerTest;
+import org.kie.flyway.test.dataSources.TestDataSource;
+import org.kie.flyway.test.models.Customer;
+import org.kie.flyway.test.models.Guitar;
+import org.kie.flyway.test.models.KieFlywayMigration;
+
+import static org.kie.flyway.test.models.TestModels.EXPECTED_GUITARS;
+
+public abstract class AbstractKieFlywayTest {
+ public static final String MODULE_MIGRATIONS_QUERY_TEMPLATE = "select \"version\", \"description\", \"success\" from \"kie_flyway_history_%s\" where \"version\" = ?";
+ public static final String QUERY_CUSTOMERS_DATA = "select id, name, last_name, email from customers order by id";
+ public static final String QUERY_GUITARS_DATA = "select id, brand, model, rating from guitars order by id";
+ public static final String QUERY_QUERY_TABLE_EXISTS = "select count(*) as count from information_schema.tables where table_name = ?";
+
+ public void validateKieFlywayIndex(String moduleName, Collection<KieFlywayMigration> expectedMigrations, TestDataSource dataSource) {
+ expectedMigrations.forEach(kieFlywayMigration -> validateFlywayMigration(moduleName, kieFlywayMigration, dataSource));
+ }
+
+ private void validateFlywayMigration(final String moduleName, final KieFlywayMigration migration, final TestDataSource dataSource) {
+ try (Connection con = dataSource.getDataSource().getConnection();
+ PreparedStatement stmt = con.prepareStatement(KieFlywayInitializerTest.MODULE_MIGRATIONS_QUERY_TEMPLATE.formatted(moduleName));) {
+ stmt.setString(1, migration.version());
+ try (ResultSet rs = stmt.executeQuery()) {
+ Assertions.assertThat(rs.next())
+ .isTrue();
+ Assertions.assertThat(rs.getString("version"))
+ .isEqualTo(migration.version());
+ Assertions.assertThat(rs.getString("description"))
+ .isEqualTo(migration.description().formatted(dataSource.getDbType()));
+ Assertions.assertThat(rs.getBoolean("success"))
+ .isEqualTo(true);
+ Assertions.assertThat(rs.next())
+ .isFalse();
+ }
+ } catch (Exception ex) {
+ throw new RuntimeException(ex);
+ }
+ }
+
+ protected void validateCustomersData(Collection<Customer> expectedCustomers, TestDataSource dataSource) {
+ try (Connection con = dataSource.getDataSource().getConnection();
+ PreparedStatement stmt = con.prepareStatement(KieFlywayInitializerTest.QUERY_CUSTOMERS_DATA);
+ ResultSet rs = stmt.executeQuery()) {
+
+ for (Customer customer : expectedCustomers) {
+ Assertions.assertThat(rs.next())
+ .isTrue();
+ Assertions.assertThat(rs.getInt("id"))
+ .isEqualTo(customer.id());
+ Assertions.assertThat(rs.getString("name"))
+ .isEqualTo(customer.name());
+ Assertions.assertThat(rs.getString("last_name"))
+ .isEqualTo(customer.lastName());
+ Assertions.assertThat(rs.getString("email"))
+ .isEqualTo(customer.email());
+ }
+ Assertions.assertThat(rs.next())
+ .isFalse();
+ } catch (Exception ex) {
+ throw new RuntimeException(ex);
+ }
+ }
+
+ protected void validateGuitarsData(TestDataSource dataSource) {
+ try (Connection con = dataSource.getDataSource().getConnection();
+ PreparedStatement stmt = con.prepareStatement(KieFlywayInitializerTest.QUERY_GUITARS_DATA);
+ ResultSet rs = stmt.executeQuery()) {
+
+ for (Guitar guitar : EXPECTED_GUITARS) {
+ Assertions.assertThat(rs.next())
+ .isTrue();
+ Assertions.assertThat(rs.getInt("id"))
+ .isEqualTo(guitar.id());
+ Assertions.assertThat(rs.getString("brand"))
+ .isEqualTo(guitar.brand());
+ Assertions.assertThat(rs.getString("model"))
+ .isEqualTo(guitar.model());
+ Assertions.assertThat(rs.getInt("rating"))
+ .isEqualTo(guitar.rating());
+ }
+
+ Assertions.assertThat(rs.next())
+ .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);) {
+ stmt.setString(1, tableName);
+ try (ResultSet rs = stmt.executeQuery()) {
+ Assertions.assertThat(rs.next()).isTrue();
+ Assertions.assertThat(rs.getInt("count")).isEqualTo(0);
+ }
+ } catch (Exception ex) {
+ throw new RuntimeException(ex);
+ }
+ }
+}
diff --git a/addons/common/flyway/src/test/java/org/kie/flyway/test/dataSources/H2TestDataSource.java b/addons/common/flyway/src/test/java/org/kie/flyway/test/dataSources/H2TestDataSource.java
new file mode 100644
index 0000000000..1b811681f6
--- /dev/null
+++ b/addons/common/flyway/src/test/java/org/kie/flyway/test/dataSources/H2TestDataSource.java
@@ -0,0 +1,62 @@
+/*
+ * 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.test.dataSources;
+
+import java.sql.Connection;
+import java.sql.SQLException;
+import java.sql.Statement;
+
+import javax.sql.DataSource;
+
+import org.h2.jdbcx.JdbcDataSource;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class H2TestDataSource implements TestDataSource {
+ private static final Logger LOGGER = LoggerFactory.getLogger(H2TestDataSource.class);
+
+ private final JdbcDataSource dataSource;
+
+ public H2TestDataSource() {
+ dataSource = new JdbcDataSource();
+ dataSource.setURL("jdbc:h2:mem:test_db;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=true");
+ dataSource.setUser("sa");
+ dataSource.setPassword("sa");
+ }
+
+ @Override
+ public String getDbType() {
+ return "h2";
+ }
+
+ @Override
+ public DataSource getDataSource() {
+ return dataSource;
+ }
+
+ @Override
+ public void shutDown() {
+ try (Connection con = dataSource.getConnection(); Statement stmt = con.createStatement()) {
+ stmt.execute("SHUTDOWN");
+ } catch (SQLException e) {
+ LOGGER.warn("Error shutting down database", e);
+ }
+ }
+}
diff --git a/addons/common/persistence/jdbc/src/test/java/org/kie/persistence/jdbc/PostgreSqlProcessInstancesIT.java b/addons/common/flyway/src/test/java/org/kie/flyway/test/dataSources/PostgreSQLTestDataSource.java
similarity index 53%
copy from addons/common/persistence/jdbc/src/test/java/org/kie/persistence/jdbc/PostgreSqlProcessInstancesIT.java
copy to addons/common/flyway/src/test/java/org/kie/flyway/test/dataSources/PostgreSQLTestDataSource.java
index 3840a9c430..dc909d0fa5 100644
--- a/addons/common/persistence/jdbc/src/test/java/org/kie/persistence/jdbc/PostgreSqlProcessInstancesIT.java
+++ b/addons/common/flyway/src/test/java/org/kie/flyway/test/dataSources/PostgreSQLTestDataSource.java
@@ -16,33 +16,32 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.kie.persistence.jdbc;
+
+package org.kie.flyway.test.dataSources;
import javax.sql.DataSource;
-import org.junit.jupiter.api.BeforeAll;
import org.kie.kogito.testcontainers.KogitoPostgreSqlContainer;
import org.postgresql.ds.PGSimpleDataSource;
-import org.testcontainers.junit.jupiter.Container;
-import org.testcontainers.junit.jupiter.Testcontainers;
-
-@Testcontainers
-public class PostgreSqlProcessInstancesIT extends AbstractProcessInstancesIT {
-
- @Container
- private final static KogitoPostgreSqlContainer PG_CONTAINER = new KogitoPostgreSqlContainer();
- private static PGSimpleDataSource PG_DATA_SOURCE;
-
- @BeforeAll
- public static void start() {
- PG_DATA_SOURCE = new PGSimpleDataSource();
- PG_DATA_SOURCE.setUrl(PG_CONTAINER.getJdbcUrl());
- PG_DATA_SOURCE.setUser(PG_CONTAINER.getUsername());
- PG_DATA_SOURCE.setPassword(PG_CONTAINER.getPassword());
- initMigration(PG_CONTAINER, "postgresql");
+
+public class PostgreSQLTestDataSource implements TestDataSource {
+
+ private PGSimpleDataSource dataSource;
+
+ public PostgreSQLTestDataSource(KogitoPostgreSqlContainer pgContainer) {
+ dataSource = new PGSimpleDataSource();
+ dataSource.setUrl(pgContainer.getJdbcUrl());
+ dataSource.setUser(pgContainer.getUsername());
+ dataSource.setPassword(pgContainer.getPassword());
+ }
+
+ @Override
+ public String getDbType() {
+ return "postgresql";
}
- protected DataSource getDataSource() {
- return PG_DATA_SOURCE;
+ @Override
+ public DataSource getDataSource() {
+ return dataSource;
}
}
diff --git a/addons/common/flyway/src/test/java/org/kie/flyway/test/dataSources/TestDataSource.java b/addons/common/flyway/src/test/java/org/kie/flyway/test/dataSources/TestDataSource.java
new file mode 100644
index 0000000000..0a0ecc6974
--- /dev/null
+++ b/addons/common/flyway/src/test/java/org/kie/flyway/test/dataSources/TestDataSource.java
@@ -0,0 +1,33 @@
+/*
+ * 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.test.dataSources;
+
+import javax.sql.DataSource;
+
+public interface TestDataSource {
+
+ String getDbType();
+
+ DataSource getDataSource();
+
+ default void shutDown() {
+
+ }
+}
diff --git a/addons/common/flyway/src/test/java/org/kie/flyway/test/models/Customer.java b/addons/common/flyway/src/test/java/org/kie/flyway/test/models/Customer.java
new file mode 100644
index 0000000000..607a7084a8
--- /dev/null
+++ b/addons/common/flyway/src/test/java/org/kie/flyway/test/models/Customer.java
@@ -0,0 +1,23 @@
+/*
+ * 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.test.models;
+
+public record Customer(Integer id, String name, String lastName, String email) {
+}
diff --git a/addons/common/flyway/src/test/java/org/kie/flyway/test/models/Guitar.java b/addons/common/flyway/src/test/java/org/kie/flyway/test/models/Guitar.java
new file mode 100644
index 0000000000..f914b01193
--- /dev/null
+++ b/addons/common/flyway/src/test/java/org/kie/flyway/test/models/Guitar.java
@@ -0,0 +1,23 @@
+/*
+ * 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.test.models;
+
+public record Guitar(Integer id, String brand, String model, Integer rating) {
+}
diff --git a/addons/common/flyway/src/test/java/org/kie/flyway/test/models/KieFlywayMigration.java b/addons/common/flyway/src/test/java/org/kie/flyway/test/models/KieFlywayMigration.java
new file mode 100644
index 0000000000..7df23f76a5
--- /dev/null
+++ b/addons/common/flyway/src/test/java/org/kie/flyway/test/models/KieFlywayMigration.java
@@ -0,0 +1,23 @@
+/*
+ * 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.test.models;
+
+public record KieFlywayMigration(String version, String description) {
+}
diff --git a/addons/common/flyway/src/test/java/org/kie/flyway/test/models/TestModels.java b/addons/common/flyway/src/test/java/org/kie/flyway/test/models/TestModels.java
new file mode 100644
index 0000000000..8a13692ca2
--- /dev/null
+++ b/addons/common/flyway/src/test/java/org/kie/flyway/test/models/TestModels.java
@@ -0,0 +1,50 @@
+/*
+ * 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.test.models;
+
+import java.util.Arrays;
+import java.util.Collection;
+
+public interface TestModels {
+
+ static final Collection<KieFlywayMigration> EXPECTED_CUSTOMERS_MIGRATIONS = Arrays.asList(
+ new KieFlywayMigration("1.0.0", "Create table %s"),
+ new KieFlywayMigration("1.0.1", "Alter table %s"),
+ new KieFlywayMigration("1.0.2", "Insert book characters %s"),
+ new KieFlywayMigration("1.0.5", "Insert game characters %s"));
+
+ static final Collection<Customer> EXPECTED_CUSTOMERS = Arrays.asList(new Customer(1, "Ned", "Stark", "n.stark@winterfell.book"),
+ new Customer(2, "Ender", "Wiggin", "ender@endersgame.book"),
+ new Customer(3, "Guybrush", "Threepwood", "guybrush@monkeyisland.game"),
+ new Customer(4, "Herman", "Toothrot", "toothrot@monkeyisland.game"));
+
+ static final Collection<KieFlywayMigration> EXPECTED_GUITARS_MIGRATIONS = Arrays.asList(
+ new KieFlywayMigration("1.0.0", "Create guitars table %s"),
+ new KieFlywayMigration("1.0.1", "Alter guitars table %s"),
+ new KieFlywayMigration("1.0.2", "Insert fender guitars %s"),
+ new KieFlywayMigration("1.0.5", "Insert gibson guitars %s"));
+
+ static final Collection<Guitar> EXPECTED_GUITARS = Arrays.asList(new Guitar(1, "Fender", "Telecaster", 10),
+ new Guitar(2, "Fender", "Stratocaster", 9),
+ new Guitar(3, "Fender", "Jazzmaster", 7),
+ new Guitar(4, "Gibson", "SG", 9),
+ new Guitar(5, "Gibson", "Les Paul", 9),
+ new Guitar(6, "Gibson", "ES-330", 10));
+}
diff --git a/quarkus/addons/persistence/jdbc/runtime/src/main/java/org/kie/kogito/persistence/quarkus/KogitoAddOnPersistenceJDBCConfigSource.java b/addons/common/flyway/src/test/java/org/kie/flyway/test/utils/TestClassLoader.java
similarity index 50%
copy from quarkus/addons/persistence/jdbc/runtime/src/main/java/org/kie/kogito/persistence/quarkus/KogitoAddOnPersistenceJDBCConfigSource.java
copy to addons/common/flyway/src/test/java/org/kie/flyway/test/utils/TestClassLoader.java
index 9e0a7e8791..7b55cd237f 100644
--- a/quarkus/addons/persistence/jdbc/runtime/src/main/java/org/kie/kogito/persistence/quarkus/KogitoAddOnPersistenceJDBCConfigSource.java
+++ b/addons/common/flyway/src/test/java/org/kie/flyway/test/utils/TestClassLoader.java
@@ -16,40 +16,32 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.kie.kogito.persistence.quarkus;
-import java.util.Map;
-import java.util.Set;
+package org.kie.flyway.test.utils;
-import org.eclipse.microprofile.config.spi.ConfigSource;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.stream.Stream;
-public class KogitoAddOnPersistenceJDBCConfigSource implements ConfigSource {
+import org.kie.flyway.initializer.impl.DefaultKieModuleFlywayConfigLoader;
- static final Integer ORDINAL = 500;
+public class TestClassLoader extends ClassLoader {
+ private final List<URL> modules = new ArrayList<>();
- private final Map<String, String> configuration;
-
- public KogitoAddOnPersistenceJDBCConfigSource(Map<String, String> configuration) {
- this.configuration = configuration;
- }
-
- @Override
- public Set<String> getPropertyNames() {
- return configuration.keySet();
+ public TestClassLoader(ClassLoader parent) {
+ super(parent);
}
- @Override
- public int getOrdinal() {
- return ORDINAL;
- }
-
- @Override
- public String getValue(String propertyName) {
- return configuration.get(propertyName);
+ public void addKieFlywayModule(String resourceUrl) {
+ this.modules.add(getResource(resourceUrl));
}
@Override
- public String getName() {
- return KogitoAddOnPersistenceJDBCConfigSource.class.getSimpleName();
+ public Stream<URL> resources(String name) {
+ if (!modules.isEmpty() && DefaultKieModuleFlywayConfigLoader.KIE_FLYWAY_DESCRIPTOR_FILE_LOCATION.equals(name)) {
+ return modules.stream();
+ }
+ return super.resources(name);
}
}
diff --git a/springboot/integration-tests/integration-tests-springboot-processes-persistence-it/integration-tests-springboot-processes-jdbc/src/main/resources/application.properties b/addons/common/flyway/src/test/resources/META-INF/kie-flyway.properties
similarity index 80%
copy from springboot/integration-tests/integration-tests-springboot-processes-persistence-it/integration-tests-springboot-processes-jdbc/src/main/resources/application.properties
copy to addons/common/flyway/src/test/resources/META-INF/kie-flyway.properties
index 2b28c3283b..a4f89f2416 100644
--- a/springboot/integration-tests/integration-tests-springboot-processes-persistence-it/integration-tests-springboot-processes-jdbc/src/main/resources/application.properties
+++ b/addons/common/flyway/src/test/resources/META-INF/kie-flyway.properties
@@ -17,9 +17,8 @@
# under the License.
#
-server.address=0.0.0.0
+module.name=test
-kogito.persistence.type=jdbc
-
-spring.flyway.locations=classpath:db/{vendor}
-spring.flyway.enabled=true
+module.locations.h2=classpath:kie-flyway/db/test/h2
+module.locations.postgresql=classpath:kie-flyway/db/test/postgresql
+module.locations.default=classpath:kie-flyway/db/test/ansi
\ No newline at end of file
diff --git a/springboot/integration-tests/integration-tests-springboot-processes-persistence-it/integration-tests-springboot-processes-jdbc/src/main/resources/application.properties b/addons/common/flyway/src/test/resources/initializers/kie-flyway.customers.properties
similarity index 78%
copy from springboot/integration-tests/integration-tests-springboot-processes-persistence-it/integration-tests-springboot-processes-jdbc/src/main/resources/application.properties
copy to addons/common/flyway/src/test/resources/initializers/kie-flyway.customers.properties
index 2b28c3283b..ad55f01d8e 100644
--- a/springboot/integration-tests/integration-tests-springboot-processes-persistence-it/integration-tests-springboot-processes-jdbc/src/main/resources/application.properties
+++ b/addons/common/flyway/src/test/resources/initializers/kie-flyway.customers.properties
@@ -17,9 +17,8 @@
# under the License.
#
-server.address=0.0.0.0
+module.name=customers
-kogito.persistence.type=jdbc
-
-spring.flyway.locations=classpath:db/{vendor}
-spring.flyway.enabled=true
+module.locations.h2=classpath:kie-flyway/db/customers/h2
+module.locations.postgresql=classpath:kie-flyway/db/customers/postgresql
+module.locations.default=classpath:kie-flyway/db/customers/ansi
\ No newline at end of file
diff --git a/springboot/integration-tests/integration-tests-springboot-processes-persistence-it/integration-tests-springboot-processes-postgresql/src/main/resources/application.properties b/addons/common/flyway/src/test/resources/initializers/kie-flyway.customers2.properties
similarity index 69%
copy from springboot/integration-tests/integration-tests-springboot-processes-persistence-it/integration-tests-springboot-processes-postgresql/src/main/resources/application.properties
copy to addons/common/flyway/src/test/resources/initializers/kie-flyway.customers2.properties
index 8081c3c1aa..11cc64b3c8 100644
--- a/springboot/integration-tests/integration-tests-springboot-processes-persistence-it/integration-tests-springboot-processes-postgresql/src/main/resources/application.properties
+++ b/addons/common/flyway/src/test/resources/initializers/kie-flyway.customers2.properties
@@ -17,9 +17,8 @@
# under the License.
#
-server.address=0.0.0.0
+module.name=customers
-kogito.persistence.type=postgresql
-
-# Details https://www.postgresql.org/docs/9.6/static/libpq-connect.html#LIBPQ-CONNSTRING
-kogito.persistence.postgresql.connection.uri=postgresql://kogito-user:kogito-pass@localhost:5432/kogito
\ No newline at end of file
+module.locations.h2=classpath:kie-flyway/db/customers/h2,classpath:kie-flyway/db/customers-2/h2
+module.locations.postgresql=classpath:kie-flyway/db/customers/postgresql,classpath:kie-flyway/db/customers-2/postgresql
+module.locations.default=classpath:kie-flyway/db/customers/ansi,classpath:kie-flyway/db/customers-2/ansi
\ No newline at end of file
diff --git a/springboot/integration-tests/integration-tests-springboot-processes-persistence-it/integration-tests-springboot-processes-jdbc/src/main/resources/application.properties b/addons/common/flyway/src/test/resources/initializers/kie-flyway.duplicated1.properties
similarity index 79%
copy from springboot/integration-tests/integration-tests-springboot-processes-persistence-it/integration-tests-springboot-processes-jdbc/src/main/resources/application.properties
copy to addons/common/flyway/src/test/resources/initializers/kie-flyway.duplicated1.properties
index 2b28c3283b..c5b21d77a5 100644
--- a/springboot/integration-tests/integration-tests-springboot-processes-persistence-it/integration-tests-springboot-processes-jdbc/src/main/resources/application.properties
+++ b/addons/common/flyway/src/test/resources/initializers/kie-flyway.duplicated1.properties
@@ -17,9 +17,8 @@
# under the License.
#
-server.address=0.0.0.0
+module.name=test-duplicated-1
-kogito.persistence.type=jdbc
-
-spring.flyway.locations=classpath:db/{vendor}
-spring.flyway.enabled=true
+module.locations.h2=classpath:kie-flyway/db/test/h2
+module.locations.postgresql=classpath:kie-flyway/db/test/postgresql
+module.locations.default=classpath:kie-flyway/db/test/ansi
\ No newline at end of file
diff --git a/springboot/integration-tests/integration-tests-springboot-processes-persistence-it/integration-tests-springboot-processes-jdbc/src/main/resources/application.properties b/addons/common/flyway/src/test/resources/initializers/kie-flyway.duplicated2.properties
similarity index 79%
copy from springboot/integration-tests/integration-tests-springboot-processes-persistence-it/integration-tests-springboot-processes-jdbc/src/main/resources/application.properties
copy to addons/common/flyway/src/test/resources/initializers/kie-flyway.duplicated2.properties
index 2b28c3283b..7ca37ee74f 100644
--- a/springboot/integration-tests/integration-tests-springboot-processes-persistence-it/integration-tests-springboot-processes-jdbc/src/main/resources/application.properties
+++ b/addons/common/flyway/src/test/resources/initializers/kie-flyway.duplicated2.properties
@@ -17,9 +17,8 @@
# under the License.
#
-server.address=0.0.0.0
+module.name=test-duplicated-2
-kogito.persistence.type=jdbc
-
-spring.flyway.locations=classpath:db/{vendor}
-spring.flyway.enabled=true
+module.locations.h2=classpath:kie-flyway/db/test/h2
+module.locations.postgresql=classpath:kie-flyway/db/test/postgresql
+module.locations.default=classpath:kie-flyway/db/test/ansi
\ No newline at end of file
diff --git a/quarkus/addons/persistence/jdbc/runtime/src/main/resources/META-INF/services/io.smallrye.config.ConfigSourceFactory b/addons/common/flyway/src/test/resources/initializers/kie-flyway.empty.properties
similarity index 90%
rename from quarkus/addons/persistence/jdbc/runtime/src/main/resources/META-INF/services/io.smallrye.config.ConfigSourceFactory
rename to addons/common/flyway/src/test/resources/initializers/kie-flyway.empty.properties
index 0ce6025b8a..d8a500d9d8 100644
--- a/quarkus/addons/persistence/jdbc/runtime/src/main/resources/META-INF/services/io.smallrye.config.ConfigSourceFactory
+++ b/addons/common/flyway/src/test/resources/initializers/kie-flyway.empty.properties
@@ -17,4 +17,3 @@
# under the License.
#
-org.kie.kogito.persistence.quarkus.KogitoAddOnPersistenceJDBCConfigSourceFactory
diff --git a/springboot/integration-tests/integration-tests-springboot-processes-persistence-it/integration-tests-springboot-processes-jdbc/src/main/resources/application.properties b/addons/common/flyway/src/test/resources/initializers/kie-flyway.guitars.properties
similarity index 79%
copy from springboot/integration-tests/integration-tests-springboot-processes-persistence-it/integration-tests-springboot-processes-jdbc/src/main/resources/application.properties
copy to addons/common/flyway/src/test/resources/initializers/kie-flyway.guitars.properties
index 2b28c3283b..3663d80f6e 100644
--- a/springboot/integration-tests/integration-tests-springboot-processes-persistence-it/integration-tests-springboot-processes-jdbc/src/main/resources/application.properties
+++ b/addons/common/flyway/src/test/resources/initializers/kie-flyway.guitars.properties
@@ -17,9 +17,8 @@
# under the License.
#
-server.address=0.0.0.0
+module.name=guitars
-kogito.persistence.type=jdbc
-
-spring.flyway.locations=classpath:db/{vendor}
-spring.flyway.enabled=true
+module.locations.h2=classpath:kie-flyway/db/guitars/h2
+module.locations.postgresql=classpath:kie-flyway/db/guitars/postgresql
+module.locations.default=classpath:kie-flyway/db/guitars/ansi
\ No newline at end of file
diff --git a/quarkus/integration-tests/integration-tests-quarkus-processes-persistence/integration-tests-quarkus-processes-postgresql/src/main/resources/application.properties b/addons/common/flyway/src/test/resources/initializers/kie-flyway.guitars_default.properties
similarity index 84%
copy from quarkus/integration-tests/integration-tests-quarkus-processes-persistence/integration-tests-quarkus-processes-postgresql/src/main/resources/application.properties
copy to addons/common/flyway/src/test/resources/initializers/kie-flyway.guitars_default.properties
index 91a52baeab..2328c545a7 100644
--- a/quarkus/integration-tests/integration-tests-quarkus-processes-persistence/integration-tests-quarkus-processes-postgresql/src/main/resources/application.properties
+++ b/addons/common/flyway/src/test/resources/initializers/kie-flyway.guitars_default.properties
@@ -17,8 +17,7 @@
# under the License.
#
-kogito.persistence.type=postgresql
+module.name=guitars
-# Quarkus
-quarkus.flyway.migrate-at-start=true
-quarkus.flyway.clean-at-start=true
\ No newline at end of file
+module.locations.postgresql=classpath:kie-flyway/db/guitars/postgresql
+module.locations.default=classpath:kie-flyway/db/guitars/h2
\ No newline at end of file
diff --git a/addons/common/persistence/postgresql/.gitignore b/addons/common/flyway/src/test/resources/initializers/kie-flyway.no.locations.properties
similarity index 95%
copy from addons/common/persistence/postgresql/.gitignore
copy to addons/common/flyway/src/test/resources/initializers/kie-flyway.no.locations.properties
index acccaf1ecb..62dc592d7d 100644
--- a/addons/common/persistence/postgresql/.gitignore
+++ b/addons/common/flyway/src/test/resources/initializers/kie-flyway.no.locations.properties
@@ -1,4 +1,4 @@
-###
+#
# 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
@@ -15,6 +15,6 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
-###
+#
-src/main/resources/db/migration/*
\ No newline at end of file
+module.name=no-locations
\ No newline at end of file
diff --git a/addons/common/persistence/postgresql/.gitignore b/addons/common/flyway/src/test/resources/initializers/kie-flyway.wrong.format.properties
similarity index 90%
copy from addons/common/persistence/postgresql/.gitignore
copy to addons/common/flyway/src/test/resources/initializers/kie-flyway.wrong.format.properties
index acccaf1ecb..157c346edd 100644
--- a/addons/common/persistence/postgresql/.gitignore
+++ b/addons/common/flyway/src/test/resources/initializers/kie-flyway.wrong.format.properties
@@ -1,4 +1,4 @@
-###
+#
# 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
@@ -15,6 +15,8 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
-###
+#
+
+module.name=test-wrong-format
-src/main/resources/db/migration/*
\ No newline at end of file
+module.locations.h2.default=this won't work
\ No newline at end of file
diff --git a/addons/common/flyway/src/test/resources/kie-flyway/db/customers-2/ansi/V1.0.5__Insert_game_characters_ansi.sql b/addons/common/flyway/src/test/resources/kie-flyway/db/customers-2/ansi/V1.0.5__Insert_game_characters_ansi.sql
new file mode 100644
index 0000000000..fdc120933e
--- /dev/null
+++ b/addons/common/flyway/src/test/resources/kie-flyway/db/customers-2/ansi/V1.0.5__Insert_game_characters_ansi.sql
@@ -0,0 +1,21 @@
+/*
+ * 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.
+ */
+
+insert into customers (id, name, last_name, email) values (3, 'Guybrush', 'Threepwood', 'guybrush@monkeyisland.game');
+insert into customers (id, name, last_name, email) values (4, 'Herman', 'Toothrot', 'toothrot@monkeyisland.game');
\ No newline at end of file
diff --git a/addons/common/flyway/src/test/resources/kie-flyway/db/customers-2/h2/V1.0.5__Insert_game_characters_h2.sql b/addons/common/flyway/src/test/resources/kie-flyway/db/customers-2/h2/V1.0.5__Insert_game_characters_h2.sql
new file mode 100644
index 0000000000..fdc120933e
--- /dev/null
+++ b/addons/common/flyway/src/test/resources/kie-flyway/db/customers-2/h2/V1.0.5__Insert_game_characters_h2.sql
@@ -0,0 +1,21 @@
+/*
+ * 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.
+ */
+
+insert into customers (id, name, last_name, email) values (3, 'Guybrush', 'Threepwood', 'guybrush@monkeyisland.game');
+insert into customers (id, name, last_name, email) values (4, 'Herman', 'Toothrot', 'toothrot@monkeyisland.game');
\ No newline at end of file
diff --git a/addons/common/flyway/src/test/resources/kie-flyway/db/customers-2/postgresql/V1.0.5__Insert_game_characters_postgresql.sql b/addons/common/flyway/src/test/resources/kie-flyway/db/customers-2/postgresql/V1.0.5__Insert_game_characters_postgresql.sql
new file mode 100644
index 0000000000..fdc120933e
--- /dev/null
+++ b/addons/common/flyway/src/test/resources/kie-flyway/db/customers-2/postgresql/V1.0.5__Insert_game_characters_postgresql.sql
@@ -0,0 +1,21 @@
+/*
+ * 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.
+ */
+
+insert into customers (id, name, last_name, email) values (3, 'Guybrush', 'Threepwood', 'guybrush@monkeyisland.game');
+insert into customers (id, name, last_name, email) values (4, 'Herman', 'Toothrot', 'toothrot@monkeyisland.game');
\ No newline at end of file
diff --git a/addons/common/flyway/src/test/resources/kie-flyway/db/customers/ansi/V1.0.0__Create_table_ansi.sql b/addons/common/flyway/src/test/resources/kie-flyway/db/customers/ansi/V1.0.0__Create_table_ansi.sql
new file mode 100644
index 0000000000..9783fb1f16
--- /dev/null
+++ b/addons/common/flyway/src/test/resources/kie-flyway/db/customers/ansi/V1.0.0__Create_table_ansi.sql
@@ -0,0 +1,26 @@
+/*
+ * 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.
+ */
+
+create table customers
+(
+ id bigint not null,
+ name varchar(128) not null,
+ last_name varchar(128) not null,
+ constraint customers_pk primary key (id)
+);
\ No newline at end of file
diff --git a/addons/common/flyway/src/test/resources/kie-flyway/db/customers/ansi/V1.0.1__Alter_table_ansi.sql b/addons/common/flyway/src/test/resources/kie-flyway/db/customers/ansi/V1.0.1__Alter_table_ansi.sql
new file mode 100644
index 0000000000..bda9e5e58b
--- /dev/null
+++ b/addons/common/flyway/src/test/resources/kie-flyway/db/customers/ansi/V1.0.1__Alter_table_ansi.sql
@@ -0,0 +1,20 @@
+/*
+ * 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.
+ */
+
+alter table customers add column email varchar(128);
\ No newline at end of file
diff --git a/addons/common/flyway/src/test/resources/kie-flyway/db/customers/ansi/V1.0.2__Insert_book_characters_ansi.sql b/addons/common/flyway/src/test/resources/kie-flyway/db/customers/ansi/V1.0.2__Insert_book_characters_ansi.sql
new file mode 100644
index 0000000000..6702a0c4c0
--- /dev/null
+++ b/addons/common/flyway/src/test/resources/kie-flyway/db/customers/ansi/V1.0.2__Insert_book_characters_ansi.sql
@@ -0,0 +1,21 @@
+/*
+ * 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.
+ */
+
+insert into customers (id, name, last_name, email) values (1, 'Ned', 'Stark', 'n.stark@winterfell.book');
+insert into customers (id, name, last_name, email) values (2, 'Ender', 'Wiggin', 'ender@endersgame.book');
\ No newline at end of file
diff --git a/addons/common/flyway/src/test/resources/kie-flyway/db/customers/h2/V1.0.0__Create_table_h2.sql b/addons/common/flyway/src/test/resources/kie-flyway/db/customers/h2/V1.0.0__Create_table_h2.sql
new file mode 100644
index 0000000000..9783fb1f16
--- /dev/null
+++ b/addons/common/flyway/src/test/resources/kie-flyway/db/customers/h2/V1.0.0__Create_table_h2.sql
@@ -0,0 +1,26 @@
+/*
+ * 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.
+ */
+
+create table customers
+(
+ id bigint not null,
+ name varchar(128) not null,
+ last_name varchar(128) not null,
+ constraint customers_pk primary key (id)
+);
\ No newline at end of file
diff --git a/addons/common/flyway/src/test/resources/kie-flyway/db/customers/h2/V1.0.1__Alter_table_h2.sql b/addons/common/flyway/src/test/resources/kie-flyway/db/customers/h2/V1.0.1__Alter_table_h2.sql
new file mode 100644
index 0000000000..bda9e5e58b
--- /dev/null
+++ b/addons/common/flyway/src/test/resources/kie-flyway/db/customers/h2/V1.0.1__Alter_table_h2.sql
@@ -0,0 +1,20 @@
+/*
+ * 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.
+ */
+
+alter table customers add column email varchar(128);
\ No newline at end of file
diff --git a/addons/common/flyway/src/test/resources/kie-flyway/db/customers/h2/V1.0.2__Insert_book_characters_h2.sql b/addons/common/flyway/src/test/resources/kie-flyway/db/customers/h2/V1.0.2__Insert_book_characters_h2.sql
new file mode 100644
index 0000000000..6702a0c4c0
--- /dev/null
+++ b/addons/common/flyway/src/test/resources/kie-flyway/db/customers/h2/V1.0.2__Insert_book_characters_h2.sql
@@ -0,0 +1,21 @@
+/*
+ * 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.
+ */
+
+insert into customers (id, name, last_name, email) values (1, 'Ned', 'Stark', 'n.stark@winterfell.book');
+insert into customers (id, name, last_name, email) values (2, 'Ender', 'Wiggin', 'ender@endersgame.book');
\ No newline at end of file
diff --git a/addons/common/flyway/src/test/resources/kie-flyway/db/customers/postgresql/V1.0.0__Create_table_postgresql.sql b/addons/common/flyway/src/test/resources/kie-flyway/db/customers/postgresql/V1.0.0__Create_table_postgresql.sql
new file mode 100644
index 0000000000..9783fb1f16
--- /dev/null
+++ b/addons/common/flyway/src/test/resources/kie-flyway/db/customers/postgresql/V1.0.0__Create_table_postgresql.sql
@@ -0,0 +1,26 @@
+/*
+ * 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.
+ */
+
+create table customers
+(
+ id bigint not null,
+ name varchar(128) not null,
+ last_name varchar(128) not null,
+ constraint customers_pk primary key (id)
+);
\ No newline at end of file
diff --git a/addons/common/flyway/src/test/resources/kie-flyway/db/customers/postgresql/V1.0.1__Alter_table_postgresql.sql b/addons/common/flyway/src/test/resources/kie-flyway/db/customers/postgresql/V1.0.1__Alter_table_postgresql.sql
new file mode 100644
index 0000000000..bda9e5e58b
--- /dev/null
+++ b/addons/common/flyway/src/test/resources/kie-flyway/db/customers/postgresql/V1.0.1__Alter_table_postgresql.sql
@@ -0,0 +1,20 @@
+/*
+ * 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.
+ */
+
+alter table customers add column email varchar(128);
\ No newline at end of file
diff --git a/addons/common/flyway/src/test/resources/kie-flyway/db/customers/postgresql/V1.0.2__Insert_book_characters_postgresql.sql b/addons/common/flyway/src/test/resources/kie-flyway/db/customers/postgresql/V1.0.2__Insert_book_characters_postgresql.sql
new file mode 100644
index 0000000000..6702a0c4c0
--- /dev/null
+++ b/addons/common/flyway/src/test/resources/kie-flyway/db/customers/postgresql/V1.0.2__Insert_book_characters_postgresql.sql
@@ -0,0 +1,21 @@
+/*
+ * 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.
+ */
+
+insert into customers (id, name, last_name, email) values (1, 'Ned', 'Stark', 'n.stark@winterfell.book');
+insert into customers (id, name, last_name, email) values (2, 'Ender', 'Wiggin', 'ender@endersgame.book');
\ No newline at end of file
diff --git a/addons/common/flyway/src/test/resources/kie-flyway/db/guitars/ansi/V1.0.0__Create_guitars_table_ansi.sql b/addons/common/flyway/src/test/resources/kie-flyway/db/guitars/ansi/V1.0.0__Create_guitars_table_ansi.sql
new file mode 100644
index 0000000000..dbbc6788e0
--- /dev/null
+++ b/addons/common/flyway/src/test/resources/kie-flyway/db/guitars/ansi/V1.0.0__Create_guitars_table_ansi.sql
@@ -0,0 +1,26 @@
+/*
+ * 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.
+ */
+
+create table guitars
+(
+ id bigint not null,
+ brand varchar(128) not null,
+ model varchar(128) not null,
+ constraint guitars_pk primary key (id)
+);
\ No newline at end of file
diff --git a/addons/common/flyway/src/test/resources/kie-flyway/db/guitars/ansi/V1.0.1__Alter_guitars_table_ansi.sql b/addons/common/flyway/src/test/resources/kie-flyway/db/guitars/ansi/V1.0.1__Alter_guitars_table_ansi.sql
new file mode 100644
index 0000000000..e7b1e28c61
--- /dev/null
+++ b/addons/common/flyway/src/test/resources/kie-flyway/db/guitars/ansi/V1.0.1__Alter_guitars_table_ansi.sql
@@ -0,0 +1,20 @@
+/*
+ * 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.
+ */
+
+alter table guitars add column rating bigint not null;
\ No newline at end of file
diff --git a/addons/common/flyway/src/test/resources/kie-flyway/db/guitars/ansi/V1.0.2__Insert_fender_guitars_ansi.sql b/addons/common/flyway/src/test/resources/kie-flyway/db/guitars/ansi/V1.0.2__Insert_fender_guitars_ansi.sql
new file mode 100644
index 0000000000..38ca843c4f
--- /dev/null
+++ b/addons/common/flyway/src/test/resources/kie-flyway/db/guitars/ansi/V1.0.2__Insert_fender_guitars_ansi.sql
@@ -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.
+ */
+
+insert into guitars (id, brand, model, rating) values (1, 'Fender', 'Telecaster', 10);
+insert into guitars (id, brand, model, rating) values (2, 'Fender', 'Stratocaster', 9);
+insert into guitars (id, brand, model, rating) values (3, 'Fender', 'Jazzmaster', 7);
\ No newline at end of file
diff --git a/addons/common/flyway/src/test/resources/kie-flyway/db/guitars/ansi/V1.0.5__Insert_gibson_guitars_ansi.sql b/addons/common/flyway/src/test/resources/kie-flyway/db/guitars/ansi/V1.0.5__Insert_gibson_guitars_ansi.sql
new file mode 100644
index 0000000000..b96b93d98b
--- /dev/null
+++ b/addons/common/flyway/src/test/resources/kie-flyway/db/guitars/ansi/V1.0.5__Insert_gibson_guitars_ansi.sql
@@ -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.
+ */
+
+insert into guitars (id, brand, model, rating) values (4, 'Gibson', 'SG', 9);
+insert into guitars (id, brand, model, rating) values (5, 'Gibson', 'Les Paul', 9);
+insert into guitars (id, brand, model, rating) values (6, 'Gibson', 'ES-330', 10);
\ No newline at end of file
diff --git a/addons/common/flyway/src/test/resources/kie-flyway/db/guitars/h2/V1.0.0__Create_guitars_table_h2.sql b/addons/common/flyway/src/test/resources/kie-flyway/db/guitars/h2/V1.0.0__Create_guitars_table_h2.sql
new file mode 100644
index 0000000000..3a4ce51257
--- /dev/null
+++ b/addons/common/flyway/src/test/resources/kie-flyway/db/guitars/h2/V1.0.0__Create_guitars_table_h2.sql
@@ -0,0 +1,26 @@
+/*
+ * 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.
+ */
+
+create table guitars
+(
+ id bigint not null,
+ brand varchar(128) not null,
+ model varchar(128) not null,
+ constraint guitars_pk primary key (id)
+);
\ No newline at end of file
diff --git a/addons/common/flyway/src/test/resources/kie-flyway/db/guitars/h2/V1.0.1__Alter_guitars_table_h2.sql b/addons/common/flyway/src/test/resources/kie-flyway/db/guitars/h2/V1.0.1__Alter_guitars_table_h2.sql
new file mode 100644
index 0000000000..e7b1e28c61
--- /dev/null
+++ b/addons/common/flyway/src/test/resources/kie-flyway/db/guitars/h2/V1.0.1__Alter_guitars_table_h2.sql
@@ -0,0 +1,20 @@
+/*
+ * 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.
+ */
+
+alter table guitars add column rating bigint not null;
\ No newline at end of file
diff --git a/addons/common/flyway/src/test/resources/kie-flyway/db/guitars/h2/V1.0.2__Insert_fender_guitars_h2.sql b/addons/common/flyway/src/test/resources/kie-flyway/db/guitars/h2/V1.0.2__Insert_fender_guitars_h2.sql
new file mode 100644
index 0000000000..38ca843c4f
--- /dev/null
+++ b/addons/common/flyway/src/test/resources/kie-flyway/db/guitars/h2/V1.0.2__Insert_fender_guitars_h2.sql
@@ -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.
+ */
+
+insert into guitars (id, brand, model, rating) values (1, 'Fender', 'Telecaster', 10);
+insert into guitars (id, brand, model, rating) values (2, 'Fender', 'Stratocaster', 9);
+insert into guitars (id, brand, model, rating) values (3, 'Fender', 'Jazzmaster', 7);
\ No newline at end of file
diff --git a/addons/common/flyway/src/test/resources/kie-flyway/db/guitars/h2/V1.0.5__Insert_gibson_guitars_h2.sql b/addons/common/flyway/src/test/resources/kie-flyway/db/guitars/h2/V1.0.5__Insert_gibson_guitars_h2.sql
new file mode 100644
index 0000000000..b96b93d98b
--- /dev/null
+++ b/addons/common/flyway/src/test/resources/kie-flyway/db/guitars/h2/V1.0.5__Insert_gibson_guitars_h2.sql
@@ -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.
+ */
+
+insert into guitars (id, brand, model, rating) values (4, 'Gibson', 'SG', 9);
+insert into guitars (id, brand, model, rating) values (5, 'Gibson', 'Les Paul', 9);
+insert into guitars (id, brand, model, rating) values (6, 'Gibson', 'ES-330', 10);
\ No newline at end of file
diff --git a/addons/common/flyway/src/test/resources/kie-flyway/db/guitars/postgresql/V1.0.0__Create_guitars_table_postgresql.sql b/addons/common/flyway/src/test/resources/kie-flyway/db/guitars/postgresql/V1.0.0__Create_guitars_table_postgresql.sql
new file mode 100644
index 0000000000..3a4ce51257
--- /dev/null
+++ b/addons/common/flyway/src/test/resources/kie-flyway/db/guitars/postgresql/V1.0.0__Create_guitars_table_postgresql.sql
@@ -0,0 +1,26 @@
+/*
+ * 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.
+ */
+
+create table guitars
+(
+ id bigint not null,
+ brand varchar(128) not null,
+ model varchar(128) not null,
+ constraint guitars_pk primary key (id)
+);
\ No newline at end of file
diff --git a/addons/common/flyway/src/test/resources/kie-flyway/db/guitars/postgresql/V1.0.1__Alter_guitars_table_postgresql.sql b/addons/common/flyway/src/test/resources/kie-flyway/db/guitars/postgresql/V1.0.1__Alter_guitars_table_postgresql.sql
new file mode 100644
index 0000000000..e7b1e28c61
--- /dev/null
+++ b/addons/common/flyway/src/test/resources/kie-flyway/db/guitars/postgresql/V1.0.1__Alter_guitars_table_postgresql.sql
@@ -0,0 +1,20 @@
+/*
+ * 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.
+ */
+
+alter table guitars add column rating bigint not null;
\ No newline at end of file
diff --git a/addons/common/flyway/src/test/resources/kie-flyway/db/guitars/postgresql/V1.0.2__Insert_fender_guitars_postgresql.sql b/addons/common/flyway/src/test/resources/kie-flyway/db/guitars/postgresql/V1.0.2__Insert_fender_guitars_postgresql.sql
new file mode 100644
index 0000000000..38ca843c4f
--- /dev/null
+++ b/addons/common/flyway/src/test/resources/kie-flyway/db/guitars/postgresql/V1.0.2__Insert_fender_guitars_postgresql.sql
@@ -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.
+ */
+
+insert into guitars (id, brand, model, rating) values (1, 'Fender', 'Telecaster', 10);
+insert into guitars (id, brand, model, rating) values (2, 'Fender', 'Stratocaster', 9);
+insert into guitars (id, brand, model, rating) values (3, 'Fender', 'Jazzmaster', 7);
\ No newline at end of file
diff --git a/addons/common/flyway/src/test/resources/kie-flyway/db/guitars/postgresql/V1.0.5__Insert_gibson_guitars_postgresql.sql b/addons/common/flyway/src/test/resources/kie-flyway/db/guitars/postgresql/V1.0.5__Insert_gibson_guitars_postgresql.sql
new file mode 100644
index 0000000000..b96b93d98b
--- /dev/null
+++ b/addons/common/flyway/src/test/resources/kie-flyway/db/guitars/postgresql/V1.0.5__Insert_gibson_guitars_postgresql.sql
@@ -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.
+ */
+
+insert into guitars (id, brand, model, rating) values (4, 'Gibson', 'SG', 9);
+insert into guitars (id, brand, model, rating) values (5, 'Gibson', 'Les Paul', 9);
+insert into guitars (id, brand, model, rating) values (6, 'Gibson', 'ES-330', 10);
\ No newline at end of file
diff --git a/addons/common/flyway/src/test/resources/kie-flyway/db/test/ansi/V1.0.0__Create_table.sql b/addons/common/flyway/src/test/resources/kie-flyway/db/test/ansi/V1.0.0__Create_table.sql
new file mode 100644
index 0000000000..ed8eb3013b
--- /dev/null
+++ b/addons/common/flyway/src/test/resources/kie-flyway/db/test/ansi/V1.0.0__Create_table.sql
@@ -0,0 +1,25 @@
+/*
+ * 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.
+ */
+
+create table test_table
+(
+ id bigint not null,
+ message varchar(128) not null,
+ constraint test_table_pkey primary key (id)
+);
\ No newline at end of file
diff --git a/addons/common/flyway/src/test/resources/kie-flyway/db/test/ansi/V1.0.1__Alter_table.sql b/addons/common/flyway/src/test/resources/kie-flyway/db/test/ansi/V1.0.1__Alter_table.sql
new file mode 100644
index 0000000000..a7fd7a59b2
--- /dev/null
+++ b/addons/common/flyway/src/test/resources/kie-flyway/db/test/ansi/V1.0.1__Alter_table.sql
@@ -0,0 +1,20 @@
+/*
+ * 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.
+ */
+
+alter table test_table add column dbtype varchar(128);
\ No newline at end of file
diff --git a/addons/common/flyway/src/test/resources/kie-flyway/db/test/ansi/V1.0.2__Insert_data.sql b/addons/common/flyway/src/test/resources/kie-flyway/db/test/ansi/V1.0.2__Insert_data.sql
new file mode 100644
index 0000000000..de9448fc68
--- /dev/null
+++ b/addons/common/flyway/src/test/resources/kie-flyway/db/test/ansi/V1.0.2__Insert_data.sql
@@ -0,0 +1,21 @@
+/*
+ * 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.
+ */
+
+insert into test_table (id, message, dbtype)
+values (1, 'Hello from Kie Flyway - test', 'ansi');
\ No newline at end of file
diff --git a/addons/common/flyway/src/test/resources/kie-flyway/db/test/h2/V1.0.0__Create_table.sql b/addons/common/flyway/src/test/resources/kie-flyway/db/test/h2/V1.0.0__Create_table.sql
new file mode 100644
index 0000000000..ed8eb3013b
--- /dev/null
+++ b/addons/common/flyway/src/test/resources/kie-flyway/db/test/h2/V1.0.0__Create_table.sql
@@ -0,0 +1,25 @@
+/*
+ * 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.
+ */
+
+create table test_table
+(
+ id bigint not null,
+ message varchar(128) not null,
+ constraint test_table_pkey primary key (id)
+);
\ No newline at end of file
diff --git a/addons/common/flyway/src/test/resources/kie-flyway/db/test/h2/V1.0.1__Alter_table.sql b/addons/common/flyway/src/test/resources/kie-flyway/db/test/h2/V1.0.1__Alter_table.sql
new file mode 100644
index 0000000000..a7fd7a59b2
--- /dev/null
+++ b/addons/common/flyway/src/test/resources/kie-flyway/db/test/h2/V1.0.1__Alter_table.sql
@@ -0,0 +1,20 @@
+/*
+ * 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.
+ */
+
+alter table test_table add column dbtype varchar(128);
\ No newline at end of file
diff --git a/addons/common/flyway/src/test/resources/kie-flyway/db/test/h2/V1.0.2__Insert_data.sql b/addons/common/flyway/src/test/resources/kie-flyway/db/test/h2/V1.0.2__Insert_data.sql
new file mode 100644
index 0000000000..8c16905304
--- /dev/null
+++ b/addons/common/flyway/src/test/resources/kie-flyway/db/test/h2/V1.0.2__Insert_data.sql
@@ -0,0 +1,21 @@
+/*
+ * 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.
+ */
+
+insert into test_table (id, message, dbtype)
+values (1, 'Hello from Kie Flyway - test', 'H2');
\ No newline at end of file
diff --git a/addons/common/flyway/src/test/resources/kie-flyway/db/test/postgresql/V1.0.0__Create_table.sql b/addons/common/flyway/src/test/resources/kie-flyway/db/test/postgresql/V1.0.0__Create_table.sql
new file mode 100644
index 0000000000..ed8eb3013b
--- /dev/null
+++ b/addons/common/flyway/src/test/resources/kie-flyway/db/test/postgresql/V1.0.0__Create_table.sql
@@ -0,0 +1,25 @@
+/*
+ * 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.
+ */
+
+create table test_table
+(
+ id bigint not null,
+ message varchar(128) not null,
+ constraint test_table_pkey primary key (id)
+);
\ No newline at end of file
diff --git a/addons/common/flyway/src/test/resources/kie-flyway/db/test/postgresql/V1.0.1__Alter_table.sql b/addons/common/flyway/src/test/resources/kie-flyway/db/test/postgresql/V1.0.1__Alter_table.sql
new file mode 100644
index 0000000000..a7fd7a59b2
--- /dev/null
+++ b/addons/common/flyway/src/test/resources/kie-flyway/db/test/postgresql/V1.0.1__Alter_table.sql
@@ -0,0 +1,20 @@
+/*
+ * 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.
+ */
+
+alter table test_table add column dbtype varchar(128);
\ No newline at end of file
diff --git a/addons/common/flyway/src/test/resources/kie-flyway/db/test/postgresql/V1.0.2__Insert_data.sql b/addons/common/flyway/src/test/resources/kie-flyway/db/test/postgresql/V1.0.2__Insert_data.sql
new file mode 100644
index 0000000000..258edf6a7f
--- /dev/null
+++ b/addons/common/flyway/src/test/resources/kie-flyway/db/test/postgresql/V1.0.2__Insert_data.sql
@@ -0,0 +1,21 @@
+/*
+ * 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.
+ */
+
+insert into test_table (id, message, dbtype)
+values (1, 'Hello from Kie Flyway - test', 'postgresql');
\ No newline at end of file
diff --git a/addons/common/persistence/ddl/src/assembly/db-scripts.xml b/addons/common/persistence/ddl/src/assembly/db-scripts.xml
index 6055cb3e26..4033e889b7 100644
--- a/addons/common/persistence/ddl/src/assembly/db-scripts.xml
+++ b/addons/common/persistence/ddl/src/assembly/db-scripts.xml
@@ -28,21 +28,14 @@
<includeBaseDirectory>false</includeBaseDirectory>
<fileSets>
<fileSet>
- <directory>${path.to.persistence.modules}/jdbc/src/main/resources/db/postgresql</directory>
+ <directory>${path.to.persistence.modules}/jdbc/src/main/resources/kie-flyway/db/persistence-jdbc/postgresql</directory>
<outputDirectory>postgresql</outputDirectory>
<includes>
<include>*.sql</include>
</includes>
</fileSet>
<fileSet>
- <directory>${path.to.persistence.modules}/jdbc/src/main/resources/db/oracle</directory>
- <outputDirectory>oracle</outputDirectory>
- <includes>
- <include>*.sql</include>
- </includes>
- </fileSet>
- <fileSet>
- <directory>${path.to.persistence.modules}/jdbc/src/main/resources/db/ansi</directory>
+ <directory>${path.to.persistence.modules}/jdbc/src/main/resources/kie-flyway/db/persistence-jdbc/ansi</directory>
<outputDirectory>ansi</outputDirectory>
<includes>
<include>*.sql</include>
diff --git a/addons/common/persistence/ddl/src/assembly/productized-db-scripts.xml b/addons/common/persistence/ddl/src/assembly/productized-db-scripts.xml
index e036f13899..39ec204674 100644
--- a/addons/common/persistence/ddl/src/assembly/productized-db-scripts.xml
+++ b/addons/common/persistence/ddl/src/assembly/productized-db-scripts.xml
@@ -28,7 +28,7 @@
<includeBaseDirectory>false</includeBaseDirectory>
<fileSets>
<fileSet>
- <directory>${path.to.persistence.modules}/jdbc/src/main/resources/db/postgresql</directory>
+ <directory>${path.to.persistence.modules}/jdbc/src/main/resources/kie-flyway/db/postgresql</directory>
<outputDirectory>postgresql</outputDirectory>
<includes>
<include>*.sql</include>
diff --git a/addons/common/persistence/jdbc/pom.xml b/addons/common/persistence/jdbc/pom.xml
index aac9886605..b0fe68f133 100644
--- a/addons/common/persistence/jdbc/pom.xml
+++ b/addons/common/persistence/jdbc/pom.xml
@@ -83,9 +83,8 @@
<scope>test</scope>
</dependency>
<dependency>
- <groupId>org.flywaydb</groupId>
- <artifactId>flyway-core</artifactId>
- <version>${version.org.flywaydb}</version>
+ <groupId>org.kie</groupId>
+ <artifactId>kie-addons-flyway</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
diff --git a/springboot/integration-tests/integration-tests-springboot-processes-persistence-it/integration-tests-springboot-processes-jdbc/src/main/resources/application.properties b/addons/common/persistence/jdbc/src/main/resources/META-INF/kie-flyway.properties
similarity index 76%
copy from springboot/integration-tests/integration-tests-springboot-processes-persistence-it/integration-tests-springboot-processes-jdbc/src/main/resources/application.properties
copy to addons/common/persistence/jdbc/src/main/resources/META-INF/kie-flyway.properties
index 2b28c3283b..a2a0dccd06 100644
--- a/springboot/integration-tests/integration-tests-springboot-processes-persistence-it/integration-tests-springboot-processes-jdbc/src/main/resources/application.properties
+++ b/addons/common/persistence/jdbc/src/main/resources/META-INF/kie-flyway.properties
@@ -17,9 +17,8 @@
# under the License.
#
-server.address=0.0.0.0
+module.name=runtime-persistence
-kogito.persistence.type=jdbc
-
-spring.flyway.locations=classpath:db/{vendor}
-spring.flyway.enabled=true
+module.locations.default=classpath:kie-flyway/db/persistence-jdbc/ansi
+module.locations.postgresql=classpath:kie-flyway/db/persistence-jdbc/postgresql
+module.locations.h2=classpath:kie-flyway/db/persistence-jdbc/ansi
\ No newline at end of file
diff --git a/addons/common/persistence/jdbc/src/main/resources/db/ansi/V1.35.0__create_runtime_ansi.sql b/addons/common/persistence/jdbc/src/main/resources/kie-flyway/db/persistence-jdbc/ansi/V1.35.0__create_runtime_ansi.sql
similarity index 100%
rename from addons/common/persistence/jdbc/src/main/resources/db/ansi/V1.35.0__create_runtime_ansi.sql
rename to addons/common/persistence/jdbc/src/main/resources/kie-flyway/db/persistence-jdbc/ansi/V1.35.0__create_runtime_ansi.sql
diff --git a/addons/common/persistence/jdbc/src/main/resources/db/ansi/V10.0.0__add_business_key_ansi.sql b/addons/common/persistence/jdbc/src/main/resources/kie-flyway/db/persistence-jdbc/ansi/V10.0.0__add_business_key_ansi.sql
similarity index 100%
rename from addons/common/persistence/jdbc/src/main/resources/db/ansi/V10.0.0__add_business_key_ansi.sql
rename to addons/common/persistence/jdbc/src/main/resources/kie-flyway/db/persistence-jdbc/ansi/V10.0.0__add_business_key_ansi.sql
diff --git a/addons/common/persistence/jdbc/src/main/resources/db/ansi/V10.0.1__create_correlation_ansi.sql b/addons/common/persistence/jdbc/src/main/resources/kie-flyway/db/persistence-jdbc/ansi/V10.0.1__create_correlation_ansi.sql
similarity index 100%
rename from addons/common/persistence/jdbc/src/main/resources/db/ansi/V10.0.1__create_correlation_ansi.sql
rename to addons/common/persistence/jdbc/src/main/resources/kie-flyway/db/persistence-jdbc/ansi/V10.0.1__create_correlation_ansi.sql
diff --git a/addons/common/persistence/jdbc/src/main/resources/db/postgresql/V1.35.0__create_runtime_PostgreSQL.sql b/addons/common/persistence/jdbc/src/main/resources/kie-flyway/db/persistence-jdbc/postgresql/V1.35.0__create_runtime_PostgreSQL.sql
similarity index 100%
rename from addons/common/persistence/jdbc/src/main/resources/db/postgresql/V1.35.0__create_runtime_PostgreSQL.sql
rename to addons/common/persistence/jdbc/src/main/resources/kie-flyway/db/persistence-jdbc/postgresql/V1.35.0__create_runtime_PostgreSQL.sql
diff --git a/addons/common/persistence/jdbc/src/main/resources/db/postgresql/V10.0.0__add_business_key_PostgreSQL.sql b/addons/common/persistence/jdbc/src/main/resources/kie-flyway/db/persistence-jdbc/postgresql/V10.0.0__add_business_key_PostgreSQL.sql
similarity index 100%
rename from addons/common/persistence/jdbc/src/main/resources/db/postgresql/V10.0.0__add_business_key_PostgreSQL.sql
rename to addons/common/persistence/jdbc/src/main/resources/kie-flyway/db/persistence-jdbc/postgresql/V10.0.0__add_business_key_PostgreSQL.sql
diff --git a/addons/common/persistence/jdbc/src/main/resources/db/postgresql/V10.0.1__alter_correlation_PostgreSQL.sql b/addons/common/persistence/jdbc/src/main/resources/kie-flyway/db/persistence-jdbc/postgresql/V10.0.1__alter_correlation_PostgreSQL.sql
similarity index 100%
rename from addons/common/persistence/jdbc/src/main/resources/db/postgresql/V10.0.1__alter_correlation_PostgreSQL.sql
rename to addons/common/persistence/jdbc/src/main/resources/kie-flyway/db/persistence-jdbc/postgresql/V10.0.1__alter_correlation_PostgreSQL.sql
diff --git a/addons/common/persistence/jdbc/src/test/java/org/kie/persistence/jdbc/AbstractProcessInstancesIT.java b/addons/common/persistence/jdbc/src/test/java/org/kie/persistence/jdbc/AbstractProcessInstancesIT.java
index 981114c5df..2f4355beff 100644
--- a/addons/common/persistence/jdbc/src/test/java/org/kie/persistence/jdbc/AbstractProcessInstancesIT.java
+++ b/addons/common/persistence/jdbc/src/test/java/org/kie/persistence/jdbc/AbstractProcessInstancesIT.java
@@ -26,8 +26,8 @@ import java.util.Optional;
import javax.sql.DataSource;
import org.drools.io.ClassPathResource;
-import org.flywaydb.core.Flyway;
import org.junit.jupiter.api.Test;
+import org.kie.flyway.initializer.KieFlywayInitializer;
import org.kie.kogito.auth.IdentityProviders;
import org.kie.kogito.auth.SecurityPolicy;
import org.kie.kogito.internal.process.workitem.Policy;
@@ -40,7 +40,6 @@ import org.kie.kogito.process.bpmn2.BpmnVariables;
import org.kie.kogito.process.impl.DefaultWorkItemHandlerConfig;
import org.kie.kogito.process.impl.StaticProcessConfig;
import org.kie.kogito.process.workitems.impl.DefaultKogitoWorkItemHandler;
-import org.testcontainers.containers.JdbcDatabaseContainer;
import static java.util.Collections.singletonMap;
import static org.assertj.core.api.Assertions.assertThat;
@@ -62,14 +61,11 @@ abstract class AbstractProcessInstancesIT {
public static final String TEST_ID = "02ac3854-46ee-42b7-8b63-5186c9889d96";
public static Policy securityPolicy = SecurityPolicy.of(IdentityProviders.of("john"));
- DataSource dataSource;
-
- public static void initMigration(JdbcDatabaseContainer container, String dbKind) {
- Flyway flyway = Flyway.configure().dataSource(container.getJdbcUrl(),
- container.getUsername(),
- container.getPassword())
- .locations("classpath:db/" + dbKind).load();
- flyway.migrate();
+ public static void initMigration(DataSource dataSource) {
+ KieFlywayInitializer.builder()
+ .withDatasource(dataSource)
+ .build()
+ .migrate();
}
public static BpmnProcess createProcess(TestProcessInstancesFactory factory, String fileName) {
diff --git a/addons/common/persistence/jdbc/src/test/java/org/kie/persistence/jdbc/PostgreSqlProcessInstancesIT.java b/addons/common/persistence/jdbc/src/test/java/org/kie/persistence/jdbc/PostgreSqlProcessInstancesIT.java
index 3840a9c430..3092f42789 100644
--- a/addons/common/persistence/jdbc/src/test/java/org/kie/persistence/jdbc/PostgreSqlProcessInstancesIT.java
+++ b/addons/common/persistence/jdbc/src/test/java/org/kie/persistence/jdbc/PostgreSqlProcessInstancesIT.java
@@ -39,7 +39,7 @@ public class PostgreSqlProcessInstancesIT extends AbstractProcessInstancesIT {
PG_DATA_SOURCE.setUrl(PG_CONTAINER.getJdbcUrl());
PG_DATA_SOURCE.setUser(PG_CONTAINER.getUsername());
PG_DATA_SOURCE.setPassword(PG_CONTAINER.getPassword());
- initMigration(PG_CONTAINER, "postgresql");
+ initMigration(PG_DATA_SOURCE);
}
protected DataSource getDataSource() {
diff --git a/addons/common/persistence/jdbc/src/test/java/org/kie/persistence/jdbc/correlation/JDBCCorrelationServiceIT.java b/addons/common/persistence/jdbc/src/test/java/org/kie/persistence/jdbc/correlation/JDBCCorrelationServiceIT.java
index 62212ac0eb..212e41e226 100644
--- a/addons/common/persistence/jdbc/src/test/java/org/kie/persistence/jdbc/correlation/JDBCCorrelationServiceIT.java
+++ b/addons/common/persistence/jdbc/src/test/java/org/kie/persistence/jdbc/correlation/JDBCCorrelationServiceIT.java
@@ -21,16 +21,17 @@ package org.kie.persistence.jdbc.correlation;
import java.util.Collections;
import java.util.Optional;
-import org.flywaydb.core.Flyway;
+import javax.sql.DataSource;
+
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
+import org.kie.flyway.initializer.KieFlywayInitializer;
import org.kie.kogito.correlation.CompositeCorrelation;
import org.kie.kogito.correlation.CorrelationInstance;
import org.kie.kogito.correlation.SimpleCorrelation;
import org.kie.kogito.persistence.jdbc.correlation.JDBCCorrelationService;
import org.kie.kogito.testcontainers.KogitoPostgreSqlContainer;
import org.postgresql.ds.PGSimpleDataSource;
-import org.testcontainers.containers.JdbcDatabaseContainer;
import org.testcontainers.junit.jupiter.Container;
import org.testcontainers.junit.jupiter.Testcontainers;
@@ -51,17 +52,14 @@ public class JDBCCorrelationServiceIT {
dataSource.setUser(PG_CONTAINER.getUsername());
dataSource.setPassword(PG_CONTAINER.getPassword());
correlationService = new JDBCCorrelationService(dataSource);
- //create table
- // DDLRunner.init(new GenericRepository(dataSource), true);
- initMigration(PG_CONTAINER, "postgresql");
+ initMigration(dataSource);
}
- public static void initMigration(JdbcDatabaseContainer container, String dbKind) {
- Flyway flyway = Flyway.configure().dataSource(container.getJdbcUrl(),
- container.getUsername(),
- container.getPassword())
- .locations("classpath:db/" + dbKind).load();
- flyway.migrate();
+ public static void initMigration(DataSource dataSource) {
+ KieFlywayInitializer.builder()
+ .withDatasource(dataSource)
+ .build()
+ .migrate();
}
@Test
diff --git a/addons/common/persistence/postgresql/.gitignore b/addons/common/persistence/postgresql/.gitignore
index acccaf1ecb..423a2b902f 100644
--- a/addons/common/persistence/postgresql/.gitignore
+++ b/addons/common/persistence/postgresql/.gitignore
@@ -17,4 +17,4 @@
# under the License.
###
-src/main/resources/db/migration/*
\ No newline at end of file
+/src/main/resources/kie-flyway/db/persistence-postgresql/postgresql/*
\ No newline at end of file
diff --git a/addons/common/persistence/postgresql/pom.xml b/addons/common/persistence/postgresql/pom.xml
index ee2df9c829..581d6edf9f 100644
--- a/addons/common/persistence/postgresql/pom.xml
+++ b/addons/common/persistence/postgresql/pom.xml
@@ -1,4 +1,4 @@
-<!--
+ <!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
@@ -31,9 +31,9 @@
<description>PostgreSQL based persistence for KIE</description>
<properties>
<path.to.jdbc.addon>../jdbc</path.to.jdbc.addon>
- <path.to.script.folder>src/main/resources/db</path.to.script.folder>
- <path.to.migration.scripts.from>${path.to.jdbc.addon}/${path.to.script.folder}/postgresql</path.to.migration.scripts.from>
- <path.to.migration.scripts.to>${path.to.script.folder}/migration</path.to.migration.scripts.to>
+ <path.to.script.folder>src/main/resources/kie-flyway/db/</path.to.script.folder>
+ <path.to.migration.scripts.from>${path.to.jdbc.addon}/${path.to.script.folder}/persistence-jdbc/postgresql</path.to.migration.scripts.from>
+ <path.to.migration.scripts.to>${path.to.script.folder}/persistence-postgresql/postgresql</path.to.migration.scripts.to>
<java.module.name>org.kie.kogito.persistence.postgresql</java.module.name>
</properties>
@@ -61,9 +61,8 @@
<scope>test</scope>
</dependency>
<dependency>
- <groupId>org.flywaydb</groupId>
- <artifactId>flyway-core</artifactId>
- <version>${version.org.flywaydb}</version>
+ <groupId>org.kie</groupId>
+ <artifactId>kie-addons-flyway</artifactId>
<scope>test</scope>
</dependency>
<dependency>
diff --git a/springboot/integration-tests/integration-tests-springboot-processes-persistence-it/integration-tests-springboot-processes-jdbc/src/main/resources/application.properties b/addons/common/persistence/postgresql/src/main/resources/META-INF/kie-flyway.properties
similarity index 79%
copy from springboot/integration-tests/integration-tests-springboot-processes-persistence-it/integration-tests-springboot-processes-jdbc/src/main/resources/application.properties
copy to addons/common/persistence/postgresql/src/main/resources/META-INF/kie-flyway.properties
index 2b28c3283b..786041563b 100644
--- a/springboot/integration-tests/integration-tests-springboot-processes-persistence-it/integration-tests-springboot-processes-jdbc/src/main/resources/application.properties
+++ b/addons/common/persistence/postgresql/src/main/resources/META-INF/kie-flyway.properties
@@ -17,9 +17,7 @@
# under the License.
#
-server.address=0.0.0.0
+module.name=runtime-persistence
-kogito.persistence.type=jdbc
-
-spring.flyway.locations=classpath:db/{vendor}
-spring.flyway.enabled=true
+module.locations.postgresql=classpath:kie-flyway/db/persistence-postgresql/postgresql
+module.locations.default=classpath:kie-flyway/db/persistence-postgresql/postgresql
\ No newline at end of file
diff --git a/addons/common/persistence/postgresql/src/test/java/org/kie/persistence/postgresql/PostgresqlProcessInstancesIT.java b/addons/common/persistence/postgresql/src/test/java/org/kie/persistence/postgresql/PostgresqlProcessInstancesIT.java
index 7948364084..ea22618429 100644
--- a/addons/common/persistence/postgresql/src/test/java/org/kie/persistence/postgresql/PostgresqlProcessInstancesIT.java
+++ b/addons/common/persistence/postgresql/src/test/java/org/kie/persistence/postgresql/PostgresqlProcessInstancesIT.java
@@ -22,10 +22,10 @@ import java.util.Collections;
import java.util.Optional;
import org.drools.io.ClassPathResource;
-import org.flywaydb.core.Flyway;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
+import org.kie.flyway.initializer.KieFlywayInitializer;
import org.kie.kogito.auth.IdentityProviders;
import org.kie.kogito.auth.SecurityPolicy;
import org.kie.kogito.persistence.postgresql.AbstractProcessInstancesFactory;
@@ -41,6 +41,7 @@ import org.kie.kogito.process.impl.DefaultWorkItemHandlerConfig;
import org.kie.kogito.process.impl.StaticProcessConfig;
import org.kie.kogito.process.workitems.impl.DefaultKogitoWorkItemHandler;
import org.kie.kogito.testcontainers.KogitoPostgreSqlContainer;
+import org.postgresql.ds.PGSimpleDataSource;
import org.testcontainers.junit.jupiter.Container;
import org.testcontainers.junit.jupiter.Testcontainers;
@@ -76,9 +77,18 @@ class PostgresqlProcessInstancesIT {
@BeforeAll
public static void startContainerAndPublicPortIsAvailable() {
container.start();
- Flyway flyway = Flyway.configure().dataSource(container.getJdbcUrl(), container.getUsername(), container.getPassword()).load();
- flyway.migrate();
+
client = client();
+
+ PGSimpleDataSource ds = new PGSimpleDataSource();
+ ds.setUrl(container.getJdbcUrl());
+ ds.setUser(container.getUsername());
+ ds.setPassword(container.getPassword());
+
+ KieFlywayInitializer.builder()
+ .withDatasource(ds)
+ .build()
+ .migrate();
}
@AfterAll
diff --git a/addons/common/pom.xml b/addons/common/pom.xml
index 6ac076d796..1a12e57c0c 100644
--- a/addons/common/pom.xml
+++ b/addons/common/pom.xml
@@ -54,6 +54,7 @@
<module>tracing</module>
<module>task-management</module>
<module>marshallers</module>
+ <module>flyway</module>
</modules>
<dependencyManagement>
diff --git a/kogito-bom/pom.xml b/kogito-bom/pom.xml
index 41d7037eb3..bc9fba78c4 100755
--- a/kogito-bom/pom.xml
+++ b/kogito-bom/pom.xml
@@ -781,6 +781,18 @@
<classifier>sources</classifier>
</dependency>
+ <dependency>
+ <groupId>org.kie</groupId>
+ <artifactId>kie-addons-springboot-flyway</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.kie</groupId>
+ <artifactId>kie-addons-springboot-flyway</artifactId>
+ <version>${project.version}</version>
+ <classifier>sources</classifier>
+ </dependency>
+
<!-- Grafana API -->
<dependency>
<groupId>org.kie.kogito</groupId>
@@ -1720,6 +1732,42 @@
<classifier>sources</classifier>
</dependency>
+ <!-- Flyway Add-on-->
+ <dependency>
+ <groupId>org.kie</groupId>
+ <artifactId>kie-addons-flyway</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.kie</groupId>
+ <artifactId>kie-addons-flyway</artifactId>
+ <version>${project.version}</version>
+ <classifier>sources</classifier>
+ </dependency>
+ <dependency>
+ <groupId>org.kie</groupId>
+ <artifactId>kie-addons-quarkus-flyway</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.kie</groupId>
+ <artifactId>kie-addons-quarkus-flyway</artifactId>
+ <version>${project.version}</version>
+ <classifier>sources</classifier>
+ </dependency>
+ <dependency>
+ <groupId>org.kie</groupId>
+ <artifactId>kie-addons-quarkus-flyway-deployment</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.kie</groupId>
+ <artifactId>kie-addons-quarkus-flyway-deployment</artifactId>
+ <version>${project.version}</version>
+ <classifier>sources</classifier>
+ </dependency>
+
+
<!-- drools -->
<dependency>
<groupId>org.kie.kogito</groupId>
diff --git a/kogito-build/kogito-dependencies-bom/pom.xml b/kogito-build/kogito-dependencies-bom/pom.xml
index e0a87af2f9..0c815fc235 100644
--- a/kogito-build/kogito-dependencies-bom/pom.xml
+++ b/kogito-build/kogito-dependencies-bom/pom.xml
@@ -82,6 +82,7 @@
<version.io.micrometer>1.12.2</version.io.micrometer>
<version.org.flywaydb>9.22.3</version.org.flywaydb>
<version.org.postgresql>42.7.2</version.org.postgresql>
+ <version.com.h2>2.2.220</version.com.h2>
<version.io.serverlessworkflow>4.0.5.Final</version.io.serverlessworkflow>
<!-- Aligned with Quarkus 2.7 (LTS) - see https://issues.redhat.com/browse/KOGITO-7971 -->
<version.io.smallrye-open-api>3.10.0</version.io.smallrye-open-api>
@@ -376,6 +377,11 @@
<artifactId>postgresql</artifactId>
<version>${version.org.postgresql}</version>
</dependency>
+ <dependency>
+ <groupId>com.h2database</groupId>
+ <artifactId>h2</artifactId>
+ <version>${version.com.h2}</version>
+ </dependency>
<dependency>
<groupId>io.smallrye</groupId>
<artifactId>smallrye-open-api-core</artifactId>
@@ -700,6 +706,13 @@
<version>${version.io.swagger.core.v3}</version>
</dependency>
+ <!-- Flyway -->
+ <dependency>
+ <groupId>org.flywaydb</groupId>
+ <artifactId>flyway-core</artifactId>
+ <version>${version.org.flywaydb}</version>
+ </dependency>
+
<!-- infinispan -->
<dependency>
<groupId>org.infinispan</groupId>
diff --git a/kogito-test-utils/src/main/java/org/kie/kogito/testcontainers/KogitoPostgreSqlContainer.java b/kogito-test-utils/src/main/java/org/kie/kogito/testcontainers/KogitoPostgreSqlContainer.java
index 2c284e6074..b631bf23c7 100644
--- a/kogito-test-utils/src/main/java/org/kie/kogito/testcontainers/KogitoPostgreSqlContainer.java
+++ b/kogito-test-utils/src/main/java/org/kie/kogito/testcontainers/KogitoPostgreSqlContainer.java
@@ -27,6 +27,8 @@ import org.slf4j.LoggerFactory;
import org.testcontainers.containers.PostgreSQLContainer;
import org.testcontainers.containers.output.OutputFrame;
import org.testcontainers.containers.output.Slf4jLogConsumer;
+import org.testcontainers.containers.wait.strategy.HostPortWaitStrategy;
+import org.testcontainers.containers.wait.strategy.WaitAllStrategy;
/**
* PostgreSQL Container for Kogito examples.
@@ -42,6 +44,15 @@ public class KogitoPostgreSqlContainer extends PostgreSQLContainer<KogitoPostgre
withLogConsumer(getLogger());
withLogConsumer(new Slf4jLogConsumer(LOGGER));
withStartupTimeout(Constants.CONTAINER_START_TIMEOUT);
+
+ /*
+ * Overriding default waitStrategy (LogMessageWaitStrategy) added by the parent to also wait for the mapped port to be available. This ensures that the PostgreSQLContainer is running
+ * and the mapped ports are ready before running any test.
+ * This avoids connection issues with the container when using container managers that do the port mapping after the container has started.
+ */
+ this.waitStrategy = new WaitAllStrategy()
+ .withStrategy(this.waitStrategy)
+ .withStrategy(new HostPortWaitStrategy());
}
private Consumer<OutputFrame> getLogger() {
diff --git a/quarkus/addons/flyway/deployment/pom.xml b/quarkus/addons/flyway/deployment/pom.xml
new file mode 100644
index 0000000000..1e6eefccdc
--- /dev/null
+++ b/quarkus/addons/flyway/deployment/pom.xml
@@ -0,0 +1,81 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ~ 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.
+ -->
+<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>org.kie</groupId>
+ <artifactId>kie-addons-quarkus-flyway-parent</artifactId>
+ <version>999-SNAPSHOT</version>
+ </parent>
+ <artifactId>kie-addons-quarkus-flyway-deployment</artifactId>
+ <name>Kie :: Add-Ons :: Quarkus :: Flyway :: Deployment</name>
+
+ <properties>
+ <java.module.name>org.kie.flyway.quarkus.deployment</java.module.name>
+ </properties>
+
+ <dependencies>
+
+ <dependency>
+ <groupId>org.kie</groupId>
+ <artifactId>kie-addons-quarkus-flyway</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.kie</groupId>
+ <artifactId>kogito-addons-quarkus-common-deployment</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>io.quarkus</groupId>
+ <artifactId>quarkus-arc-deployment</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>io.quarkus</groupId>
+ <artifactId>quarkus-agroal-deployment</artifactId>
+ </dependency>
+ <!-- Test dependencies -->
+ <dependency>
+ <groupId>org.mockito</groupId>
+ <artifactId>mockito-junit-jupiter</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.assertj</groupId>
+ <artifactId>assertj-core</artifactId>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+ <build>
+ <plugins>
+ <plugin>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <configuration>
+ <annotationProcessorPaths>
+ <path>
+ <groupId>io.quarkus</groupId>
+ <artifactId>quarkus-extension-processor</artifactId>
+ <version>${version.io.quarkus}</version>
+ </path>
+ </annotationProcessorPaths>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+</project>
diff --git a/quarkus/addons/flyway/deployment/src/main/java/org/kie/flyway/quarkus/deployment/KieFlywayExtensionProcessor.java b/quarkus/addons/flyway/deployment/src/main/java/org/kie/flyway/quarkus/deployment/KieFlywayExtensionProcessor.java
new file mode 100644
index 0000000000..5ec0851898
--- /dev/null
+++ b/quarkus/addons/flyway/deployment/src/main/java/org/kie/flyway/quarkus/deployment/KieFlywayExtensionProcessor.java
@@ -0,0 +1,66 @@
+/*
+ * 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.quarkus.deployment;
+
+import java.util.List;
+import java.util.Optional;
+
+import org.kie.flyway.quarkus.KieFlywayQuarkusRecorder;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import io.quarkus.agroal.spi.JdbcDataSourceBuildItem;
+import io.quarkus.arc.deployment.BeanContainerBuildItem;
+import io.quarkus.arc.deployment.SyntheticBeansRuntimeInitBuildItem;
+import io.quarkus.deployment.annotations.*;
+import io.quarkus.deployment.annotations.Record;
+import io.quarkus.deployment.builditem.FeatureBuildItem;
+
+public class KieFlywayExtensionProcessor {
+ private static final Logger LOGGER = LoggerFactory.getLogger(KieFlywayExtensionProcessor.class);
+
+ private static final String FEATURE = "kie-flyway";
+
+ @BuildStep
+ FeatureBuildItem feature() {
+ return new FeatureBuildItem(FEATURE);
+ }
+
+ @BuildStep
+ @Consume(BeanContainerBuildItem.class)
+ @Consume(JdbcDataSourceBuildItem.class)
+ @Produce(SyntheticBeansRuntimeInitBuildItem.class)
+ @Record(ExecutionTime.RUNTIME_INIT)
+ void runMigration(
+ KieFlywayQuarkusRecorder recorder,
+ List<JdbcDataSourceBuildItem> jdbcDataSourceBuildItems) {
+
+ Optional<JdbcDataSourceBuildItem> jdbcDataSourceOptional = jdbcDataSourceBuildItems.stream()
+ .filter(JdbcDataSourceBuildItem::isDefault)
+ .findFirst();
+
+ if (jdbcDataSourceOptional.isEmpty()) {
+ LOGGER.warn("KIE Flyway: No default DataSource defined, Skipping KIE Flyway...");
+ return;
+ }
+
+ JdbcDataSourceBuildItem jdbcDataSource = jdbcDataSourceOptional.get();
+ recorder.run(jdbcDataSource.getName());
+ }
+}
diff --git a/quarkus/addons/flyway/pom.xml b/quarkus/addons/flyway/pom.xml
new file mode 100644
index 0000000000..8d225364a8
--- /dev/null
+++ b/quarkus/addons/flyway/pom.xml
@@ -0,0 +1,39 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ~ 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.
+ -->
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>org.kie</groupId>
+ <artifactId>kogito-addons-quarkus-parent</artifactId>
+ <version>999-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>kie-addons-quarkus-flyway-parent</artifactId>
+ <name>Kie :: Add-Ons :: Quarkus :: Flyway :: Parent</name>
+ <packaging>pom</packaging>
+
+ <modules>
+ <module>runtime</module>
+ <module>deployment</module>
+ </modules>
+
+</project>
diff --git a/quarkus/addons/flyway/runtime/pom.xml b/quarkus/addons/flyway/runtime/pom.xml
new file mode 100644
index 0000000000..3190d2cbf8
--- /dev/null
+++ b/quarkus/addons/flyway/runtime/pom.xml
@@ -0,0 +1,93 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ~ 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.
+ -->
+<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>org.kie</groupId>
+ <artifactId>kie-addons-quarkus-flyway-parent</artifactId>
+ <version>999-SNAPSHOT</version>
+ </parent>
+ <artifactId>kie-addons-quarkus-flyway</artifactId>
+ <name>Kie :: Add-Ons :: Quarkus :: Flyway :: Runtime</name>
+
+ <properties>
+ <java.module.name>org.kie.flyway.quarkus.runtime</java.module.name>
+ </properties>
+
+ <dependencies>
+ <dependency>
+ <groupId>jakarta.enterprise</groupId>
+ <artifactId>jakarta.enterprise.cdi-api</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>io.quarkus</groupId>
+ <artifactId>quarkus-core</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>io.quarkus</groupId>
+ <artifactId>quarkus-agroal</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>io.quarkus</groupId>
+ <artifactId>quarkus-builder</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.kie</groupId>
+ <artifactId>kie-addons-flyway</artifactId>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>io.quarkus</groupId>
+ <artifactId>quarkus-extension-maven-plugin</artifactId>
+ <version>${version.io.quarkus}</version>
+ <executions>
+ <execution>
+ <phase>compile</phase>
+ <goals>
+ <goal>extension-descriptor</goal>
+ </goals>
+ <configuration>
+ <deployment>${project.groupId}:${project.artifactId}-deployment:${project.version}</deployment>
+ <capabilities>
+ <provides>org.kie.addons.flyway</provides>
+ </capabilities>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ <plugin>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <configuration>
+ <annotationProcessorPaths>
+ <path>
+ <groupId>io.quarkus</groupId>
+ <artifactId>quarkus-extension-processor</artifactId>
+ <version>${version.io.quarkus}</version>
+ </path>
+ </annotationProcessorPaths>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+</project>
diff --git a/quarkus/addons/flyway/runtime/src/main/java/org/kie/flyway/quarkus/KieFlywayQuarkusRecorder.java b/quarkus/addons/flyway/runtime/src/main/java/org/kie/flyway/quarkus/KieFlywayQuarkusRecorder.java
new file mode 100644
index 0000000000..13d4c84161
--- /dev/null
+++ b/quarkus/addons/flyway/runtime/src/main/java/org/kie/flyway/quarkus/KieFlywayQuarkusRecorder.java
@@ -0,0 +1,48 @@
+/*
+ * 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.quarkus;
+
+import javax.sql.DataSource;
+
+import org.kie.flyway.integration.KieFlywayRunner;
+
+import io.quarkus.agroal.runtime.DataSources;
+import io.quarkus.arc.Arc;
+import io.quarkus.runtime.RuntimeValue;
+import io.quarkus.runtime.annotations.Recorder;
+
+@Recorder
+public class KieFlywayQuarkusRecorder {
+
+ private final RuntimeValue<KieFlywayQuarkusRuntimeConfig> config;
+
+ public KieFlywayQuarkusRecorder(RuntimeValue<KieFlywayQuarkusRuntimeConfig> config) {
+ this.config = config;
+ }
+
+ public void run(String defaultDSName) {
+
+ DataSources agroalDatasourceS = Arc.container().select(DataSources.class).get();
+ DataSource dataSource = agroalDatasourceS.getDataSource(defaultDSName);
+
+ KieFlywayRunner.get(config.getValue())
+ .runFlyway(dataSource);
+ }
+}
diff --git a/quarkus/addons/flyway/runtime/src/main/java/org/kie/flyway/quarkus/KieFlywayQuarkusRuntimeConfig.java b/quarkus/addons/flyway/runtime/src/main/java/org/kie/flyway/quarkus/KieFlywayQuarkusRuntimeConfig.java
new file mode 100644
index 0000000000..3f79c9643e
--- /dev/null
+++ b/quarkus/addons/flyway/runtime/src/main/java/org/kie/flyway/quarkus/KieFlywayQuarkusRuntimeConfig.java
@@ -0,0 +1,71 @@
+/*
+ * 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.quarkus;
+
+import java.util.Map;
+
+import org.kie.flyway.integration.KieFlywayConfiguration;
+import org.kie.flyway.integration.KieFlywayNamedModule;
+
+import io.quarkus.runtime.annotations.*;
+
+/**
+ * Configuration for the Kie Flyway initializer
+ */
+@ConfigRoot(prefix = "kie", name = "flyway", phase = ConfigPhase.RUN_TIME)
+public class KieFlywayQuarkusRuntimeConfig implements KieFlywayConfiguration<KieFlywayQuarkusRuntimeConfig.KieQuarkusFlywayNamedModule> {
+
+ /**
+ * Enables the execution of the Flyway initializer during the application startup
+ */
+ @ConfigItem(name = "enabled", defaultValue = "true")
+ boolean enabled;
+
+ /**
+ * List of {@link KieQuarkusFlywayNamedModule} that allow to enable or disable a given modul
+ */
+ @ConfigItem(name = "modules")
+ Map<String, KieQuarkusFlywayNamedModule> modules;
+
+ @Override
+ public boolean isEnabled() {
+ return enabled;
+ }
+
+ @Override
+ public Map<String, KieQuarkusFlywayNamedModule> getModules() {
+ return modules;
+ }
+
+ @ConfigGroup
+ public static class KieQuarkusFlywayNamedModule implements KieFlywayNamedModule {
+
+ /**
+ * Enables the execution of the Flyway initializer for a specific Kie module
+ */
+ @ConfigItem(name = "enabled", defaultValue = "true")
+ boolean enabled;
+
+ @Override
+ public boolean isEnabled() {
+ return enabled;
+ }
+ }
+}
diff --git a/quarkus/integration-tests/integration-tests-quarkus-processes-persistence/integration-tests-quarkus-processes-jdbc/src/main/resources/application.properties b/quarkus/addons/flyway/runtime/src/main/resources/META-INF/quarkus-extension.yaml
similarity index 68%
copy from quarkus/integration-tests/integration-tests-quarkus-processes-persistence/integration-tests-quarkus-processes-jdbc/src/main/resources/application.properties
copy to quarkus/addons/flyway/runtime/src/main/resources/META-INF/quarkus-extension.yaml
index d8f8597118..4500983809 100644
--- a/quarkus/integration-tests/integration-tests-quarkus-processes-persistence/integration-tests-quarkus-processes-jdbc/src/main/resources/application.properties
+++ b/quarkus/addons/flyway/runtime/src/main/resources/META-INF/quarkus-extension.yaml
@@ -17,8 +17,20 @@
# under the License.
#
-kogito.persistence.type=jdbc
-#run create tables scripts
-quarkus.datasource.db-kind=postgresql
-quarkus.flyway.migrate-at-start=true
-quarkus.flyway.clean-at-start=true
\ No newline at end of file
+name: KIE Flyway Add-On
+description: Add-On that enables other addons to initialize their DB using Flyway
+metadata:
+ keywords:
+ - KIE
+ - Flyway
+ - persistence
+ - jdbc
+ guide: https://quarkus.io/guides/kie
+ categories:
+ - "business-automation"
+ - "cloud"
+ - "flyway"
+ - "persistence"
+ status: "stable"
+ config:
+ - "kie.flyway"
diff --git a/addons/common/persistence/postgresql/.gitignore b/quarkus/addons/flyway/runtime/src/main/resources/application.properties
similarity index 95%
copy from addons/common/persistence/postgresql/.gitignore
copy to quarkus/addons/flyway/runtime/src/main/resources/application.properties
index acccaf1ecb..9062673824 100644
--- a/addons/common/persistence/postgresql/.gitignore
+++ b/quarkus/addons/flyway/runtime/src/main/resources/application.properties
@@ -1,4 +1,4 @@
-###
+#
# 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
@@ -15,6 +15,6 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
-###
+#
-src/main/resources/db/migration/*
\ No newline at end of file
+%dev,test.kie.flyway.enabled=true
\ No newline at end of file
diff --git a/quarkus/addons/persistence/jdbc/deployment/pom.xml b/quarkus/addons/persistence/jdbc/deployment/pom.xml
index 53344acf12..c5defc7336 100644
--- a/quarkus/addons/persistence/jdbc/deployment/pom.xml
+++ b/quarkus/addons/persistence/jdbc/deployment/pom.xml
@@ -44,12 +44,12 @@
<artifactId>kogito-addons-quarkus-common-deployment</artifactId>
</dependency>
<dependency>
- <groupId>io.quarkus</groupId>
- <artifactId>quarkus-arc-deployment</artifactId>
+ <groupId>org.kie</groupId>
+ <artifactId>kie-addons-quarkus-flyway-deployment</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
- <artifactId>quarkus-flyway-deployment</artifactId>
+ <artifactId>quarkus-arc-deployment</artifactId>
</dependency>
</dependencies>
<build>
diff --git a/quarkus/addons/persistence/jdbc/runtime/pom.xml b/quarkus/addons/persistence/jdbc/runtime/pom.xml
index 8b2083cc70..aca45b3bda 100644
--- a/quarkus/addons/persistence/jdbc/runtime/pom.xml
+++ b/quarkus/addons/persistence/jdbc/runtime/pom.xml
@@ -51,8 +51,8 @@
<artifactId>kie-addons-persistence-jdbc</artifactId>
</dependency>
<dependency>
- <groupId>io.quarkus</groupId>
- <artifactId>quarkus-flyway</artifactId>
+ <groupId>org.kie</groupId>
+ <artifactId>kie-addons-quarkus-flyway</artifactId>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
diff --git a/quarkus/addons/persistence/jdbc/runtime/src/main/java/org/kie/kogito/persistence/quarkus/KogitoAddOnPersistenceJDBCConfigSourceFactory.java b/quarkus/addons/persistence/jdbc/runtime/src/main/java/org/kie/kogito/persistence/quarkus/KogitoAddOnPersistenceJDBCConfigSourceFactory.java
deleted file mode 100644
index 5f5493d351..0000000000
--- a/quarkus/addons/persistence/jdbc/runtime/src/main/java/org/kie/kogito/persistence/quarkus/KogitoAddOnPersistenceJDBCConfigSourceFactory.java
+++ /dev/null
@@ -1,83 +0,0 @@
-/*
- * 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.kogito.persistence.quarkus;
-
-import java.util.Arrays;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.OptionalInt;
-import java.util.Set;
-import java.util.stream.Collectors;
-
-import org.eclipse.microprofile.config.spi.ConfigSource;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import io.smallrye.config.ConfigSourceContext;
-import io.smallrye.config.ConfigSourceFactory;
-import io.smallrye.config.ConfigValue;
-
-import static org.kie.kogito.persistence.quarkus.KogitoAddOnPersistenceJDBCConfigSource.ORDINAL;
-
-public class KogitoAddOnPersistenceJDBCConfigSourceFactory implements ConfigSourceFactory {
- private static final Logger LOGGER = LoggerFactory.getLogger(KogitoAddOnPersistenceJDBCConfigSourceFactory.class);
-
- static final String FLYWAY_LOCATIONS = "quarkus.flyway.locations";
- static final String DATASOURCE_DB_KIND = "quarkus.datasource.db-kind";
- private static final String LOCATION_PREFIX = "classpath:/db/";
- static final String POSTGRESQL = "postgresql";
- private static final String ANSI = "ansi";
-
- @Override
- public Iterable<ConfigSource> getConfigSources(ConfigSourceContext context) {
- ConfigValue flywayLocationsConfigValue = context.getValue(FLYWAY_LOCATIONS);
- return getConfigSourcesInternal(context.getValue(DATASOURCE_DB_KIND).getValue(),
- flywayLocationsConfigValue.getValue(), flywayLocationsConfigValue.getConfigSourceOrdinal());
- }
-
- Iterable<ConfigSource> getConfigSourcesInternal(String databaseName, String flywayLocationsValue, int flywayLocationsConfigSourceOrdinal) {
- Map<String, String> configuration = new HashMap<>();
- if (databaseName != null) {
- if (flywayLocationsValue == null || flywayLocationsConfigSourceOrdinal == Integer.MIN_VALUE) {
- configuration.put(FLYWAY_LOCATIONS, LOCATION_PREFIX + getDBName(databaseName));
- } else {
- Set<String> locations = Arrays.stream(flywayLocationsValue.split(",")).collect(Collectors.toSet());
- locations.add(LOCATION_PREFIX + getDBName(databaseName));
- configuration.put(FLYWAY_LOCATIONS, String.join(",", locations));
- }
- } else {
- LOGGER.warn("Kogito Flyway must have the property \"quarkus.datasource.db-kind\" to be set to initialize process schema.");
- }
- return List.of(new KogitoAddOnPersistenceJDBCConfigSource(configuration));
- }
-
- @Override
- public OptionalInt getPriority() {
- return OptionalInt.of(ORDINAL);
- }
-
- private String getDBName(final String dbKind) {
- if (POSTGRESQL.equals(dbKind)) {
- return POSTGRESQL;
- } else {
- return ANSI;
- }
- }
-}
diff --git a/quarkus/addons/persistence/jdbc/runtime/src/test/java/org/kie/kogito/persistence/quarkus/KogitoAddOnPersistenceJDBCConfigSourceFactoryTest.java b/quarkus/addons/persistence/jdbc/runtime/src/test/java/org/kie/kogito/persistence/quarkus/KogitoAddOnPersistenceJDBCConfigSourceFactoryTest.java
deleted file mode 100644
index c6033f3123..0000000000
--- a/quarkus/addons/persistence/jdbc/runtime/src/test/java/org/kie/kogito/persistence/quarkus/KogitoAddOnPersistenceJDBCConfigSourceFactoryTest.java
+++ /dev/null
@@ -1,85 +0,0 @@
-/*
- * 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.kogito.persistence.quarkus;
-
-import java.util.Arrays;
-import java.util.Set;
-import java.util.stream.Collectors;
-
-import org.eclipse.microprofile.config.spi.ConfigSource;
-import org.junit.jupiter.api.Test;
-
-import static org.assertj.core.api.Assertions.assertThat;
-import static org.kie.kogito.persistence.quarkus.KogitoAddOnPersistenceJDBCConfigSourceFactory.FLYWAY_LOCATIONS;
-import static org.kie.kogito.persistence.quarkus.KogitoAddOnPersistenceJDBCConfigSourceFactory.POSTGRESQL;
-
-class KogitoAddOnPersistenceJDBCConfigSourceFactoryTest {
-
- private final static KogitoAddOnPersistenceJDBCConfigSourceFactory factory = new KogitoAddOnPersistenceJDBCConfigSourceFactory();
-
- @Test
- void getConfigSourcesInternalExistingLocations() {
- Set<String> locationsSet = getLocationsSet(getConfigSource(POSTGRESQL, "/path/to/locations", Integer.MAX_VALUE)
- .getValue(FLYWAY_LOCATIONS));
-
- assertThat(locationsSet).containsExactlyInAnyOrder("/path/to/locations", "classpath:/db/postgresql");
- }
-
- @Test
- void getConfigSourcesInternalDefaultLocations() {
- Set<String> locationsSet = getLocationsSet(getConfigSource(POSTGRESQL, "/path/to/locations", Integer.MIN_VALUE)
- .getValue(FLYWAY_LOCATIONS));
-
- assertThat(locationsSet).containsOnly("classpath:/db/postgresql");
- }
-
- @Test
- void getConfigSourcesInternalNoExistingLocations() {
- Set<String> locationsSet = getLocationsSet(getConfigSource(POSTGRESQL, null, Integer.MAX_VALUE)
- .getValue(FLYWAY_LOCATIONS));
-
- assertThat(locationsSet).containsExactlyInAnyOrder("classpath:/db/postgresql");
- }
-
- @Test
- void getConfigSourcesInternalDatabaseNameEmpty() {
- ConfigSource configSource = getConfigSource(null, "/path/to/locations", Integer.MAX_VALUE);
- assertThat(configSource.getPropertyNames()).isEmpty();
- }
-
- @Test
- void getConfigSourcesInternalEnsuresNoDuplication() {
- Set<String> locationsSet = getLocationsSet(getConfigSource(POSTGRESQL, "classpath:/db/postgresql", Integer.MAX_VALUE)
- .getValue(FLYWAY_LOCATIONS));
-
- assertThat(locationsSet).containsExactlyInAnyOrder("classpath:/db/postgresql");
- }
-
- private static ConfigSource getConfigSource(String databaseName, String flywayLocationsValue,
- int flywayLocationsConfigSourceOrdinal) {
- Iterable<ConfigSource> configSources = factory.getConfigSourcesInternal(databaseName, flywayLocationsValue,
- flywayLocationsConfigSourceOrdinal);
- assertThat(configSources).hasSize(1);
- return configSources.iterator().next();
- }
-
- private static Set<String> getLocationsSet(String locations) {
- return Arrays.stream(locations.split(",")).collect(Collectors.toSet());
- }
-}
\ No newline at end of file
diff --git a/quarkus/addons/persistence/postgresql/deployment/pom.xml b/quarkus/addons/persistence/postgresql/deployment/pom.xml
index 2b668718c1..785f84a028 100644
--- a/quarkus/addons/persistence/postgresql/deployment/pom.xml
+++ b/quarkus/addons/persistence/postgresql/deployment/pom.xml
@@ -44,16 +44,16 @@
<artifactId>kogito-addons-quarkus-common-deployment</artifactId>
</dependency>
<dependency>
- <groupId>io.quarkus</groupId>
- <artifactId>quarkus-arc-deployment</artifactId>
+ <groupId>org.kie</groupId>
+ <artifactId>kie-addons-quarkus-flyway-deployment</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
- <artifactId>quarkus-reactive-pg-client-deployment</artifactId>
+ <artifactId>quarkus-arc-deployment</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
- <artifactId>quarkus-flyway-deployment</artifactId>
+ <artifactId>quarkus-reactive-pg-client-deployment</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
diff --git a/quarkus/addons/persistence/postgresql/runtime/pom.xml b/quarkus/addons/persistence/postgresql/runtime/pom.xml
index 584cc425df..a2f11150fb 100644
--- a/quarkus/addons/persistence/postgresql/runtime/pom.xml
+++ b/quarkus/addons/persistence/postgresql/runtime/pom.xml
@@ -55,8 +55,8 @@
</dependency>
<!-- Flyway -->
<dependency>
- <groupId>io.quarkus</groupId>
- <artifactId>quarkus-flyway</artifactId>
+ <groupId>org.kie</groupId>
+ <artifactId>kie-addons-quarkus-flyway</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
diff --git a/quarkus/addons/pom.xml b/quarkus/addons/pom.xml
index 6b27efb501..2a51d08ca8 100644
--- a/quarkus/addons/pom.xml
+++ b/quarkus/addons/pom.xml
@@ -40,6 +40,7 @@
<module>messaging</module>
<module>common</module>
<module>rest-exception-handler</module>
+ <module>flyway</module>
<module>persistence</module>
<module>process-management</module>
<module>source-files</module>
diff --git a/quarkus/extensions/kogito-quarkus-serverless-workflow-extension/kogito-quarkus-serverless-workflow-integration-test/src/main/resources/application.properties b/quarkus/extensions/kogito-quarkus-serverless-workflow-extension/kogito-quarkus-serverless-workflow-integration-test/src/main/resources/application.properties
index 977b958331..4148d96572 100644
--- a/quarkus/extensions/kogito-quarkus-serverless-workflow-extension/kogito-quarkus-serverless-workflow-integration-test/src/main/resources/application.properties
+++ b/quarkus/extensions/kogito-quarkus-serverless-workflow-extension/kogito-quarkus-serverless-workflow-integration-test/src/main/resources/application.properties
@@ -23,8 +23,7 @@ quarkus.swagger-ui.always-include=true
kogito.persistence.type=jdbc
kogito.persistence.proto.marshaller=false
quarkus.datasource.db-kind=postgresql
-quarkus.flyway.migrate-at-start=true
-quarkus.flyway.clean-at-start=true
+kie.flyway.enabled=true
quarkus.http.test-port=0
quarkus.log.level=INFO
diff --git a/quarkus/integration-tests/integration-tests-quarkus-processes-persistence/integration-tests-quarkus-processes-jdbc/src/main/resources/application.properties b/quarkus/integration-tests/integration-tests-quarkus-processes-persistence/integration-tests-quarkus-processes-jdbc/src/main/resources/application.properties
index d8f8597118..19109e37cd 100644
--- a/quarkus/integration-tests/integration-tests-quarkus-processes-persistence/integration-tests-quarkus-processes-jdbc/src/main/resources/application.properties
+++ b/quarkus/integration-tests/integration-tests-quarkus-processes-persistence/integration-tests-quarkus-processes-jdbc/src/main/resources/application.properties
@@ -20,5 +20,5 @@
kogito.persistence.type=jdbc
#run create tables scripts
quarkus.datasource.db-kind=postgresql
-quarkus.flyway.migrate-at-start=true
-quarkus.flyway.clean-at-start=true
\ No newline at end of file
+
+kie.flyway.enabled=true
\ No newline at end of file
diff --git a/quarkus/integration-tests/integration-tests-quarkus-processes-persistence/integration-tests-quarkus-processes-postgresql/src/main/resources/application.properties b/quarkus/integration-tests/integration-tests-quarkus-processes-persistence/integration-tests-quarkus-processes-postgresql/src/main/resources/application.properties
index 91a52baeab..e090cfc7be 100644
--- a/quarkus/integration-tests/integration-tests-quarkus-processes-persistence/integration-tests-quarkus-processes-postgresql/src/main/resources/application.properties
+++ b/quarkus/integration-tests/integration-tests-quarkus-processes-persistence/integration-tests-quarkus-processes-postgresql/src/main/resources/application.properties
@@ -19,6 +19,4 @@
kogito.persistence.type=postgresql
-# Quarkus
-quarkus.flyway.migrate-at-start=true
-quarkus.flyway.clean-at-start=true
\ No newline at end of file
+kie.flyway.enabled=true
\ No newline at end of file
diff --git a/springboot/addons/flyway/pom.xml b/springboot/addons/flyway/pom.xml
new file mode 100644
index 0000000000..00d429c9d3
--- /dev/null
+++ b/springboot/addons/flyway/pom.xml
@@ -0,0 +1,73 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ~ 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.
+ -->
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <parent>
+ <artifactId>kogito-addons-springboot-parent</artifactId>
+ <groupId>org.kie</groupId>
+ <version>999-SNAPSHOT</version>
+ </parent>
+ <modelVersion>4.0.0</modelVersion>
+
+ <artifactId>kie-addons-springboot-flyway</artifactId>
+ <name>Kie :: Add-Ons :: Spring Boot :: Flyway</name>
+
+ <properties>
+ <java.module.name>org.kie.springboot.flyway</java.module.name>
+ </properties>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.springframework.boot</groupId>
+ <artifactId>spring-boot-starter-web</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework.boot</groupId>
+ <artifactId>spring-boot-starter-jdbc</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.kie</groupId>
+ <artifactId>kie-addons-flyway</artifactId>
+ </dependency>
+
+ <!-- test dependencies -->
+ <dependency>
+ <groupId>org.junit.jupiter</groupId>
+ <artifactId>junit-jupiter-engine</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.assertj</groupId>
+ <artifactId>assertj-core</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.mockito</groupId>
+ <artifactId>mockito-junit-jupiter</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>ch.qos.logback</groupId>
+ <artifactId>logback-classic</artifactId>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+</project>
\ No newline at end of file
diff --git a/springboot/addons/flyway/src/main/java/org/kie/flyway/springboot/KieFlywaySpringbootAutoConfiguration.java b/springboot/addons/flyway/src/main/java/org/kie/flyway/springboot/KieFlywaySpringbootAutoConfiguration.java
new file mode 100644
index 0000000000..dba3430b91
--- /dev/null
+++ b/springboot/addons/flyway/src/main/java/org/kie/flyway/springboot/KieFlywaySpringbootAutoConfiguration.java
@@ -0,0 +1,50 @@
+/*
+ * 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 javax.sql.DataSource;
+
+import org.flywaydb.core.Flyway;
+import org.springframework.beans.factory.ObjectProvider;
+import org.springframework.boot.autoconfigure.AutoConfiguration;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
+import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
+import org.springframework.boot.context.properties.EnableConfigurationProperties;
+import org.springframework.boot.sql.init.dependency.DatabaseInitializationDependencyConfigurer;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Import;
+
+@AutoConfiguration(after = { DataSourceAutoConfiguration.class })
+@ConditionalOnProperty(prefix = "kie.flyway", name = "enabled", havingValue = "true")
+@ConditionalOnClass(Flyway.class)
+@Import(DatabaseInitializationDependencyConfigurer.class)
+@EnableConfigurationProperties(KieFlywaySpringbootProperties.class)
+public class KieFlywaySpringbootAutoConfiguration {
+
+ @Bean
+ public KieFlywaySpringbootInitializer kieFlyway(KieFlywaySpringbootProperties properties, ObjectProvider<DataSource> dataSource) {
+
+ DataSource ds = dataSource.getIfAvailable();
+
+ return new KieFlywaySpringbootInitializer(properties, ds);
+ }
+
+}
diff --git a/springboot/addons/flyway/src/main/java/org/kie/flyway/springboot/KieFlywaySpringbootInitializer.java b/springboot/addons/flyway/src/main/java/org/kie/flyway/springboot/KieFlywaySpringbootInitializer.java
new file mode 100644
index 0000000000..dff89d58c2
--- /dev/null
+++ b/springboot/addons/flyway/src/main/java/org/kie/flyway/springboot/KieFlywaySpringbootInitializer.java
@@ -0,0 +1,51 @@
+/*
+ * 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 javax.sql.DataSource;
+
+import org.kie.flyway.integration.KieFlywayRunner;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.InitializingBean;
+import org.springframework.core.Ordered;
+
+public class KieFlywaySpringbootInitializer implements InitializingBean, Ordered {
+ private static final Logger LOGGER = LoggerFactory.getLogger(KieFlywaySpringbootInitializer.class);
+
+ private final KieFlywaySpringbootProperties properties;
+ private final DataSource dataSource;
+
+ public KieFlywaySpringbootInitializer(KieFlywaySpringbootProperties properties, DataSource dataSource) {
+ this.properties = properties;
+ this.dataSource = dataSource;
+ }
+
+ @Override
+ public void afterPropertiesSet() {
+ KieFlywayRunner.get(properties)
+ .runFlyway(dataSource);
+ }
+
+ @Override
+ public int getOrder() {
+ return 0;
+ }
+}
diff --git a/springboot/addons/flyway/src/main/java/org/kie/flyway/springboot/KieFlywaySpringbootProperties.java b/springboot/addons/flyway/src/main/java/org/kie/flyway/springboot/KieFlywaySpringbootProperties.java
new file mode 100644
index 0000000000..3c89ad447d
--- /dev/null
+++ b/springboot/addons/flyway/src/main/java/org/kie/flyway/springboot/KieFlywaySpringbootProperties.java
@@ -0,0 +1,63 @@
+/*
+ * 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 java.util.HashMap;
+import java.util.Map;
+
+import org.kie.flyway.integration.KieFlywayConfiguration;
+import org.kie.flyway.integration.KieFlywayNamedModule;
+import org.springframework.boot.context.properties.ConfigurationProperties;
+
+@ConfigurationProperties(prefix = "kie.flyway")
+public class KieFlywaySpringbootProperties implements KieFlywayConfiguration<KieFlywaySpringbootProperties.KieFlywaySpringbootNamedModule> {
+ private boolean enabled = true;
+
+ private Map<String, KieFlywaySpringbootNamedModule> modules = new HashMap<>();
+
+ public boolean isEnabled() {
+ return enabled;
+ }
+
+ public void setEnabled(boolean enabled) {
+ this.enabled = enabled;
+ }
+
+ public Map<String, KieFlywaySpringbootNamedModule> getModules() {
+ return modules;
+ }
+
+ public void setModules(Map<String, KieFlywaySpringbootNamedModule> modules) {
+ this.modules = modules;
+ }
+
+ public static class KieFlywaySpringbootNamedModule implements KieFlywayNamedModule {
+
+ private boolean enabled = true;
+
+ public boolean isEnabled() {
+ return enabled;
+ }
+
+ public void setEnabled(boolean enabled) {
+ this.enabled = enabled;
+ }
+ }
+}
diff --git a/quarkus/addons/persistence/jdbc/runtime/src/main/java/org/kie/kogito/persistence/quarkus/KogitoAddOnPersistenceJDBCConfigSource.java b/springboot/addons/flyway/src/main/java/org/kie/flyway/springboot/detector/KieFlywaySpringbootInitializerDetector.java
similarity index 51%
rename from quarkus/addons/persistence/jdbc/runtime/src/main/java/org/kie/kogito/persistence/quarkus/KogitoAddOnPersistenceJDBCConfigSource.java
rename to springboot/addons/flyway/src/main/java/org/kie/flyway/springboot/detector/KieFlywaySpringbootInitializerDetector.java
index 9e0a7e8791..193f61d3ec 100644
--- a/quarkus/addons/persistence/jdbc/runtime/src/main/java/org/kie/kogito/persistence/quarkus/KogitoAddOnPersistenceJDBCConfigSource.java
+++ b/springboot/addons/flyway/src/main/java/org/kie/flyway/springboot/detector/KieFlywaySpringbootInitializerDetector.java
@@ -16,40 +16,23 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.kie.kogito.persistence.quarkus;
-import java.util.Map;
-import java.util.Set;
-
-import org.eclipse.microprofile.config.spi.ConfigSource;
-
-public class KogitoAddOnPersistenceJDBCConfigSource implements ConfigSource {
-
- static final Integer ORDINAL = 500;
-
- private final Map<String, String> configuration;
-
- public KogitoAddOnPersistenceJDBCConfigSource(Map<String, String> configuration) {
- this.configuration = configuration;
- }
+package org.kie.flyway.springboot.detector;
- @Override
- public Set<String> getPropertyNames() {
- return configuration.keySet();
- }
+import java.util.Set;
- @Override
- public int getOrdinal() {
- return ORDINAL;
- }
+import org.kie.flyway.springboot.KieFlywaySpringbootInitializer;
+import org.springframework.boot.sql.init.dependency.AbstractBeansOfTypeDatabaseInitializerDetector;
+import org.springframework.core.Ordered;
+public class KieFlywaySpringbootInitializerDetector extends AbstractBeansOfTypeDatabaseInitializerDetector {
@Override
- public String getValue(String propertyName) {
- return configuration.get(propertyName);
+ protected Set<Class<?>> getDatabaseInitializerBeanTypes() {
+ return Set.of(KieFlywaySpringbootInitializer.class);
}
@Override
- public String getName() {
- return KogitoAddOnPersistenceJDBCConfigSource.class.getSimpleName();
+ public int getOrder() {
+ return Ordered.HIGHEST_PRECEDENCE;
}
}
diff --git a/springboot/addons/flyway/src/main/resources/META-INF/beans.xml b/springboot/addons/flyway/src/main/resources/META-INF/beans.xml
new file mode 100644
index 0000000000..e69de29bb2
diff --git a/quarkus/integration-tests/integration-tests-quarkus-processes-persistence/integration-tests-quarkus-processes-jdbc/src/main/resources/application.properties b/springboot/addons/flyway/src/main/resources/META-INF/spring.factories
similarity index 81%
copy from quarkus/integration-tests/integration-tests-quarkus-processes-persistence/integration-tests-quarkus-processes-jdbc/src/main/resources/application.properties
copy to springboot/addons/flyway/src/main/resources/META-INF/spring.factories
index d8f8597118..84b09ca03f 100644
--- a/quarkus/integration-tests/integration-tests-quarkus-processes-persistence/integration-tests-quarkus-processes-jdbc/src/main/resources/application.properties
+++ b/springboot/addons/flyway/src/main/resources/META-INF/spring.factories
@@ -17,8 +17,6 @@
# under the License.
#
-kogito.persistence.type=jdbc
-#run create tables scripts
-quarkus.datasource.db-kind=postgresql
-quarkus.flyway.migrate-at-start=true
-quarkus.flyway.clean-at-start=true
\ No newline at end of file
+# DataSource Initializer Detectors
+org.springframework.boot.sql.init.dependency.DatabaseInitializerDetector=\
+org.kie.flyway.springboot.detector.KieFlywaySpringbootInitializerDetector
\ No newline at end of file
diff --git a/addons/common/persistence/postgresql/.gitignore b/springboot/addons/flyway/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports
similarity index 92%
copy from addons/common/persistence/postgresql/.gitignore
copy to springboot/addons/flyway/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports
index acccaf1ecb..24653073af 100644
--- a/addons/common/persistence/postgresql/.gitignore
+++ b/springboot/addons/flyway/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports
@@ -1,4 +1,4 @@
-###
+#
# 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
@@ -15,6 +15,6 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
-###
+#
-src/main/resources/db/migration/*
\ No newline at end of file
+org.kie.flyway.springboot.KieFlywaySpringbootAutoConfiguration
\ No newline at end of file
diff --git a/springboot/addons/persistence/jdbc/pom.xml b/springboot/addons/persistence/jdbc/pom.xml
index 12fe4766a3..5c52342139 100644
--- a/springboot/addons/persistence/jdbc/pom.xml
+++ b/springboot/addons/persistence/jdbc/pom.xml
@@ -42,6 +42,10 @@
<groupId>org.kie</groupId>
<artifactId>kie-addons-persistence-jdbc</artifactId>
</dependency>
+ <dependency>
+ <groupId>org.kie</groupId>
+ <artifactId>kie-addons-springboot-flyway</artifactId>
+ </dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
diff --git a/springboot/addons/persistence/postgresql/pom.xml b/springboot/addons/persistence/postgresql/pom.xml
index 025fd3e808..827ee10320 100644
--- a/springboot/addons/persistence/postgresql/pom.xml
+++ b/springboot/addons/persistence/postgresql/pom.xml
@@ -42,6 +42,10 @@
<groupId>org.kie</groupId>
<artifactId>kie-addons-persistence-postgresql</artifactId>
</dependency>
+ <dependency>
+ <groupId>org.kie</groupId>
+ <artifactId>kie-addons-springboot-flyway</artifactId>
+ </dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
diff --git a/springboot/addons/pom.xml b/springboot/addons/pom.xml
index 46fd6ecde8..d6221ca7a6 100644
--- a/springboot/addons/pom.xml
+++ b/springboot/addons/pom.xml
@@ -49,6 +49,7 @@
<module>process-management</module>
<module>task-management</module>
<module>kubernetes</module>
+ <module>flyway</module>
<module>persistence</module>
</modules>
diff --git a/springboot/integration-tests/integration-tests-springboot-processes-persistence-it/integration-tests-springboot-processes-jdbc/src/main/resources/application.properties b/springboot/integration-tests/integration-tests-springboot-processes-persistence-it/integration-tests-springboot-processes-jdbc/src/main/resources/application.properties
index 2b28c3283b..580f609a9e 100644
--- a/springboot/integration-tests/integration-tests-springboot-processes-persistence-it/integration-tests-springboot-processes-jdbc/src/main/resources/application.properties
+++ b/springboot/integration-tests/integration-tests-springboot-processes-persistence-it/integration-tests-springboot-processes-jdbc/src/main/resources/application.properties
@@ -21,5 +21,6 @@ server.address=0.0.0.0
kogito.persistence.type=jdbc
-spring.flyway.locations=classpath:db/{vendor}
-spring.flyway.enabled=true
+kie.flyway.enabled=true
+
+spring.flyway.enabled=false
diff --git a/springboot/integration-tests/integration-tests-springboot-processes-persistence-it/integration-tests-springboot-processes-postgresql/src/main/resources/application.properties b/springboot/integration-tests/integration-tests-springboot-processes-persistence-it/integration-tests-springboot-processes-postgresql/src/main/resources/application.properties
index 8081c3c1aa..ec75b6f644 100644
--- a/springboot/integration-tests/integration-tests-springboot-processes-persistence-it/integration-tests-springboot-processes-postgresql/src/main/resources/application.properties
+++ b/springboot/integration-tests/integration-tests-springboot-processes-persistence-it/integration-tests-springboot-processes-postgresql/src/main/resources/application.properties
@@ -20,6 +20,8 @@
server.address=0.0.0.0
kogito.persistence.type=postgresql
+kie.flyway.enabled=true
+spring.flyway.enabled=false
# Details https://www.postgresql.org/docs/9.6/static/libpq-connect.html#LIBPQ-CONNSTRING
kogito.persistence.postgresql.connection.uri=postgresql://kogito-user:kogito-pass@localhost:5432/kogito
\ No newline at end of file
diff --git a/springboot/test/src/main/java/org/kie/kogito/testcontainers/springboot/PostgreSqlSpringBootTestResource.java b/springboot/test/src/main/java/org/kie/kogito/testcontainers/springboot/PostgreSqlSpringBootTestResource.java
index eddd29e5f7..b9f32af757 100644
--- a/springboot/test/src/main/java/org/kie/kogito/testcontainers/springboot/PostgreSqlSpringBootTestResource.java
+++ b/springboot/test/src/main/java/org/kie/kogito/testcontainers/springboot/PostgreSqlSpringBootTestResource.java
@@ -34,9 +34,6 @@ public class PostgreSqlSpringBootTestResource extends ConditionalSpringBootTestR
public static final String SPRING_DATASOURCE_URL = "spring.datasource.url";
public static final String SPRING_DATASOURCE_USERNAME = "spring.datasource.username";
public static final String SPRING_DATASOURCE_PASSWORD = "spring.datasource.password";
- public static final String SPRING_FLYWAY_URL = "spring.flyway.url";
- public static final String SPRING_FLYWAY_USERNAME = "spring.flyway.user";
- public static final String SPRING_FLYWAY_PASSWORD = "spring.flyway.password";
public PostgreSqlSpringBootTestResource() {
super(new KogitoPostgreSqlContainer());
@@ -49,9 +46,6 @@ public class PostgreSqlSpringBootTestResource extends ConditionalSpringBootTestR
properties.put(SPRING_DATASOURCE_URL, getTestResource().getJdbcUrl());
properties.put(SPRING_DATASOURCE_USERNAME, getTestResource().getUsername());
properties.put(SPRING_DATASOURCE_PASSWORD, getTestResource().getPassword());
- properties.put(SPRING_FLYWAY_URL, getTestResource().getJdbcUrl());
- properties.put(SPRING_FLYWAY_USERNAME, getTestResource().getUsername());
- properties.put(SPRING_FLYWAY_PASSWORD, getTestResource().getPassword());
return properties;
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@kie.apache.org
For additional commands, e-mail: commits-help@kie.apache.org