Files
wecom-ai-assistant/deploy/scripts/migrate.ps1
2026-02-05 16:36:32 +08:00

32 lines
1003 B
PowerShell

# One-click migrate (Docker). Run from project root: .\deploy\scripts\migrate.ps1
$ErrorActionPreference = "Stop"
$ProjectRoot = Split-Path -Parent (Split-Path -Parent $PSScriptRoot)
Set-Location $ProjectRoot
Write-Host "[1/3] Starting database..." -ForegroundColor Cyan
docker compose up -d db
Write-Host "[2/3] Waiting for DB ready..." -ForegroundColor Cyan
$max = 30
for ($i = 0; $i -lt $max; $i++) {
$null = docker compose exec -T db pg_isready -U wecom -d wecom_ai 2>$null
if ($LASTEXITCODE -eq 0) { break }
Start-Sleep -Seconds 1
}
if ($i -ge $max) {
Write-Host "DB not ready in ${max}s. Check: docker compose logs db" -ForegroundColor Red
exit 1
}
Write-Host "[3/3] Running Alembic upgrade head..." -ForegroundColor Cyan
docker compose run --rm backend sh -c "alembic upgrade head"
$code = $LASTEXITCODE
if ($code -eq 0) {
Write-Host "Migrate done." -ForegroundColor Green
} else {
Write-Host "Migrate failed. See errors above." -ForegroundColor Red
exit 1
}