All checks were successful
Deploy storage stack / deploy (push) Successful in 24s
29 lines
780 B
Bash
29 lines
780 B
Bash
#!/bin/sh
|
|
# Idempotent bootstrap: create per-app roles and databases.
|
|
# Re-running is safe — checks before creating, updates passwords if changed.
|
|
set -eu
|
|
|
|
ensure_role() {
|
|
role="$1"
|
|
password="$2"
|
|
exists=$(psql -tAc "SELECT 1 FROM pg_roles WHERE rolname='${role}'")
|
|
if [ "${exists}" = "1" ]; then
|
|
psql -c "ALTER ROLE \"${role}\" WITH LOGIN PASSWORD '${password}';"
|
|
else
|
|
psql -c "CREATE ROLE \"${role}\" WITH LOGIN PASSWORD '${password}';"
|
|
fi
|
|
}
|
|
|
|
ensure_db() {
|
|
db="$1"
|
|
owner="$2"
|
|
exists=$(psql -tAc "SELECT 1 FROM pg_database WHERE datname='${db}'")
|
|
if [ "${exists}" != "1" ]; then
|
|
psql -c "CREATE DATABASE \"${db}\" OWNER \"${owner}\";"
|
|
fi
|
|
}
|
|
|
|
ensure_role "asxpio" "${ASXPIO_DB_PASSWORD}"
|
|
ensure_db "asxpio" "asxpio"
|
|
|
|
echo "postgres-init: done"
|