mirror of
https://github.com/hansjone/netx.git
synced 2026-10-10 16:50:47 +08:00
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 <cursoragent@cursor.com>
This commit is contained in:
parent
a0264e5e94
commit
dbe3062d1b
1 changed files with 9 additions and 12 deletions
|
|
@ -44,18 +44,15 @@ $env:PGPASSWORD = $SuperPassword
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Write-Host "==> Ensuring role '$NetxUser'"
|
Write-Host "==> Ensuring role '$NetxUser'"
|
||||||
$roleSql = @"
|
$roleExists = & psql -h $PgHost -p $PgPort -U $SuperUser -d postgres -tAc "SELECT 1 FROM pg_roles WHERE rolname='$NetxUser'"
|
||||||
DO `$\$
|
if ($LASTEXITCODE -ne 0) {
|
||||||
BEGIN
|
throw "psql_failed (query role exists)"
|
||||||
IF NOT EXISTS (SELECT 1 FROM pg_roles WHERE rolname = '$NetxUser') THEN
|
}
|
||||||
CREATE ROLE $NetxUser LOGIN PASSWORD '$NetxPassword';
|
if (-not ($roleExists -match "1")) {
|
||||||
ELSE
|
Invoke-Psql -Database "postgres" -Sql "CREATE ROLE $NetxUser LOGIN PASSWORD '$NetxPassword';"
|
||||||
ALTER ROLE $NetxUser WITH LOGIN PASSWORD '$NetxPassword';
|
} else {
|
||||||
END IF;
|
Invoke-Psql -Database "postgres" -Sql "ALTER ROLE $NetxUser WITH LOGIN PASSWORD '$NetxPassword';"
|
||||||
END
|
}
|
||||||
`$\$;
|
|
||||||
"@
|
|
||||||
Invoke-Psql -Database "postgres" -Sql $roleSql
|
|
||||||
|
|
||||||
Write-Host "==> Ensuring database '$NetxDatabase'"
|
Write-Host "==> Ensuring database '$NetxDatabase'"
|
||||||
$dbExists = & psql -h $PgHost -p $PgPort -U $SuperUser -d postgres -tAc "SELECT 1 FROM pg_database WHERE datname='$NetxDatabase'"
|
$dbExists = & psql -h $PgHost -p $PgPort -U $SuperUser -d postgres -tAc "SELECT 1 FROM pg_database WHERE datname='$NetxDatabase'"
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue