mirror of
https://github.com/lleene/dockerconfig.git
synced 2025-01-22 21:02:22 +01:00
WIP: pgsql init
This commit is contained in:
parent
7ce2bbde8d
commit
2c4b686aab
23
pg-init-scripts/init_db.sh
Normal file
23
pg-init-scripts/init_db.sh
Normal file
@ -0,0 +1,23 @@
|
||||
#!/usr/bin/env 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 WITH OWNER $database TEMPLATE template0 ENCODING UTF8 LC_COLLATE 'en_US.UTF-8' LC_CTYPE 'en_US.UTF-8';
|
||||
GRANT ALL PRIVILEGES ON DATABASE $database TO $database;
|
||||
ALTER ROLE $database WITH LOGIN PASSWORD '$POSTGRES_PASSWORD';
|
||||
EOSQL
|
||||
}
|
||||
|
||||
if [ -n "$POSTGRES_MULTIPLE_DATABASES" ]; then
|
||||
echo "Creating databases: $POSTGRES_MULTIPLE_DATABASES"
|
||||
for db in $(echo "$POSTGRES_MULTIPLE_DATABASES" | tr ',' ' '); do
|
||||
create_user_and_database "$db"
|
||||
done
|
||||
echo "Multiple databases created"
|
||||
fi
|
Loading…
x
Reference in New Issue
Block a user