From dbe3062d1bd5f05d005fc29af9de283bf7afde61 Mon Sep 17 00:00:00 2001 From: oliver Date: Wed, 6 May 2026 17:17:30 +0800 Subject: [PATCH] fix(setup): avoid DO $$ in init_pg role bootstrap Replace the DO-block role upsert with explicit role existence check plus CREATE/ALTER statements, preventing PowerShell/psql quoting issues on some Windows setups. Co-authored-by: Cursor --- scripts/init_pg.ps1 | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/scripts/init_pg.ps1 b/scripts/init_pg.ps1 index 00480ab..d9c02de 100644 --- a/scripts/init_pg.ps1 +++ b/scripts/init_pg.ps1 @@ -44,18 +44,15 @@ $env:PGPASSWORD = $SuperPassword try { Write-Host "==> Ensuring role '$NetxUser'" - $roleSql = @" -DO `$\$ -BEGIN - IF NOT EXISTS (SELECT 1 FROM pg_roles WHERE rolname = '$NetxUser') THEN - CREATE ROLE $NetxUser LOGIN PASSWORD '$NetxPassword'; - ELSE - ALTER ROLE $NetxUser WITH LOGIN PASSWORD '$NetxPassword'; - END IF; -END -`$\$; -"@ - Invoke-Psql -Database "postgres" -Sql $roleSql + $roleExists = & psql -h $PgHost -p $PgPort -U $SuperUser -d postgres -tAc "SELECT 1 FROM pg_roles WHERE rolname='$NetxUser'" + if ($LASTEXITCODE -ne 0) { + throw "psql_failed (query role exists)" + } + if (-not ($roleExists -match "1")) { + Invoke-Psql -Database "postgres" -Sql "CREATE ROLE $NetxUser LOGIN PASSWORD '$NetxPassword';" + } else { + Invoke-Psql -Database "postgres" -Sql "ALTER ROLE $NetxUser WITH LOGIN PASSWORD '$NetxPassword';" + } Write-Host "==> Ensuring database '$NetxDatabase'" $dbExists = & psql -h $PgHost -p $PgPort -U $SuperUser -d postgres -tAc "SELECT 1 FROM pg_database WHERE datname='$NetxDatabase'"