testcontainers / testcontainers/testcontainers-java

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

オープン
#8,634 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

type/enhancement
主要言語
Java
スター
8.7k
フォーク
1.9k
平均マージ
2日 17時間
マージ済み PR(30日)
9

説明

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';

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

まず、PostgreSQL コンテナの既存の init-script の動作と、関連する issue #7680、#2578、#1997、#2232 を確認します。JDBC ドライバーが psql メタコマンドをサポートしていない状況で、スクリプトが名前付きデータベースを対象にする方法を定義します。提案された API でデータベースを作成し、各スキーマスクリプトを指定されたデータベースに対して実行できれば完了です。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
java, postgresql
領域
databases
issue の種類
機能追加
難易度
5/5
見積もり時間
1週間以上
活発さ
停滞
明瞭さ
おおむね明確
初心者へのやさしさ
30/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。