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

11 lines
461 B
Bash
Raw Normal View History

2024-08-13 07:32:28 +00:00
#!/usr/bin/env sh
set -e
if [ -n "$POSTGRES_APP_USER" ]; then
psql -v ON_ERROR_STOP=1 --username "${POSTGRES_USER:-postgres}" --dbname "$" <<-EOSQL
CREATE USER $POSTGRES_APP_USER with encrypted password '$POSTGRES_APP_PASSWORD';
GRANT CREATE, CONNECT ON DATABASE ${POSTGRES_DB:-postgres} TO $POSTGRES_APP_USER;
ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT SELECT, UPDATE, INSERT, DELETE, REFERENCES ON TABLES TO $POSTGRES_APP_USER;
EOSQL
fi