Fix missing user

This commit is contained in:
soraefir
2026-05-06 01:58:07 +02:00
parent f3fcb320be
commit e7a414df5f

View File

@@ -26,6 +26,9 @@ in {
systemd.services.postgresql.postStart = lib.mkAfter '' systemd.services.postgresql.postStart = lib.mkAfter ''
PSQL="${pkgs.postgresql}/bin/psql" PSQL="${pkgs.postgresql}/bin/psql"
${lib.concatMapStringsSep "\n" (name: '' ${lib.concatMapStringsSep "\n" (name: ''
$PSQL -tAc "SELECT 1 FROM pg_roles WHERE rolname = '${name}_user'" | grep -q 1 || \
$PSQL -tAc "CREATE ROLE ${name}_user WITH LOGIN;"
$PSQL -tAc "ALTER DATABASE ${name}_db OWNER TO ${name}_user;" $PSQL -tAc "ALTER DATABASE ${name}_db OWNER TO ${name}_user;"
if [ -f "${config.sops.secrets."${name}_pass".path}" ]; then if [ -f "${config.sops.secrets."${name}_pass".path}" ]; then