2023-07-05 00:31:59 +02:00
|
|
|
#!/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
|
2023-07-15 19:30:17 +02:00
|
|
|
CREATE DATABASE "$database" OWNER $POSTGRES_USER;
|
2023-07-05 00:31:59 +02:00
|
|
|
EOSQL
|
|
|
|
}
|
|
|
|
|
|
|
|
if [ -n "$POSTGRES_MULTIPLE_DATABASES" ]; then
|
|
|
|
echo "Multiple database creation requested: $POSTGRES_MULTIPLE_DATABASES"
|
|
|
|
for database in $(echo "$POSTGRES_MULTIPLE_DATABASES" | tr ',' ' '); do
|
|
|
|
create_user_and_database "$database"
|
|
|
|
done
|
|
|
|
echo "Multiple databases created"
|
|
|
|
fi
|