run.ps1 обрывается на миграциях: NativeCommandError при ErrorActionPreference = Stop (#45) #46

Merged
NotBigGhost merged 1 commits from issue-45-runps1-migration-stderr into dev 2026-09-09 20:57:37 +03:00
Showing only changes of commit 29a0e17fd1 - Show all commits
+14 -9
View File
@@ -84,16 +84,21 @@ switch ($appEnv) {
} }
# Schema first: a branch may add a migration, and uvicorn would otherwise start # 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. # 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 # Start-Process, not "& python ... 2> file": alembic logs to stderr, and in
# native exe wraps every line into an ErrorRecord. # 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 Write-Host "Applying migrations (alembic upgrade head)..." -ForegroundColor Green
$migLog = [System.IO.Path]::GetTempFileName() $migOut = [System.IO.Path]::GetTempFileName()
Push-Location $backend $migErr = [System.IO.Path]::GetTempFileName()
& $py -m alembic upgrade head 2> $migLog $mig = Start-Process -FilePath $py `
$migCode = $LASTEXITCODE -ArgumentList "-m", "alembic", "upgrade", "head" `
Pop-Location -WorkingDirectory $backend -NoNewWindow -Wait -PassThru `
$migText = (Get-Content $migLog -Raw) -RedirectStandardOutput $migOut -RedirectStandardError $migErr
Remove-Item $migLog -Force -ErrorAction SilentlyContinue $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) { if ($migCode -ne 0) {
Write-Host $migText Write-Host $migText
if ($migText -match "locate revision") { if ($migText -match "locate revision") {