#!/usr/bin/env pwsh # 查询所有素材类型 param( [Parameter(Mandatory=$false)] [ValidateSet('production', 'shadow')] [string]$Target = 'production' ) $ErrorActionPreference = 'Stop' $ServerIP = "192.168.58.20" if ($Target -eq 'production') { $DatabaseName = "lobechat" } else { $DatabaseName = "lobechat_stage" } $SqlQuery = @' SELECT DISTINCT "materialType", COUNT(*) as count FROM materials WHERE "deletedAt" IS NULL GROUP BY "materialType" ORDER BY "materialType"; '@ Write-Host "查询所有素材类型 ($Target)..." -ForegroundColor Cyan $QueryBytes = [System.Text.Encoding]::UTF8.GetBytes($SqlQuery) $QueryBase64 = [Convert]::ToBase64String($QueryBytes) $RemoteCommand = "echo '$QueryBase64' | base64 -d | docker exec -i gongxiangpan-postgres-1 psql -U gongxiangpan -d $DatabaseName" $Result = ssh -o StrictHostKeyChecking=no root@$ServerIP $RemoteCommand if ($LASTEXITCODE -eq 0) { Write-Host $Result -ForegroundColor Green } else { Write-Host "查询失败!" -ForegroundColor Red Write-Host $Result -ForegroundColor Red }