gongxiangp2/scripts/run-migration-shadow.ps1
chenpei ea9076df45 feat: 实现统一的下载错误处理系统并修复产品全案数据库Schema
- 创建统一的下载错误处理模块 (lib/download-errors.ts)
- 实现13种错误类型分类和中文错误消息
- 后端统一使用 createDownloadError 创建标准化错误响应
- 前端统一使用 parseDownloadError 解析错误并显示
- 修复正式系统数据库Schema,添加产品全案相关字段和表
- 执行数据库迁移:添加 task_no, task_status, task_fetched_at 字段
- 创建 material_assets, api_keys, api_call_logs 表
2026-01-05 17:52:42 +08:00

138 lines
4.8 KiB
PowerShell

# 影子系统迁移执行脚本
# 执行阶段一和阶段二的数据库迁移
$ErrorActionPreference = "Stop"
Write-Host "========================================" -ForegroundColor Cyan
Write-Host "影子系统数据库迁移脚本" -ForegroundColor Cyan
Write-Host "========================================" -ForegroundColor Cyan
Write-Host ""
# 设置环境变量(影子系统)
$env:DATABASE_URL = "postgresql://gongxiangpan:gongxiangpan123@192.168.58.20:5432/lobechat_stage"
Write-Host "✅ 环境变量已设置" -ForegroundColor Green
Write-Host " 数据库: lobechat_stage (影子系统)" -ForegroundColor Cyan
Write-Host ""
# 切换到项目根目录
Set-Location $PSScriptRoot\..
$projectRoot = Get-Location
Write-Host "项目目录: $projectRoot" -ForegroundColor Cyan
Write-Host ""
# 步骤1: 应用Schema变更
Write-Host "📋 步骤1: 应用Schema变更..." -ForegroundColor Yellow
Write-Host " 执行: npx prisma db push" -ForegroundColor Gray
try {
npx prisma db push --accept-data-loss
if ($LASTEXITCODE -ne 0) {
throw "Schema更新失败"
}
Write-Host " ✅ Schema更新成功" -ForegroundColor Green
} catch {
Write-Host " ❌ Schema更新失败: $_" -ForegroundColor Red
exit 1
}
Write-Host ""
# 步骤2: 生成Prisma Client
Write-Host "📋 步骤2: 生成Prisma Client..." -ForegroundColor Yellow
try {
npx prisma generate
if ($LASTEXITCODE -ne 0) {
throw "Prisma Client生成失败"
}
Write-Host " ✅ Prisma Client生成成功" -ForegroundColor Green
} catch {
Write-Host " ❌ Prisma Client生成失败: $_" -ForegroundColor Red
exit 1
}
Write-Host ""
# 步骤3: 阶段一迁移 - 用户状态管理
Write-Host "📋 步骤3: 阶段一迁移 - 用户状态管理..." -ForegroundColor Yellow
Write-Host " 执行: npx tsx scripts/migrate-user-status-safe.ts" -ForegroundColor Gray
try {
npx tsx scripts/migrate-user-status-safe.ts
if ($LASTEXITCODE -ne 0) {
throw "阶段一迁移失败"
}
Write-Host " ✅ 阶段一迁移成功" -ForegroundColor Green
} catch {
Write-Host " ❌ 阶段一迁移失败: $_" -ForegroundColor Red
exit 1
}
Write-Host ""
# 步骤4: 验证阶段一
Write-Host "📋 步骤4: 验证阶段一迁移结果..." -ForegroundColor Yellow
Write-Host " 执行: npx tsx scripts/verify-migration.ts 1" -ForegroundColor Gray
try {
npx tsx scripts/verify-migration.ts 1
if ($LASTEXITCODE -ne 0) {
Write-Host " ⚠️ 验证发现问题,请检查输出" -ForegroundColor Yellow
} else {
Write-Host " ✅ 阶段一验证通过" -ForegroundColor Green
}
} catch {
Write-Host " ⚠️ 验证过程出错: $_" -ForegroundColor Yellow
}
Write-Host ""
# 步骤5: 阶段二迁移 - 部门外键关联
Write-Host "📋 步骤5: 阶段二迁移 - 部门外键关联..." -ForegroundColor Yellow
Write-Host " 执行: npx tsx scripts/migrate-department-to-id-safe.ts" -ForegroundColor Gray
try {
npx tsx scripts/migrate-department-to-id-safe.ts
if ($LASTEXITCODE -ne 0) {
throw "阶段二迁移失败"
}
Write-Host " ✅ 阶段二迁移成功" -ForegroundColor Green
} catch {
Write-Host " ❌ 阶段二迁移失败: $_" -ForegroundColor Red
exit 1
}
Write-Host ""
# 步骤6: 验证阶段二
Write-Host "📋 步骤6: 验证阶段二迁移结果..." -ForegroundColor Yellow
Write-Host " 执行: npx tsx scripts/verify-migration.ts 2" -ForegroundColor Gray
try {
npx tsx scripts/verify-migration.ts 2
if ($LASTEXITCODE -ne 0) {
Write-Host " ⚠️ 验证发现问题,请检查输出" -ForegroundColor Yellow
} else {
Write-Host " ✅ 阶段二验证通过" -ForegroundColor Green
}
} catch {
Write-Host " ⚠️ 验证过程出错: $_" -ForegroundColor Yellow
}
Write-Host ""
# 步骤7: 完整验证
Write-Host "📋 步骤7: 完整验证..." -ForegroundColor Yellow
Write-Host " 执行: npx tsx scripts/verify-migration.ts" -ForegroundColor Gray
try {
npx tsx scripts/verify-migration.ts
if ($LASTEXITCODE -ne 0) {
Write-Host " ⚠️ 验证发现问题,请检查输出" -ForegroundColor Yellow
} else {
Write-Host " ✅ 完整验证通过" -ForegroundColor Green
}
} catch {
Write-Host " ⚠️ 验证过程出错: $_" -ForegroundColor Yellow
}
Write-Host ""
Write-Host "========================================" -ForegroundColor Green
Write-Host "✅ 迁移执行完成" -ForegroundColor Green
Write-Host "========================================" -ForegroundColor Green
Write-Host ""
Write-Host "⚠️ 下一步:" -ForegroundColor Yellow
Write-Host " 1. 检查验证输出,确认没有错误" -ForegroundColor White
Write-Host " 2. 在影子系统进行功能测试" -ForegroundColor White
Write-Host " 3. 访问: http://192.168.58.20:5320" -ForegroundColor Cyan
Write-Host ""