Files
2026-12-02 15:06:48 +08:00

29 lines
1.2 KiB
PowerShell

param(
[Parameter(Mandatory = $true)][string]$JdbcUrl,
[Parameter(Mandatory = $true)][string]$User,
[Parameter(Mandatory = $true)][string]$Mapping,
[string]$PasswordEnv = "DB_PASSWORD",
[switch]$Apply,
[ValidateRange(0, 3600)][int]$LockTimeoutSeconds = 60
)
$ErrorActionPreference = "Stop"
$backend = (Resolve-Path (Join-Path $PSScriptRoot "..\..\financial_system_backend")).Path
$mappingPath = (Resolve-Path $Mapping).Path
$classpathFile = Join-Path $backend "target\migration-classpath.txt"
Push-Location $backend
try {
& mvn.cmd -q -DskipTests compile dependency:build-classpath "-Dmdep.outputFile=$classpathFile"
if ($LASTEXITCODE -ne 0) { throw "TENANT_BACKFILL_BUILD_FAILED" }
$dependencyClasspath = Get-Content -Raw $classpathFile
$classpath = (Join-Path $backend "target\classes") + ";" + $dependencyClasspath.Trim()
$dryRun = if ($Apply) { "false" } else { "true" }
& java -cp $classpath com.finance.system.migration.TenantBackfillTool `
"--url=$JdbcUrl" "--user=$User" "--password-env=$PasswordEnv" `
"--mapping=$mappingPath" "--dry-run=$dryRun" "--lock-timeout-seconds=$LockTimeoutSeconds"
if ($LASTEXITCODE -ne 0) { throw "TENANT_BACKFILL_FAILED" }
} finally {
Pop-Location
}