$ErrorActionPreference = 'Stop' $repoRoot = Split-Path $PSScriptRoot -Parent if ($env:DATABASE_URL) { return } $localRoot = Join-Path $repoRoot '.local' $pgCtl = Join-Path $localRoot 'pgsql\bin\pg_ctl.exe' $dataPath = Join-Path $localRoot 'pgdata' if (!(Test-Path -LiteralPath $pgCtl)) { throw 'Run mockups/setup-database.ps1 first.' } & $pgCtl status -D $dataPath *> $null if ($LASTEXITCODE -ne 0) { $argsForPg = @('start','-D',('"'+$dataPath+'"'),'-l',('"'+(Join-Path $localRoot 'postgres.log')+'"'),'-o','"-h 127.0.0.1 -p 55432"','-w','-t','30') $startResult = Start-Process -FilePath $pgCtl -ArgumentList $argsForPg -WindowStyle Hidden -PassThru if (!$startResult.WaitForExit(35000)) { throw 'PostgreSQL start timed out. See .local/postgres.log.' } if ($startResult.ExitCode -ne 0) { throw 'PostgreSQL could not start. See .local/postgres.log.' } }