xoxys.postgres/files/init-user-db.sh

13 lines
536 B
Bash

#!/usr/bin/env sh
set -e
if [ -n "$POSTGRES_APP_USER" ] && [ -n "$POSTGRES_APP_PASSWORD" ] && [ -n "$POSTGRES_APP_DB" ]; then
echo "Create app user and database"
psql -v ON_ERROR_STOP=1 --username "${POSTGRES_USER:-postgres}" <<-EOSQL
CREATE USER $POSTGRES_APP_USER WITH ENCRYPTED PASSWORD '${POSTGRES_APP_PASSWORD}';
CREATE DATABASE $POSTGRES_APP_DB;
GRANT ALL PRIVILEGES ON DATABASE $POSTGRES_APP_DB TO $POSTGRES_APP_USER;
ALTER DATABASE $POSTGRES_APP_DB OWNER TO $POSTGRES_APP_USER;
EOSQL
fi