reset-dev-data.ps1 1.2 KB

12345678910111213141516171819202122232425262728293031323334
  1. param(
  2. [string]$Confirmation
  3. )
  4. $ErrorActionPreference = "Stop"
  5. $ProjectRoot = Split-Path -Parent $PSScriptRoot
  6. $Expected = "RESET insurance_s1"
  7. Write-Host "即将重建数据库:insurance_s1_core、insurance_s1_agent、insurance_s1_analytics"
  8. Write-Host "即将删除 Redis 前缀:ins:s1:*"
  9. if ([string]::IsNullOrWhiteSpace($Confirmation)) {
  10. $Confirmation = Read-Host "请输入 $Expected 继续"
  11. }
  12. if ($Confirmation -cne $Expected) {
  13. throw "确认文本不匹配,已取消。"
  14. }
  15. Push-Location (Join-Path $ProjectRoot "backend")
  16. try {
  17. uv run alembic -c alembic.ini --name alembic_analytics downgrade base
  18. if ($LASTEXITCODE -ne 0) { throw "Analytics 数据库清理失败。" }
  19. uv run alembic -c alembic.ini --name alembic_agent downgrade base
  20. if ($LASTEXITCODE -ne 0) { throw "Agent 数据库清理失败。" }
  21. uv run alembic -c alembic.ini --name alembic_core downgrade base
  22. if ($LASTEXITCODE -ne 0) { throw "Core 数据库清理失败。" }
  23. uv run python -m zbt.commands.reset_cache
  24. if ($LASTEXITCODE -ne 0) { throw "Redis 清理失败。" }
  25. & (Join-Path $PSScriptRoot "migrate.ps1")
  26. & (Join-Path $PSScriptRoot "seed.ps1")
  27. & (Join-Path $PSScriptRoot "build-analytics.ps1")
  28. }
  29. finally {
  30. Pop-Location
  31. }