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

13 lines
536 B
Bash
Raw Normal View History

2024-08-13 07:32:28 +00:00
#!/usr/bin/env sh
set -e
2024-08-13 12:58:02 +00:00
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;
2024-08-13 13:12:18 +00:00
ALTER DATABASE $POSTGRES_APP_DB OWNER TO $POSTGRES_APP_USER;
2024-08-13 07:32:28 +00:00
EOSQL
fi