# 删除素材脚本 param( [Parameter(Mandatory=$true)] [string]$MaterialId, [ValidateSet('production', 'shadow')] [string]$Target = 'production' ) $ServerIP = "192.168.58.20" $DbUser = "gongxiangpan" $DbName = if ($Target -eq 'shadow') { 'lobechat_stage' } else { 'lobechat' } Write-Host "========================================" -ForegroundColor Cyan Write-Host "删除素材" -ForegroundColor Cyan Write-Host "========================================" -ForegroundColor Cyan Write-Host "" Write-Host "素材 ID: $MaterialId" -ForegroundColor Yellow Write-Host "目标环境: $Target ($DbName)" -ForegroundColor Yellow Write-Host "" # 查询素材信息 Write-Host "📋 查询素材信息..." -ForegroundColor Cyan $queryCmd = "docker exec gongxiangpan-postgres-1 psql -U $DbUser -d $DbName -t -c `"SELECT \`"productModel\`", \`"materialType\`", \`"previewUrl\`" FROM materials WHERE id = '$MaterialId';`"" $materialInfo = ssh "root@$ServerIP" $queryCmd 2>&1 if ($materialInfo -match '\w+') { Write-Host "素材信息:" -ForegroundColor Gray Write-Host $materialInfo -ForegroundColor Gray Write-Host "" } else { Write-Host "❌ 素材不存在或查询失败" -ForegroundColor Red exit 1 } # 确认删除 $confirm = Read-Host "确认删除这个素材吗?(yes/no)" if ($confirm -ne 'yes') { Write-Host "❌ 已取消删除" -ForegroundColor Yellow exit 0 } # 删除素材(软删除) Write-Host "" Write-Host "🗑️ 删除素材..." -ForegroundColor Cyan $deleteCmd = "docker exec gongxiangpan-postgres-1 psql -U $DbUser -d $DbName -c `"UPDATE materials SET \`"deletedAt\`" = NOW() WHERE id = '$MaterialId';`"" $deleteResult = ssh "root@$ServerIP" $deleteCmd 2>&1 if ($deleteResult -match 'UPDATE 1') { Write-Host "✅ 素材已删除(软删除)" -ForegroundColor Green } else { Write-Host "❌ 删除失败" -ForegroundColor Red Write-Host $deleteResult -ForegroundColor Red exit 1 } Write-Host "" Write-Host "========================================" -ForegroundColor Cyan Write-Host "✅ 完成!" -ForegroundColor Green Write-Host "========================================" -ForegroundColor Cyan