diff --git a/run.ps1 b/run.ps1 index f3158ac..419da7d 100644 --- a/run.ps1 +++ b/run.ps1 @@ -84,16 +84,21 @@ switch ($appEnv) { } # Schema first: a branch may add a migration, and uvicorn would otherwise start # on the old schema and fail with 500 on the first hit of a new table. - # stderr goes to a file: alembic logs there, and in PowerShell 5.1 "2>&1" on a - # native exe wraps every line into an ErrorRecord. + # Start-Process, not "& python ... 2> file": alembic logs to stderr, and in + # Windows PowerShell 5.1 ANY stderr redirection of a native exe turns each line + # into a NativeCommandError - which is terminating under $ErrorActionPreference + # = "Stop" set at the top of this script, so the launcher died right here. Write-Host "Applying migrations (alembic upgrade head)..." -ForegroundColor Green - $migLog = [System.IO.Path]::GetTempFileName() - Push-Location $backend - & $py -m alembic upgrade head 2> $migLog - $migCode = $LASTEXITCODE - Pop-Location - $migText = (Get-Content $migLog -Raw) - Remove-Item $migLog -Force -ErrorAction SilentlyContinue + $migOut = [System.IO.Path]::GetTempFileName() + $migErr = [System.IO.Path]::GetTempFileName() + $mig = Start-Process -FilePath $py ` + -ArgumentList "-m", "alembic", "upgrade", "head" ` + -WorkingDirectory $backend -NoNewWindow -Wait -PassThru ` + -RedirectStandardOutput $migOut -RedirectStandardError $migErr + $migCode = $mig.ExitCode + $migText = ((Get-Content $migErr -Raw), (Get-Content $migOut -Raw)) -join "`n" + Remove-Item $migOut -Force -ErrorAction SilentlyContinue + Remove-Item $migErr -Force -ErrorAction SilentlyContinue if ($migCode -ne 0) { Write-Host $migText if ($migText -match "locate revision") {