Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add support for POSTGRES_USER and POSTGRES_PASSWORD envs #15

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions create-multiple-postgresql-databases.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,26 @@
set -e
set -u

function create_user_and_database() {
function create_databases() {
local database=$1
local user=$2

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

if [ -n "$POSTGRES_MULTIPLE_DATABASES" ]; then
# echo "User $POSTGRES_USER creation..."
# psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" <<-EOSQL
# CREATE USER $POSTGRES_USER WITH ENCRYPTED PASSWORD $POSTGRES_PASSWORD;
#EOSQL

echo "Multiple database creation requested: $POSTGRES_MULTIPLE_DATABASES"
for db in $(echo $POSTGRES_MULTIPLE_DATABASES | tr ',' ' '); do
create_user_and_database $db
create_databases $db $POSTGRES_USER
done
echo "Multiple databases created"
fi