Skip to content

Commit

Permalink
ci: add init database rule #71
Browse files Browse the repository at this point in the history
  • Loading branch information
GenjiruSUchiwa committed Nov 25, 2024
1 parent cec3dab commit 207e3bb
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions init-multiple-databases.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/bin/bash

set -e
set -u

function create_database() {
local database=$1
echo "Creating 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
}

if [ -n "$POSTGRES_MULTIPLE_DATABASES" ]; then
echo "Multiple database creation requested: $POSTGRES_MULTIPLE_DATABASES"
for db in $(echo $POSTGRES_MULTIPLE_DATABASES | tr ',' ' '); do
create_database $db
done
echo "Multiple databases created"
fi

0 comments on commit 207e3bb

Please sign in to comment.