Module
PostgreSQL
Proposal
new PostgreSQLContainer<>("postgres").withInitScript("init.sql");
init.sql
CREATE DATABASE example;
\c example
CREATE SCHEMA example;
does not work because the Postgres JDBC driver does not support the \c psql meta-command to switch databases.
This is similar to #7680 and its predecessors #2578, #1997, and #2232.
But in this use case one would would need to specify the database in addition to the init script path.
Something along the lines of:
new PostgreSQLContainer<>("postgres")
.withInitScript("createDatabase.sql") // CREATE DATABASE example;
.withInitScriptForDatabase("example", "createSchema.sql"); // CREATE SCHEMA example;
new PostgreSQLContainer<>("postgres")
.withInitScript("createDatabases.sql") // CREATE DATABASE example1; CREATE DATABASE example2;
.withInitScriptForDatabase("example1", "createExample1Schema.sql"); // CREATE SCHEMA example1;
.withInitScriptForDatabase("example2", "createExample2Schema.sql"); // CREATE SCHEMA example2;
Note:
new PostgreSQLContainer<>("postgres")
.withDatabaseName("example")
...;
will auto-create the example database but the DDL above would be in reality more complex like:
CREATE DATABASE example WITH OWNER example_admin TEMPLATE template0
ENCODING UTF8 LC_COLLATE 'de_DE.UTF8' LC_CTYPE 'de_DE.UTF8';
Module
PostgreSQL
Proposal
init.sql
does not work because the Postgres JDBC driver does not support the
\cpsql meta-command to switch databases.This is similar to #7680 and its predecessors #2578, #1997, and #2232.
But in this use case one would would need to specify the database in addition to the init script path.
Something along the lines of:
Note:
will auto-create the
exampledatabase but the DDL above would be in reality more complex like: