diff --git a/extensions/datasource/deployment-spi/src/main/java/io/quarkus/datasource/deployment/spi/DevServicesDatasourceContainerConfig.java b/extensions/datasource/deployment-spi/src/main/java/io/quarkus/datasource/deployment/spi/DevServicesDatasourceContainerConfig.java index 517d0705f1c7e..73de517525ab5 100644 --- a/extensions/datasource/deployment-spi/src/main/java/io/quarkus/datasource/deployment/spi/DevServicesDatasourceContainerConfig.java +++ b/extensions/datasource/deployment-spi/src/main/java/io/quarkus/datasource/deployment/spi/DevServicesDatasourceContainerConfig.java @@ -1,5 +1,6 @@ package io.quarkus.datasource.deployment.spi; +import java.util.List; import java.util.Map; import java.util.Optional; import java.util.OptionalInt; @@ -15,7 +16,7 @@ public class DevServicesDatasourceContainerConfig { private final Optional dbName; private final Optional username; private final Optional password; - private final Optional initScriptPath; + private final Optional> initScriptPath; private final Map volumes; private final boolean reuse; private final boolean showLogs; @@ -29,7 +30,7 @@ public DevServicesDatasourceContainerConfig(Optional imageName, Optional dbName, Optional username, Optional password, - Optional initScriptPath, + Optional> initScriptPath, Map volumes, boolean reuse, boolean showLogs) { @@ -84,7 +85,7 @@ public Optional getPassword() { return password; } - public Optional getInitScriptPath() { + public Optional> getInitScriptPath() { return initScriptPath; } diff --git a/extensions/datasource/runtime/src/main/java/io/quarkus/datasource/runtime/DevServicesBuildTimeConfig.java b/extensions/datasource/runtime/src/main/java/io/quarkus/datasource/runtime/DevServicesBuildTimeConfig.java index 5feca1ed6458a..4881974629115 100644 --- a/extensions/datasource/runtime/src/main/java/io/quarkus/datasource/runtime/DevServicesBuildTimeConfig.java +++ b/extensions/datasource/runtime/src/main/java/io/quarkus/datasource/runtime/DevServicesBuildTimeConfig.java @@ -1,5 +1,6 @@ package io.quarkus.datasource.runtime; +import java.util.List; import java.util.Map; import java.util.Optional; import java.util.OptionalInt; @@ -83,11 +84,11 @@ public interface DevServicesBuildTimeConfig { Optional password(); /** - * The path to a SQL script to be loaded from the classpath and applied to the Dev Service database. + * The paths to SQL scripts to be loaded from the classpath and applied to the Dev Service database. *

* This has no effect if the provider is not a container-based database, such as H2 or Derby. */ - Optional initScriptPath(); + Optional> initScriptPath(); /** * The volumes to be mapped to the container. diff --git a/extensions/devservices/db2/src/main/java/io/quarkus/devservices/db2/deployment/DB2DevServicesProcessor.java b/extensions/devservices/db2/src/main/java/io/quarkus/devservices/db2/deployment/DB2DevServicesProcessor.java index 0330030b3409b..7262dfb9a3df1 100644 --- a/extensions/devservices/db2/src/main/java/io/quarkus/devservices/db2/deployment/DB2DevServicesProcessor.java +++ b/extensions/devservices/db2/src/main/java/io/quarkus/devservices/db2/deployment/DB2DevServicesProcessor.java @@ -65,7 +65,7 @@ public RunningDevServicesDatasource startDatabase(Optional username, Opt containerConfig.getAdditionalJdbcUrlProperties().forEach(container::withUrlParam); containerConfig.getCommand().ifPresent(container::setCommand); - containerConfig.getInitScriptPath().ifPresent(container::withInitScript); + containerConfig.getInitScriptPath().ifPresent(container::withInitScripts); if (containerConfig.isShowLogs()) { container.withLogConsumer(new JBossLoggingConsumer(LOG)); } diff --git a/extensions/devservices/mariadb/src/main/java/io/quarkus/devservices/mariadb/deployment/MariaDBDevServicesProcessor.java b/extensions/devservices/mariadb/src/main/java/io/quarkus/devservices/mariadb/deployment/MariaDBDevServicesProcessor.java index 9b6de31d6e854..d3431c24f0f9f 100644 --- a/extensions/devservices/mariadb/src/main/java/io/quarkus/devservices/mariadb/deployment/MariaDBDevServicesProcessor.java +++ b/extensions/devservices/mariadb/src/main/java/io/quarkus/devservices/mariadb/deployment/MariaDBDevServicesProcessor.java @@ -74,7 +74,7 @@ public RunningDevServicesDatasource startDatabase(Optional username, Opt containerConfig.getAdditionalJdbcUrlProperties().forEach(container::withUrlParam); containerConfig.getCommand().ifPresent(container::setCommand); - containerConfig.getInitScriptPath().ifPresent(container::withInitScript); + containerConfig.getInitScriptPath().ifPresent(container::withInitScripts); if (containerConfig.isShowLogs()) { container.withLogConsumer(new JBossLoggingConsumer(LOG)); } diff --git a/extensions/devservices/mssql/src/main/java/io/quarkus/devservices/mssql/deployment/MSSQLDevServicesProcessor.java b/extensions/devservices/mssql/src/main/java/io/quarkus/devservices/mssql/deployment/MSSQLDevServicesProcessor.java index 250b6ba760804..7ba2fd1be00cc 100644 --- a/extensions/devservices/mssql/src/main/java/io/quarkus/devservices/mssql/deployment/MSSQLDevServicesProcessor.java +++ b/extensions/devservices/mssql/src/main/java/io/quarkus/devservices/mssql/deployment/MSSQLDevServicesProcessor.java @@ -65,7 +65,7 @@ public RunningDevServicesDatasource startDatabase(Optional username, Opt containerConfig.getAdditionalJdbcUrlProperties().forEach(container::withUrlParam); containerConfig.getCommand().ifPresent(container::setCommand); - containerConfig.getInitScriptPath().ifPresent(container::withInitScript); + containerConfig.getInitScriptPath().ifPresent(container::withInitScripts); if (containerConfig.isShowLogs()) { container.withLogConsumer(new JBossLoggingConsumer(LOG)); } diff --git a/extensions/devservices/mysql/src/main/java/io/quarkus/devservices/mysql/deployment/MySQLDevServicesProcessor.java b/extensions/devservices/mysql/src/main/java/io/quarkus/devservices/mysql/deployment/MySQLDevServicesProcessor.java index 733e43237b6bc..abd4bae7a622c 100644 --- a/extensions/devservices/mysql/src/main/java/io/quarkus/devservices/mysql/deployment/MySQLDevServicesProcessor.java +++ b/extensions/devservices/mysql/src/main/java/io/quarkus/devservices/mysql/deployment/MySQLDevServicesProcessor.java @@ -73,7 +73,7 @@ public RunningDevServicesDatasource startDatabase(Optional username, Opt containerConfig.getAdditionalJdbcUrlProperties().forEach(container::withUrlParam); containerConfig.getCommand().ifPresent(container::setCommand); - containerConfig.getInitScriptPath().ifPresent(container::withInitScript); + containerConfig.getInitScriptPath().ifPresent(container::withInitScripts); if (containerConfig.isShowLogs()) { container.withLogConsumer(new JBossLoggingConsumer(LOG)); } diff --git a/extensions/devservices/oracle/src/main/java/io/quarkus/devservices/oracle/deployment/OracleDevServicesProcessor.java b/extensions/devservices/oracle/src/main/java/io/quarkus/devservices/oracle/deployment/OracleDevServicesProcessor.java index 66ce14aea106b..bf5cdaee96e77 100644 --- a/extensions/devservices/oracle/src/main/java/io/quarkus/devservices/oracle/deployment/OracleDevServicesProcessor.java +++ b/extensions/devservices/oracle/src/main/java/io/quarkus/devservices/oracle/deployment/OracleDevServicesProcessor.java @@ -79,7 +79,7 @@ public RunningDevServicesDatasource startDatabase(Optional username, Opt containerConfig.getAdditionalJdbcUrlProperties().forEach(container::withUrlParam); containerConfig.getCommand().ifPresent(container::setCommand); - containerConfig.getInitScriptPath().ifPresent(container::withInitScript); + containerConfig.getInitScriptPath().ifPresent(container::withInitScripts); if (containerConfig.isShowLogs()) { container.withLogConsumer(new JBossLoggingConsumer(LOG)); } diff --git a/extensions/devservices/postgresql/src/main/java/io/quarkus/devservices/postgresql/deployment/PostgresqlDevServicesProcessor.java b/extensions/devservices/postgresql/src/main/java/io/quarkus/devservices/postgresql/deployment/PostgresqlDevServicesProcessor.java index ce05c7cc65552..59e27f1aefdcf 100644 --- a/extensions/devservices/postgresql/src/main/java/io/quarkus/devservices/postgresql/deployment/PostgresqlDevServicesProcessor.java +++ b/extensions/devservices/postgresql/src/main/java/io/quarkus/devservices/postgresql/deployment/PostgresqlDevServicesProcessor.java @@ -88,7 +88,7 @@ public RunningDevServicesDatasource startDatabase(Optional username, Opt } container.setCommand(augmentedCommand); - containerConfig.getInitScriptPath().ifPresent(container::withInitScript); + containerConfig.getInitScriptPath().ifPresent(container::withInitScripts); if (containerConfig.isShowLogs()) { container.withLogConsumer(new JBossLoggingConsumer(LOG)); } diff --git a/extensions/jdbc/jdbc-postgresql/deployment/src/test/java/io/quarkus/jdbc/postgresql/deployment/DevServicesPostgresqlDatasourceWithMultipleInitScriptsTestCase.java b/extensions/jdbc/jdbc-postgresql/deployment/src/test/java/io/quarkus/jdbc/postgresql/deployment/DevServicesPostgresqlDatasourceWithMultipleInitScriptsTestCase.java new file mode 100644 index 0000000000000..753d851a0c24c --- /dev/null +++ b/extensions/jdbc/jdbc-postgresql/deployment/src/test/java/io/quarkus/jdbc/postgresql/deployment/DevServicesPostgresqlDatasourceWithMultipleInitScriptsTestCase.java @@ -0,0 +1,52 @@ +package io.quarkus.jdbc.postgresql.deployment; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +import java.sql.CallableStatement; +import java.sql.Connection; +import java.sql.ResultSet; + +import javax.sql.DataSource; + +import jakarta.inject.Inject; + +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.RegisterExtension; + +import io.quarkus.test.QuarkusUnitTest; + +public class DevServicesPostgresqlDatasourceWithMultipleInitScriptsTestCase { + + @RegisterExtension + static QuarkusUnitTest test = new QuarkusUnitTest() + .withApplicationRoot(javaArchive -> javaArchive.addAsResource("init-db.sql")) + .withApplicationRoot(javaArchive -> javaArchive.addAsResource("init-db-2.sql")) + .overrideConfigKey("quarkus.datasource.db-kind", "postgresql") + .overrideConfigKey("quarkus.datasource.devservices.init-script-path", "init-db.sql, init-db-2.sql"); + + @Inject + DataSource ds; + + @Test + @DisplayName("Test if init-script-path executed successfully") + public void testDatasource() throws Exception { + int result = 0; + try (Connection con = ds.getConnection(); + CallableStatement cs = con.prepareCall("SELECT my_func()"); + ResultSet rs = cs.executeQuery()) { + if (rs.next()) { + result = rs.getInt(1); + } + } + assertEquals(100, result, "The first init script should have been executed"); + try (Connection con = ds.getConnection(); + CallableStatement cs = con.prepareCall("SELECT my_func_2()"); + ResultSet rs = cs.executeQuery()) { + if (rs.next()) { + result = rs.getInt(1); + } + } + assertEquals(200, result, "The second init script should have been executed"); + } +} diff --git a/extensions/jdbc/jdbc-postgresql/deployment/src/test/resources/init-db-2.sql b/extensions/jdbc/jdbc-postgresql/deployment/src/test/resources/init-db-2.sql new file mode 100644 index 0000000000000..8bb245443fcf4 --- /dev/null +++ b/extensions/jdbc/jdbc-postgresql/deployment/src/test/resources/init-db-2.sql @@ -0,0 +1 @@ +CREATE OR REPLACE FUNCTION my_func_2() RETURNS integer LANGUAGE plpgsql as $func$ BEGIN return 200; END $func$; \ No newline at end of file