param( [string]$JdbcUrl, [string]$User, [string]$Manifest = (Join-Path $PSScriptRoot "..\migrations\mysql\migration-manifest.txt"), [string]$PasswordEnv = "DB_PASSWORD", [string]$RehearsalSchema, [ValidateSet("apply", "preflight", "dry-run")][string]$Mode = "preflight", [ValidateRange(0, 3600)][int]$LockTimeoutSeconds = 60 ) $ErrorActionPreference = "Stop" $backend = (Resolve-Path (Join-Path $PSScriptRoot "..\..\financial_system_backend")).Path $manifestPath = (Resolve-Path $Manifest).Path $classpathFile = Join-Path $backend "target\migration-classpath.txt" if ($Mode -ne "dry-run" -and ([string]::IsNullOrWhiteSpace($JdbcUrl) -or [string]::IsNullOrWhiteSpace($User))) { throw "MIGRATION_CONNECTION_ARGUMENTS_REQUIRED" } if ($Mode -eq "dry-run" -and -not [string]::IsNullOrWhiteSpace($RehearsalSchema)) { throw "MIGRATION_REHEARSAL_MODE_INVALID" } Push-Location $backend try { & mvn.cmd -o -q -DskipTests compile dependency:build-classpath "-Dmdep.outputFile=$classpathFile" if ($LASTEXITCODE -ne 0) { throw "MIGRATION_RUNNER_BUILD_FAILED" } $dependencyClasspath = Get-Content -Raw $classpathFile $classpath = (Join-Path $backend "target\classes") + ";" + $dependencyClasspath.Trim() $arguments = @( "-cp", $classpath, "com.finance.system.migration.MySqlMigrationRunner", "--manifest=$manifestPath", "--mode=$Mode", "--lock-timeout-seconds=$LockTimeoutSeconds" ) if ($Mode -ne "dry-run") { $arguments += "--url=$JdbcUrl" $arguments += "--user=$User" $arguments += "--password-env=$PasswordEnv" if (-not [string]::IsNullOrWhiteSpace($RehearsalSchema)) { $arguments += "--rehearsal-schema=$RehearsalSchema" } } & java @arguments if ($LASTEXITCODE -ne 0) { throw "MIGRATION_RUNNER_FAILED" } } finally { Pop-Location }