gongxiangp2/scripts/fix-shadow-db-users-fields.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

37 lines
2.0 KiB
PowerShell
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# 修复 Shadow 数据库 users 表缺失字段
# 数据库:lobechat_stage
Write-Host "`n=== 修复 Shadow 数据库 users 表缺失字段 ===" -ForegroundColor Cyan
$server = "root@192.168.58.20"
$sqlCommands = @(
"ALTER TABLE users ADD COLUMN IF NOT EXISTS `"employmentStatus`" TEXT;",
"ALTER TABLE users ADD COLUMN IF NOT EXISTS `"resignationDate`" TIMESTAMP;",
"ALTER TABLE users ADD COLUMN IF NOT EXISTS `"transferDate`" TIMESTAMP;",
"ALTER TABLE users ADD COLUMN IF NOT EXISTS `"transferToDeptId`" TEXT;",
"ALTER TABLE users ADD COLUMN IF NOT EXISTS `"employmentNote`" TEXT;",
"ALTER TABLE users ADD COLUMN IF NOT EXISTS `"statusChangedBy`" TEXT;",
"ALTER TABLE users ADD COLUMN IF NOT EXISTS `"statusChangedAt`" TIMESTAMP;",
"UPDATE users SET `"employmentStatus`" = 'active' WHERE `"employmentStatus`" IS NULL;",
"ALTER TABLE users ALTER COLUMN `"employmentStatus`" SET DEFAULT 'active';",
"CREATE INDEX IF NOT EXISTS users_employmentStatus_idx ON users(`"employmentStatus`");",
"CREATE INDEX IF NOT EXISTS users_transferToDeptId_idx ON users(`"transferToDeptId`");"
)
foreach ($sql in $sqlCommands) {
Write-Host "执行: $sql" -ForegroundColor Gray
$result = ssh $server "docker exec gongxiangpan-postgres-1 psql -U gongxiangpan -d lobechat_stage -c '$sql'" 2>&1
if ($LASTEXITCODE -eq 0) {
Write-Host " ✓ 成功" -ForegroundColor Green
} else {
Write-Host " ⚠ 可能已存在或出错: $result" -ForegroundColor Yellow
}
}
Write-Host "`n=== 验证字段 ===" -ForegroundColor Cyan
$verifySql = "SELECT column_name, data_type FROM information_schema.columns WHERE table_name = 'users' AND column_name IN ('employmentStatus', 'resignationDate', 'transferDate', 'transferToDeptId', 'employmentNote', 'statusChangedBy', 'statusChangedAt') ORDER BY column_name;"
ssh $server "docker exec gongxiangpan-postgres-1 psql -U gongxiangpan -d lobechat_stage -c `"$verifySql`"" 2>&1
Write-Host "`n=== 修复完成 ===" -ForegroundColor Green