diff --git a/addons/common/flyway/README.md b/addons/common/flyway/README.md new file mode 100644 index 00000000000..f27595ae9af --- /dev/null +++ b/addons/common/flyway/README.md @@ -0,0 +1,152 @@ + + +# 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 not 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 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_`) 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.`: 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. + +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/`), 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..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 is 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 incharge 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 +* Data Base Type (`java.lang.String`) to identify the which script locations should be loaded. + + +```java +import org.kie.flyway.KieFlywayInitializer; + +... +KieFlywayInitializer.builder() + .withDbType("postgresql") + .withDatasource(dataSource) + .build() + .migrate(); +``` + +Additional Parameters that can be used: +* Custom ClassLoader to load the `kie-flyway.properties` from. +* Module Exclusions (`Collection`) t + +```java +import org.kie.flyway.KieFlywayInitializer; + +... +KieFlywayInitializer.builder() + .withDbType("postgresql") + .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 charged 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/flyway/src/main/java/org/kie/flyway/KieFlywayInitializer.java b/addons/common/flyway/src/main/java/org/kie/flyway/KieFlywayInitializer.java index a15675403d1..dc1eb0b0407 100644 --- a/addons/common/flyway/src/main/java/org/kie/flyway/KieFlywayInitializer.java +++ b/addons/common/flyway/src/main/java/org/kie/flyway/KieFlywayInitializer.java @@ -96,6 +96,7 @@ private void runFlyway(KieFlywayModuleConfig config) { 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())) diff --git a/addons/common/flyway/src/test/java/org/kie/flyway/AbstractKieFlywayInitializerTest.java b/addons/common/flyway/src/test/java/org/kie/flyway/AbstractKieFlywayInitializerTest.java deleted file mode 100644 index 40fd5f3934c..00000000000 --- a/addons/common/flyway/src/test/java/org/kie/flyway/AbstractKieFlywayInitializerTest.java +++ /dev/null @@ -1,155 +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.flyway; - -import java.sql.Connection; -import java.sql.PreparedStatement; -import java.sql.ResultSet; -import java.sql.SQLException; -import java.util.Arrays; -import java.util.Collection; -import java.util.function.Consumer; - -import javax.sql.DataSource; - -import org.assertj.core.api.Assertions; -import org.junit.jupiter.api.Test; -import org.kie.flyway.utils.TestClassLoader; - -public abstract class AbstractKieFlywayInitializerTest { - - private static final Collection EXPECTED_MIGRATIONS; - - static final String MODULE_MIGRATIONS_QUERY = "select \"version\", \"description\", \"success\" from \"kie_flyway_history_test\""; - static final String TEST_TABLE_QUERY = "select id, message, dbtype from test_table"; - - static { - EXPECTED_MIGRATIONS = Arrays.asList( - new KieFlywayMigration("1.0.0", "Create table"), - new KieFlywayMigration("1.0.1", "Alter table"), - new KieFlywayMigration("1.0.2", "Insert data")); - } - - protected boolean skipFirstMigrationValidation() { - return false; - } - - protected abstract DataSource getDataSource(); - - protected abstract String getDbType(); - - @Test - public void testTestKieFlywayInitializerBuilderValidations() { - Assertions.assertThatThrownBy(() -> KieFlywayInitializer.builder() - .withDbType(getDbType()) - .build()).isInstanceOf(KieFlywayException.class) - .hasMessage("Cannot create KieFlywayInitializer migration, dataSource is null."); - - Assertions.assertThatThrownBy(() -> KieFlywayInitializer.builder() - .withDatasource(getDataSource()) - .build()).isInstanceOf(KieFlywayException.class) - .hasMessage("Cannot create KieFlywayInitializer migration, database type is null."); - } - - @Test - public void testKieFlywayInitializerValidations() { - TestClassLoader classLoader = new TestClassLoader(this.getClass().getClassLoader()); - classLoader.addModuleConfig(classLoader.getResource("initializers/kie-flyway.duplicated1.properties")); - classLoader.addModuleConfig(classLoader.getResource("initializers/kie-flyway.duplicated1.properties")); - classLoader.addModuleConfig(classLoader.getResource("initializers/kie-flyway.duplicated2.properties")); - classLoader.addModuleConfig(classLoader.getResource("initializers/kie-flyway.duplicated2.properties")); - - Assertions.assertThatThrownBy(() -> { - KieFlywayInitializer.builder() - .withDbType(getDbType()) - .withDatasource(getDataSource()) - .withClassLoader(classLoader) - .build() - .migrate(); - }).isInstanceOf(KieFlywayException.class) - .hasMessage("Cannot run Kie Flyway migration: Duplicated Modules found test-duplicated-1, test-duplicated-2"); - - } - - @Test - public void testFlywayMigrations() { - KieFlywayInitializer.builder() - .withDbType(getDbType()) - .withDatasource(getDataSource()) - .build() - .migrate(); - - validateDBData(MODULE_MIGRATIONS_QUERY, this::validateFlywayMigrationsTable); - validateDBData(TEST_TABLE_QUERY, this::validateTestTable); - } - - private void validateFlywayMigrationsTable(ResultSet rs) { - try { - if (skipFirstMigrationValidation()) { - Assertions.assertThat(rs.next()) - .isTrue(); - - } - for (KieFlywayMigration migration : EXPECTED_MIGRATIONS) { - Assertions.assertThat(rs.next()) - .isTrue(); - Assertions.assertThat(rs.getString("version")) - .isEqualTo(migration.version()); - Assertions.assertThat(rs.getString("description")) - .isEqualTo(migration.description()); - Assertions.assertThat(rs.getBoolean("success")) - .isEqualTo(true); - } - } catch (SQLException e) { - throw new RuntimeException(e); - } - } - - private void validateTestTable(ResultSet rs) { - try { - Assertions.assertThat(rs.next()) - .isTrue(); - - Assertions.assertThat(rs.getInt("id")) - .isEqualTo(1); - - Assertions.assertThat(rs.getString("message")) - .isEqualTo("Hello from Kie Flyway"); - - Assertions.assertThat(rs.getString("dbtype")) - .isEqualTo(getDbType()); - } catch (Exception ex) { - throw new RuntimeException(ex); - } - } - - public void validateDBData(String query, Consumer validator) { - try (Connection con = getDataSource().getConnection(); - PreparedStatement stmt = con.prepareStatement(query); - ResultSet rs = stmt.executeQuery()) { - validator.accept(rs); - } catch (Exception ex) { - throw new RuntimeException(ex); - } - } - - private record KieFlywayMigration(String version, String description) { - } -} diff --git a/addons/common/flyway/src/test/java/org/kie/flyway/KieFlywayInitializerTest.java b/addons/common/flyway/src/test/java/org/kie/flyway/KieFlywayInitializerTest.java new file mode 100644 index 00000000000..c697571e0af --- /dev/null +++ b/addons/common/flyway/src/test/java/org/kie/flyway/KieFlywayInitializerTest.java @@ -0,0 +1,281 @@ +/* + * 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; + +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.util.*; +import java.util.stream.Stream; + +import org.assertj.core.api.Assertions; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Order; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.Arguments; +import org.junit.jupiter.params.provider.MethodSource; +import org.kie.flyway.test.dataSources.H2TestDataSource; +import org.kie.flyway.test.dataSources.PostgreSQLTestDataSource; +import org.kie.flyway.test.dataSources.TestDataSource; +import org.kie.flyway.test.models.Customer; +import org.kie.flyway.test.models.Guitar; +import org.kie.flyway.test.models.KieFlywayMigration; +import org.kie.flyway.test.utils.TestClassLoader; +import org.kie.kogito.testcontainers.KogitoPostgreSqlContainer; +import org.testcontainers.junit.jupiter.Container; +import org.testcontainers.junit.jupiter.Testcontainers; + +@Testcontainers +public class KieFlywayInitializerTest { + + static final String MODULE_MIGRATIONS_QUERY_TEMPLATE = "select \"version\", \"description\", \"success\" from \"kie_flyway_history_%s\" where \"version\" = ?"; + static final String QUERY_CUSTOMERS_DATA = "select id, name, last_name, email from customers order by id"; + static final String QUERY_GUITARS_DATA = "select id, brand, model, rating from guitars order by id"; + static final String QUERY_QUERY_TABLE_EXISTS = "select count(*) as count from information_schema.tables where table_name = ?"; + + private static final Collection EXPECTED_CUSTOMERS_MIGRATIONS; + private static final Collection EXPECTED_CUSTOMERS; + private static final Collection EXPECTED_GUITARS_MIGRATIONS; + private static final Collection EXPECTED_GUITARS; + + @Container + private static final KogitoPostgreSqlContainer PG_CONTAINER = new KogitoPostgreSqlContainer(); + + private static Collection TEST_DATASOURCES; + + private TestClassLoader classLoader; + + static { + 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")); + + 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")); + + 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")); + + 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)); + } + + @BeforeAll + public static void start() { + PG_CONTAINER.start(); + TEST_DATASOURCES = List.of(new PostgreSQLTestDataSource(PG_CONTAINER), new H2TestDataSource("h2"), new H2TestDataSource("ansi")); + } + + public static Stream getDataSources() { + return TEST_DATASOURCES.stream() + .map(Arguments::of); + } + + @BeforeEach + public void init() { + classLoader = new TestClassLoader(this.getClass().getClassLoader()); + } + + @ParameterizedTest + @MethodSource("getDataSources") + public void testTestKieFlywayInitializerBuilderValidations(TestDataSource dataSource) { + Assertions.assertThatThrownBy(() -> KieFlywayInitializer.builder() + .withDbType(dataSource.getDbType()) + .build()).isInstanceOf(KieFlywayException.class) + .hasMessage("Cannot create KieFlywayInitializer migration, dataSource is null."); + + Assertions.assertThatThrownBy(() -> KieFlywayInitializer.builder() + .withDatasource(dataSource.getDataSource()) + .build()).isInstanceOf(KieFlywayException.class) + .hasMessage("Cannot create KieFlywayInitializer migration, database type is null."); + } + + @ParameterizedTest + @MethodSource("getDataSources") + public void testKieFlywayInitializerValidations(TestDataSource dataSource) { + classLoader.addKieFlywayModule(classLoader.getResource("initializers/kie-flyway.duplicated1.properties")); + classLoader.addKieFlywayModule(classLoader.getResource("initializers/kie-flyway.duplicated1.properties")); + classLoader.addKieFlywayModule(classLoader.getResource("initializers/kie-flyway.duplicated2.properties")); + classLoader.addKieFlywayModule(classLoader.getResource("initializers/kie-flyway.duplicated2.properties")); + + Assertions.assertThatThrownBy(() -> { + KieFlywayInitializer.builder() + .withDbType(dataSource.getDbType()) + .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 testFlywayMigrations(TestDataSource dataSource) { + + classLoader.addKieFlywayModule(classLoader.getResource("initializers/kie-flyway.customers.properties")); + classLoader.addKieFlywayModule(classLoader.getResource("initializers/kie-flyway.guitars.properties")); + + KieFlywayInitializer.builder() + .withDbType(dataSource.getDbType()) + .withDatasource(dataSource.getDataSource()) + .withClassLoader(classLoader) + .withModuleExclusions(Arrays.asList("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); + } + + public 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); + } + } + + @Order(2) + @ParameterizedTest + @MethodSource("getDataSources") + public void testFlywayMigrationsUpgrade(TestDataSource dataSource) { + + classLoader.addKieFlywayModule(classLoader.getResource("initializers/kie-flyway.customers2.properties")); + classLoader.addKieFlywayModule(classLoader.getResource("initializers/kie-flyway.guitars2.properties")); + + KieFlywayInitializer.builder() + .withDbType(dataSource.getDbType()) + .withDatasource(dataSource.getDataSource()) + .withClassLoader(classLoader) + .withModuleExclusions(Arrays.asList("test-3")) + .build() + .migrate(); + + validateKieFlywayIndex("customers", EXPECTED_CUSTOMERS_MIGRATIONS, dataSource); + validateCustomersData(EXPECTED_CUSTOMERS, dataSource); + + validateKieFlywayIndex("guitars", EXPECTED_GUITARS_MIGRATIONS, dataSource); + validateGuitarsData(dataSource); + } + + public void validateKieFlywayIndex(String moduleName, Collection 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(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); + } + } + + private void validateCustomersData(Collection expectedCustomers, TestDataSource dataSource) { + try (Connection con = dataSource.getDataSource().getConnection(); + PreparedStatement stmt = con.prepareStatement(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); + } + } + + private void validateGuitarsData(TestDataSource dataSource) { + try (Connection con = dataSource.getDataSource().getConnection(); + PreparedStatement stmt = con.prepareStatement(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); + } + } + + @AfterAll + public static void shutdown() { + TEST_DATASOURCES.forEach(TestDataSource::shutDown); + } + +} diff --git a/addons/common/flyway/src/test/java/org/kie/flyway/impl/DefaultKieModuleFlywayConfigLoaderTest.java b/addons/common/flyway/src/test/java/org/kie/flyway/impl/DefaultKieModuleFlywayConfigLoaderTest.java index cb6542fff08..19a2b0f3aa3 100644 --- a/addons/common/flyway/src/test/java/org/kie/flyway/impl/DefaultKieModuleFlywayConfigLoaderTest.java +++ b/addons/common/flyway/src/test/java/org/kie/flyway/impl/DefaultKieModuleFlywayConfigLoaderTest.java @@ -27,13 +27,13 @@ import org.junit.jupiter.api.Test; import org.kie.flyway.KieFlywayException; import org.kie.flyway.model.KieFlywayModuleConfig; -import org.kie.flyway.utils.TestClassLoader; +import org.kie.flyway.test.utils.TestClassLoader; public class DefaultKieModuleFlywayConfigLoaderTest { - private static final String H2_LOCATIONS = "classpath:db/test/h2"; - private static final String PGSQL_LOCATIONS = "classpath:db/test/postgresql"; - private static final String DEFAULT_LOCATIONS = "classpath:db/test/ansi"; + 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; @@ -94,7 +94,7 @@ public void testWrongResourceFile() { } private void loadModuleConfig(String resource) { - this.testClassLoader.addModuleConfig(getResourceUrl(resource)); + this.testClassLoader.addKieFlywayModule(getResourceUrl(resource)); } private URL getResourceUrl(String resource) { diff --git a/addons/common/flyway/src/test/java/org/kie/flyway/AbstractH2KieFlywayKieFlywayMigrationInitializerTest.java b/addons/common/flyway/src/test/java/org/kie/flyway/test/dataSources/H2TestDataSource.java similarity index 59% rename from addons/common/flyway/src/test/java/org/kie/flyway/AbstractH2KieFlywayKieFlywayMigrationInitializerTest.java rename to addons/common/flyway/src/test/java/org/kie/flyway/test/dataSources/H2TestDataSource.java index 8dec2cc5d6b..15a74433ce6 100644 --- a/addons/common/flyway/src/test/java/org/kie/flyway/AbstractH2KieFlywayKieFlywayMigrationInitializerTest.java +++ b/addons/common/flyway/src/test/java/org/kie/flyway/test/dataSources/H2TestDataSource.java @@ -17,7 +17,7 @@ * under the License. */ -package org.kie.flyway; +package org.kie.flyway.test.dataSources; import java.sql.Connection; import java.sql.SQLException; @@ -26,40 +26,39 @@ import javax.sql.DataSource; import org.h2.jdbcx.JdbcDataSource; -import org.junit.jupiter.api.AfterAll; -import org.junit.jupiter.api.BeforeAll; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; -public abstract class AbstractH2KieFlywayKieFlywayMigrationInitializerTest extends AbstractKieFlywayInitializerTest { - private static JdbcDataSource dataSource; +public class H2TestDataSource implements TestDataSource { + private static final Logger LOGGER = LoggerFactory.getLogger(H2TestDataSource.class); - @BeforeAll - public static void start() { - try { - dataSource = new JdbcDataSource(); - dataSource.setURL("jdbc:h2:mem:test;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=true"); - dataSource.setUser("sa"); - dataSource.setPassword("sa"); - } catch (Exception e) { - throw new RuntimeException(e); - } - } + private String name; + private JdbcDataSource dataSource; - @AfterAll - public static void stop() { - try (Connection con = dataSource.getConnection(); Statement stmt = con.createStatement()) { - stmt.execute("SHUTDOWN"); - } catch (SQLException e) { - throw new RuntimeException(e); - } + public H2TestDataSource(String name) { + this.name = name; + dataSource = new JdbcDataSource(); + dataSource.setURL("jdbc:h2:mem:%s;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=true".formatted(name)); + dataSource.setUser("sa"); + dataSource.setPassword("sa"); } @Override - protected boolean skipFirstMigrationValidation() { - return true; + public String getDbType() { + return name; } @Override - protected DataSource getDataSource() { + 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/flyway/src/test/java/org/kie/flyway/PostgreSQLKieFlywayInitializerTest.java b/addons/common/flyway/src/test/java/org/kie/flyway/test/dataSources/PostgreSQLTestDataSource.java similarity index 53% rename from addons/common/flyway/src/test/java/org/kie/flyway/PostgreSQLKieFlywayInitializerTest.java rename to addons/common/flyway/src/test/java/org/kie/flyway/test/dataSources/PostgreSQLTestDataSource.java index 6d3c95748ce..dc909d0fa54 100644 --- a/addons/common/flyway/src/test/java/org/kie/flyway/PostgreSQLKieFlywayInitializerTest.java +++ b/addons/common/flyway/src/test/java/org/kie/flyway/test/dataSources/PostgreSQLTestDataSource.java @@ -17,36 +17,31 @@ * under the License. */ -package org.kie.flyway; +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 PostgreSQLKieFlywayInitializerTest extends AbstractKieFlywayInitializerTest { - - @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()); - } - protected DataSource getDataSource() { - return PostgreSQLKieFlywayInitializerTest.PG_DATA_SOURCE; +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()); } - protected String getDbType() { + @Override + public String getDbType() { return "postgresql"; } + + @Override + public DataSource getDataSource() { + return dataSource; + } } diff --git a/addons/common/flyway/src/test/java/org/kie/flyway/H2KieFlywayKieFlywayMigrationInitializerTest.java b/addons/common/flyway/src/test/java/org/kie/flyway/test/dataSources/TestDataSource.java similarity index 79% rename from addons/common/flyway/src/test/java/org/kie/flyway/H2KieFlywayKieFlywayMigrationInitializerTest.java rename to addons/common/flyway/src/test/java/org/kie/flyway/test/dataSources/TestDataSource.java index 69495db451a..0a0ecc6974c 100644 --- a/addons/common/flyway/src/test/java/org/kie/flyway/H2KieFlywayKieFlywayMigrationInitializerTest.java +++ b/addons/common/flyway/src/test/java/org/kie/flyway/test/dataSources/TestDataSource.java @@ -17,12 +17,17 @@ * under the License. */ -package org.kie.flyway; +package org.kie.flyway.test.dataSources; -public class H2KieFlywayKieFlywayMigrationInitializerTest extends AbstractH2KieFlywayKieFlywayMigrationInitializerTest { +import javax.sql.DataSource; + +public interface TestDataSource { + + String getDbType(); + + DataSource getDataSource(); + + default void shutDown() { - @Override - protected String getDbType() { - return "H2"; } } 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 00000000000..607a7084a82 --- /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 00000000000..f914b011938 --- /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 00000000000..7df23f76a50 --- /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/utils/TestClassLoader.java b/addons/common/flyway/src/test/java/org/kie/flyway/test/utils/TestClassLoader.java similarity index 76% rename from addons/common/flyway/src/test/java/org/kie/flyway/utils/TestClassLoader.java rename to addons/common/flyway/src/test/java/org/kie/flyway/test/utils/TestClassLoader.java index 7899931049d..92cb4d05cd8 100644 --- a/addons/common/flyway/src/test/java/org/kie/flyway/utils/TestClassLoader.java +++ b/addons/common/flyway/src/test/java/org/kie/flyway/test/utils/TestClassLoader.java @@ -17,7 +17,7 @@ * under the License. */ -package org.kie.flyway.utils; +package org.kie.flyway.test.utils; import java.net.URL; import java.util.ArrayList; @@ -27,24 +27,24 @@ import org.kie.flyway.impl.DefaultKieModuleFlywayConfigLoader; public class TestClassLoader extends ClassLoader { - private final List moduleConfigs = new ArrayList<>(); + private final List modules = new ArrayList<>(); public TestClassLoader(ClassLoader parent) { super(parent); } - public void addModuleConfig(URL resourceUrl) { - this.moduleConfigs.add(resourceUrl); + public void addKieFlywayModule(URL resourceUrl) { + this.modules.add(resourceUrl); } public void clearModuleConfigs() { - this.moduleConfigs.clear(); + this.modules.clear(); } @Override public Stream resources(String name) { - if (!moduleConfigs.isEmpty() && DefaultKieModuleFlywayConfigLoader.KIE_FLYWAY_DESCRIPTOR_FILE_LOCATION.equals(name)) { - return moduleConfigs.stream(); + if (!modules.isEmpty() && DefaultKieModuleFlywayConfigLoader.KIE_FLYWAY_DESCRIPTOR_FILE_LOCATION.equals(name)) { + return modules.stream(); } return super.resources(name); } diff --git a/addons/common/flyway/src/test/resources/META-INF/kie-flyway.properties b/addons/common/flyway/src/test/resources/META-INF/kie-flyway.properties index ea6c2a2379f..a4f89f2416d 100644 --- a/addons/common/flyway/src/test/resources/META-INF/kie-flyway.properties +++ b/addons/common/flyway/src/test/resources/META-INF/kie-flyway.properties @@ -19,6 +19,6 @@ module.name=test -module.locations.h2=classpath:db/test/h2 -module.locations.postgresql=classpath:db/test/postgresql -module.locations.default=classpath:db/test/ansi \ No newline at end of file +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/addons/common/flyway/src/test/resources/initializers/kie-flyway.customers.properties b/addons/common/flyway/src/test/resources/initializers/kie-flyway.customers.properties new file mode 100644 index 00000000000..ad55f01d8e2 --- /dev/null +++ b/addons/common/flyway/src/test/resources/initializers/kie-flyway.customers.properties @@ -0,0 +1,24 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# + +module.name=customers + +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/addons/common/flyway/src/test/resources/initializers/kie-flyway.customers2.properties b/addons/common/flyway/src/test/resources/initializers/kie-flyway.customers2.properties new file mode 100644 index 00000000000..11cc64b3c89 --- /dev/null +++ b/addons/common/flyway/src/test/resources/initializers/kie-flyway.customers2.properties @@ -0,0 +1,24 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# + +module.name=customers + +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/addons/common/flyway/src/test/resources/initializers/kie-flyway.duplicated1.properties b/addons/common/flyway/src/test/resources/initializers/kie-flyway.duplicated1.properties index 48b53e3e5ef..c5b21d77a5e 100644 --- a/addons/common/flyway/src/test/resources/initializers/kie-flyway.duplicated1.properties +++ b/addons/common/flyway/src/test/resources/initializers/kie-flyway.duplicated1.properties @@ -19,6 +19,6 @@ module.name=test-duplicated-1 -module.locations.h2=classpath:db/test/h2 -module.locations.postgresql=classpath:db/test/postgresql -module.locations.default=classpath:db/test/ansi \ No newline at end of file +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/addons/common/flyway/src/test/resources/initializers/kie-flyway.duplicated2.properties b/addons/common/flyway/src/test/resources/initializers/kie-flyway.duplicated2.properties index af8939b9c37..7ca37ee74f0 100644 --- a/addons/common/flyway/src/test/resources/initializers/kie-flyway.duplicated2.properties +++ b/addons/common/flyway/src/test/resources/initializers/kie-flyway.duplicated2.properties @@ -19,6 +19,6 @@ module.name=test-duplicated-2 -module.locations.h2=classpath:db/test/h2 -module.locations.postgresql=classpath:db/test/postgresql -module.locations.default=classpath:db/test/ansi \ No newline at end of file +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/addons/common/flyway/src/test/resources/initializers/kie-flyway.ok.properties b/addons/common/flyway/src/test/resources/initializers/kie-flyway.guitars.properties similarity index 79% rename from addons/common/flyway/src/test/resources/initializers/kie-flyway.ok.properties rename to addons/common/flyway/src/test/resources/initializers/kie-flyway.guitars.properties index ea6c2a2379f..3663d80f6ee 100644 --- a/addons/common/flyway/src/test/resources/initializers/kie-flyway.ok.properties +++ b/addons/common/flyway/src/test/resources/initializers/kie-flyway.guitars.properties @@ -17,8 +17,8 @@ # under the License. # -module.name=test +module.name=guitars -module.locations.h2=classpath:db/test/h2 -module.locations.postgresql=classpath:db/test/postgresql -module.locations.default=classpath:db/test/ansi \ No newline at end of file +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/addons/common/flyway/src/test/resources/initializers/kie-flyway.guitars2.properties b/addons/common/flyway/src/test/resources/initializers/kie-flyway.guitars2.properties new file mode 100644 index 00000000000..3663d80f6ee --- /dev/null +++ b/addons/common/flyway/src/test/resources/initializers/kie-flyway.guitars2.properties @@ -0,0 +1,24 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# + +module.name=guitars + +module.locations.h2=classpath:kie-flyway/db/guitars/h2 +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/addons/common/flyway/src/test/java/org/kie/flyway/FallbackKieFlywayKieFlywayMigrationInitializerTest.java b/addons/common/flyway/src/test/resources/kie-flyway/db/customers-2/ansi/V1.0.5__Insert_game_characters_ansi.sql similarity index 77% rename from addons/common/flyway/src/test/java/org/kie/flyway/FallbackKieFlywayKieFlywayMigrationInitializerTest.java rename to addons/common/flyway/src/test/resources/kie-flyway/db/customers-2/ansi/V1.0.5__Insert_game_characters_ansi.sql index fd2b672a300..fdc120933e0 100644 --- a/addons/common/flyway/src/test/java/org/kie/flyway/FallbackKieFlywayKieFlywayMigrationInitializerTest.java +++ b/addons/common/flyway/src/test/resources/kie-flyway/db/customers-2/ansi/V1.0.5__Insert_game_characters_ansi.sql @@ -17,12 +17,5 @@ * under the License. */ -package org.kie.flyway; - -public class FallbackKieFlywayKieFlywayMigrationInitializerTest extends H2KieFlywayKieFlywayMigrationInitializerTest { - - @Override - protected String getDbType() { - return "ansi"; - } -} +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 00000000000..fdc120933e0 --- /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 00000000000..fdc120933e0 --- /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 00000000000..9783fb1f16c --- /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 00000000000..bda9e5e58bb --- /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 00000000000..6702a0c4c01 --- /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 00000000000..9783fb1f16c --- /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 00000000000..bda9e5e58bb --- /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 00000000000..6702a0c4c01 --- /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 00000000000..9783fb1f16c --- /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 00000000000..bda9e5e58bb --- /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 00000000000..6702a0c4c01 --- /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 00000000000..dbbc6788e06 --- /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 00000000000..e7b1e28c61a --- /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 00000000000..38ca843c4fd --- /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 00000000000..b96b93d98b5 --- /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 00000000000..3a4ce512576 --- /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 00000000000..e7b1e28c61a --- /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 00000000000..38ca843c4fd --- /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 00000000000..b96b93d98b5 --- /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 00000000000..3a4ce512576 --- /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 00000000000..e7b1e28c61a --- /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 00000000000..38ca843c4fd --- /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 00000000000..b96b93d98b5 --- /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/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 similarity index 100% rename from addons/common/flyway/src/test/resources/db/test/ansi/V1.0.0__Create_table.sql rename to addons/common/flyway/src/test/resources/kie-flyway/db/test/ansi/V1.0.0__Create_table.sql diff --git a/addons/common/flyway/src/test/resources/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 similarity index 100% rename from addons/common/flyway/src/test/resources/db/test/ansi/V1.0.1__Alter_table.sql rename to addons/common/flyway/src/test/resources/kie-flyway/db/test/ansi/V1.0.1__Alter_table.sql diff --git a/addons/common/flyway/src/test/resources/db/test/h2/V1.0.2__Insert_data.sql b/addons/common/flyway/src/test/resources/kie-flyway/db/test/ansi/V1.0.2__Insert_data.sql similarity index 94% rename from addons/common/flyway/src/test/resources/db/test/h2/V1.0.2__Insert_data.sql rename to addons/common/flyway/src/test/resources/kie-flyway/db/test/ansi/V1.0.2__Insert_data.sql index fee80a419f8..de9448fc686 100644 --- a/addons/common/flyway/src/test/resources/db/test/h2/V1.0.2__Insert_data.sql +++ b/addons/common/flyway/src/test/resources/kie-flyway/db/test/ansi/V1.0.2__Insert_data.sql @@ -18,4 +18,4 @@ */ insert into test_table (id, message, dbtype) -values (1, 'Hello from Kie Flyway', 'H2'); \ No newline at end of file +values (1, 'Hello from Kie Flyway - test', 'ansi'); \ No newline at end of file diff --git a/addons/common/flyway/src/test/resources/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 similarity index 100% rename from addons/common/flyway/src/test/resources/db/test/h2/V1.0.0__Create_table.sql rename to addons/common/flyway/src/test/resources/kie-flyway/db/test/h2/V1.0.0__Create_table.sql diff --git a/addons/common/flyway/src/test/resources/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 similarity index 100% rename from addons/common/flyway/src/test/resources/db/test/h2/V1.0.1__Alter_table.sql rename to addons/common/flyway/src/test/resources/kie-flyway/db/test/h2/V1.0.1__Alter_table.sql diff --git a/addons/common/flyway/src/test/resources/db/test/ansi/V1.0.2__Insert_data.sql b/addons/common/flyway/src/test/resources/kie-flyway/db/test/h2/V1.0.2__Insert_data.sql similarity index 94% rename from addons/common/flyway/src/test/resources/db/test/ansi/V1.0.2__Insert_data.sql rename to addons/common/flyway/src/test/resources/kie-flyway/db/test/h2/V1.0.2__Insert_data.sql index 672b131eab5..8c169053040 100644 --- a/addons/common/flyway/src/test/resources/db/test/ansi/V1.0.2__Insert_data.sql +++ b/addons/common/flyway/src/test/resources/kie-flyway/db/test/h2/V1.0.2__Insert_data.sql @@ -18,4 +18,4 @@ */ insert into test_table (id, message, dbtype) -values (1, 'Hello from Kie Flyway', 'ansi'); \ No newline at end of file +values (1, 'Hello from Kie Flyway - test', 'H2'); \ No newline at end of file diff --git a/addons/common/flyway/src/test/resources/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 similarity index 100% rename from addons/common/flyway/src/test/resources/db/test/postgresql/V1.0.0__Create_table.sql rename to addons/common/flyway/src/test/resources/kie-flyway/db/test/postgresql/V1.0.0__Create_table.sql diff --git a/addons/common/flyway/src/test/resources/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 similarity index 100% rename from addons/common/flyway/src/test/resources/db/test/postgresql/V1.0.1__Alter_table.sql rename to addons/common/flyway/src/test/resources/kie-flyway/db/test/postgresql/V1.0.1__Alter_table.sql diff --git a/addons/common/flyway/src/test/resources/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 similarity index 93% rename from addons/common/flyway/src/test/resources/db/test/postgresql/V1.0.2__Insert_data.sql rename to addons/common/flyway/src/test/resources/kie-flyway/db/test/postgresql/V1.0.2__Insert_data.sql index ceac1ef8206..258edf6a7f6 100644 --- a/addons/common/flyway/src/test/resources/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 @@ -18,4 +18,4 @@ */ insert into test_table (id, message, dbtype) -values (1, 'Hello from Kie Flyway', 'postgresql'); \ No newline at end of file +values (1, 'Hello from Kie Flyway - test', 'postgresql'); \ No newline at end of file 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 2c284e60746..b631bf23c72 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.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 KogitoPostgreSqlContainer() { 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 getLogger() {