Files
danyang-match/scripts/seed-demo.ps1
T
WorkBuddy 69ebf33e18
CI/CD Pipeline / Backend Build & Test (push) Waiting to run
CI/CD Pipeline / Admin Web Build (push) Waiting to run
CI/CD Pipeline / Mini Program Compile Check (push) Waiting to run
CI/CD Pipeline / Migration Validation (push) Blocked by required conditions
CI/CD Pipeline / Test Shell Guard (Phase 23 Gate) (push) Waiting to run
CI/CD Pipeline / UI Contracts (source-structure gates) (push) Waiting to run
CI/CD Pipeline / E2E (live stack) (push) Blocked by required conditions
release: freeze demo v1.1.0 2026-10-19
2026-10-19 20:36:22 +08:00

53 lines
1.8 KiB
PowerShell

param(
[string]$Container = "danyang-match-postgres",
[string]$Database = "danyang_match",
[string]$User = "postgres",
[switch]$E2E
)
$ErrorActionPreference = "Stop"
$repoRoot = Split-Path -Parent $PSScriptRoot
$seedFiles = @(
(Join-Path $repoRoot "backend/src/main/resources/db/demo-seed-final.sql"),
(Join-Path $repoRoot "backend/src/main/resources/db/demo-seed-v11-increment.sql")
)
foreach ($seedFile in $seedFiles) {
if (-not (Test-Path -LiteralPath $seedFile)) {
throw "演示 seed 文件不存在: $seedFile"
}
if ($seedFile -like "*demo-seed-final.sql") {
$operatorCount = docker exec $Container psql -At -U $User -d $Database -c "SELECT COUNT(*) FROM operators"
if ($LASTEXITCODE -ne 0) { throw "无法检查演示运营账号" }
if ([int]$operatorCount.Trim() -gt 0) {
Write-Host "基础演示数据已存在,跳过 demo-seed-final.sql"
continue
}
}
Write-Host "执行演示数据: $([IO.Path]::GetFileName($seedFile))"
Get-Content -LiteralPath $seedFile -Raw |
docker exec -i $Container psql -v ON_ERROR_STOP=1 -U $User -d $Database
if ($LASTEXITCODE -ne 0) {
throw "演示数据执行失败: $seedFile"
}
}
if ($E2E) {
$e2ePassword = $env:E2E_OPERATOR_PASSWORD
if ([string]::IsNullOrWhiteSpace($e2ePassword)) {
throw "使用 -E2E 时必须先设置 E2E_OPERATOR_PASSWORD"
}
$operatorSeed = Join-Path $repoRoot "tests/e2e/sql/seed_e2e_operators.sql"
Write-Host "执行 E2E 运营账号 seed"
Get-Content -LiteralPath $operatorSeed -Raw |
docker exec -i $Container psql -v ON_ERROR_STOP=1 -v "pwd=$e2ePassword" -U $User -d $Database
if ($LASTEXITCODE -ne 0) {
throw "E2E 运营账号 seed 执行失败"
}
}
Write-Host "演示数据初始化完成。"