Skip to content

Add withInitScripts to the SQL database modules #1574

Open

Description

@cristianrgreco

What happens

None of the SQL database modules has a way to run a schema or seed script at startup. Their builder methods are limited to credentials and the database name:

Module Builder methods
postgresql withDatabase, withUsername, withPassword, withSSL, withSSLCert
mysql, mariadb withDatabase, withUsername, withUserPassword, withRootPassword
mssqlserver withDatabase, withPassword, withWaitForMessage
cockroachdb withDatabase, withUsername
clickhouse, oraclefree withDatabase, withUsername, withPassword

Users copy files into the image's init directory themselves, which means knowing that directory for each image:

new PostgreSqlContainer(image).withCopyFilesToContainer([
  { source: "./schema.sql", target: "/docker-entrypoint-initdb.d/schema.sql" },
]);

For images with no init directory (SQL Server), it means running the script with exec after start.

Expected

withInitScripts(...paths) on each SQL module, run in the order given, using the image's init directory where there is one and the database's CLI otherwise.

Where

packages/modules/{postgresql,mysql,mariadb,mssqlserver,cockroachdb,clickhouse,oraclefree}/src.

Notes

  • Java has withInitScript and withInitScripts on JdbcDatabaseContainer, shared by every JDBC module. Go has WithInitScripts and WithOrderedInitScripts on postgres and WithScripts on mysql.
  • Each module is an independent change.

Dependencies

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requestminorBackward compatible functionality

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions