Initial commit
All checks were successful
Deploy storage stack / deploy (push) Successful in 24s

This commit is contained in:
Sergei Poljanski 2026-05-26 17:13:14 +03:00
commit 479e3d5cf9
Signed by: asxpi
GPG key ID: 4F8851660FA4121B
10 changed files with 466 additions and 0 deletions

29
init/postgres-init.sh Normal file
View file

@ -0,0 +1,29 @@
#!/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"