Skip to content

Commit

Permalink
Merge pull request #6 from MEITREX/docker
Browse files Browse the repository at this point in the history
Update docker compose to use unified db container
  • Loading branch information
v-morlock authored Sep 13, 2024
2 parents 5681052 + 2a86b9f commit afc63f7
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions pg-init-scripts/create-multiple-databases.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/bin/bash

# Script taken with modifications from https://dev.to/bgord/multiple-postgres-databases-in-a-single-docker-container-417l

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 DATABASE "$database";
GRANT ALL PRIVILEGES ON DATABASE "$database" TO "$POSTGRES_USER";
EOSQL
}

for var in $(env | grep '^POSTGRES_CREATE_DB_' | awk -F '=' '{print $2}'); do
echo "Creating database: $var"
create_user_and_database $var
done

0 comments on commit afc63f7

Please sign in to comment.