Skip to content

Commit eecd749

Browse files
multi tenant csv helper
1 parent 1f0da68 commit eecd749

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

Helpers/multiTenantCSVDeploy.ps1

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# Define the script block to run in each runspace
2+
$scriptBlock = {
3+
param ($currentJDBC, $baselineVersion, $flywayLicenseKey, $workingDirectory)
4+
5+
$deployment = "flyway migrate -outOfOrder='true' -baselineOnMigrate='true' -errorOverrides='S0001:0:I' -configFiles=$workingDirectory\flyway.toml -locations=filesystem:$workingDirectory\migrations -url='$currentJDBC'"
6+
Write-Host "flywayCommand: $deployment"
7+
Write-Host "deploying to: $currentJDBC"
8+
Invoke-Expression $deployment
9+
}
10+
11+
# Create a runspace pool
12+
$runspacePool = [runspacefactory]::CreateRunspacePool(1, [Environment]::ProcessorCount)
13+
$runspacePool.Open()
14+
15+
# Create an array to hold the runspaces
16+
$runspaces = @()
17+
18+
# Import the CSV file
19+
$deploymentTargets = Import-Csv -Path $deploymentTargetsList
20+
21+
# Create and start runspaces
22+
foreach ($target in $deploymentTargets) {
23+
$runspace = [powershell]::Create().AddScript($scriptBlock).AddArgument($target.JDBCString).AddArgument($baselineVersion).AddArgument($flywayLicenseKey).AddArgument($workingDirectory)
24+
$runspace.RunspacePool = $runspacePool
25+
$runspaces += [PSCustomObject]@{ Pipe = $runspace; Status = $runspace.BeginInvoke() }
26+
}
27+
28+
# Wait for all runspaces to complete
29+
$runspaces | ForEach-Object {
30+
$_.Pipe.EndInvoke($_.Status)
31+
$_.Pipe.Dispose()
32+
}
33+
34+
# Close the runspace pool
35+
$runspacePool.Close()
36+
$runspacePool.Dispose()

0 commit comments

Comments
 (0)