Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Enhancement]: Support running init script against a specific database #8634

Open
sdavids opened this issue May 15, 2024 · 0 comments
Open

Comments

@sdavids
Copy link

sdavids commented May 15, 2024

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';
@sdavids sdavids changed the title [Enhancement]: Support running init script running against a specific database [Enhancement]: Support running init script against a specific database May 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant