diff --git a/docker-compose.yml b/docker-compose.yml index 2ca25d45f4..54aa0370d7 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -7,9 +7,12 @@ services: - "5421:5432" volumes: - ./pgdata:/var/lib/postgresql/data + - ./scripts/docker-entrypoint-initdb.d:/docker-entrypoint-initdb.d:ro container_name: oodi_db environment: - POSTGRES_DB: tkt_oodi + - POSTGRES_MULTIPLE_DATABASES=tkt_oodi,tkt_oodi_test + - POSTGRES_USER=postgres + - POSTGRES_PASSWORD= redis: image: redis command: ["redis-server", "--appendonly", "yes"] @@ -72,4 +75,4 @@ services: environment: - ENV=development - MONGO_URI=mongodb://mongo_db:27017/oodilearn - container_name: oodilearn \ No newline at end of file + container_name: oodilearn diff --git a/scripts/docker-entrypoint-initdb.d/create-multiple-postgresql-databases.sh b/scripts/docker-entrypoint-initdb.d/create-multiple-postgresql-databases.sh new file mode 100644 index 0000000000..aa665fa46c --- /dev/null +++ b/scripts/docker-entrypoint-initdb.d/create-multiple-postgresql-databases.sh @@ -0,0 +1,22 @@ +#!/bin/bash + +set -e +set -u + +function create_user_and_database() { + local database=$1 + echo " Creating user and database '$database'" + psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" <<-EOSQL + CREATE USER $database; + CREATE DATABASE $database; + GRANT ALL PRIVILEGES ON DATABASE $database TO $database; +EOSQL +} + +if [ -n "$POSTGRES_MULTIPLE_DATABASES" ]; then + echo "Multiple database creation requested: $POSTGRES_MULTIPLE_DATABASES" + for db in $(echo $POSTGRES_MULTIPLE_DATABASES | tr ',' ' '); do + create_user_and_database $db + done + echo "Multiple databases created" +fi