570 lines
26 KiB
PowerShell
570 lines
26 KiB
PowerShell
function Invoke-AlkamiMigrationRunner {
|
|
<#
|
|
.SYNOPSIS
|
|
Run migrations against ORB tenant, master, etc databases
|
|
|
|
.DESCRIPTION
|
|
Used to call the Alkami MigrationUtility for running migrations against various systems
|
|
ParameterSets
|
|
ORB = TeamCity ORB (Update hyphen AlkamiDatabase), SDKSetup, Developers, DevLeads RunMigrations for ORB
|
|
TeamCityInstallPackages = TeamCity Install_Packages, RunMigrationsOnServiceAgainstTarget
|
|
Runtime = Developers
|
|
|
|
.PARAMETER MigrationRunnerPath
|
|
The path that executes the migrations. This is dependent on the framework the migrations were developed in.
|
|
The expectation is that they would match their hosting service if they are bundled together.
|
|
|
|
.PARAMETER MigrationTypeName
|
|
The matched name to the type of migration being run.
|
|
This has to align with the valid type names in the SRE.MigrationUtility code -> Alkami.TeamCity.MigrationRunnerShared.Configuration namespace.
|
|
|
|
.PARAMETER Runtime
|
|
As an alternative to the MigrationTypeName and MigrationRunnerPath, you can specify the package runtime.
|
|
By specifying this parameter, you are not required to provide the feed, dbmsusers, subscriptionhost, and other parameters.
|
|
|
|
.PARAMETER PackageId
|
|
The ID of the package being installed.
|
|
|
|
.PARAMETER PackageVersion
|
|
The version of the package being installed.
|
|
|
|
.PARAMETER Feed
|
|
The feed where the package can be found.
|
|
|
|
.PARAMETER ConnectionString
|
|
The connection string to run migrations against.
|
|
On a developer machine, this can be retrieved from the machine.config automatically when using the -Runtime parameter.
|
|
|
|
.PARAMETER DbmsUser
|
|
The users the migrations are to be run targeting for typical use-cases
|
|
On a developer machine, this can be retrieved from the machine.config automatically when using the -Runtime parameter.
|
|
|
|
.PARAMETER DatabaseServiceAccount
|
|
This value should normally be supplied via manifest, but may be specified manually if invoked manually.
|
|
|
|
.PARAMETER SubscriptionHost
|
|
This is the hostname or IP address of the service that runs the subscription service.
|
|
This value is particularly valuable for migrations that talk to services during the runtime.
|
|
Example: Notification template registration that occurs once per tenant database that calls a service to register the notification templates.
|
|
|
|
.PARAMETER TempFolder
|
|
The location where files should be downloaded to.
|
|
|
|
.PARAMETER EnvironmentType
|
|
The environment type that the migrations are targeting.
|
|
|
|
.PARAMETER OrbMigrateFolderPath
|
|
The location where ORB migration dlls are located. This is typically supplied as part of the deployment process.
|
|
|
|
.PARAMETER Parallelism
|
|
This value determines how many threads/workers are used in parallel to the service.
|
|
Values should be supplied higher than 0. A value of -1 indicates to run as many threads as possible.
|
|
|
|
.PARAMETER SqlTimeout
|
|
This value determines how long a sql command should take in seconds.
|
|
Values should be supplied higher than 0. A value of -1 indicates no timeout.
|
|
Default timeout is 10 minutes
|
|
|
|
.PARAMETER LogFileFolder
|
|
When supplied, the output of the migration runner will be redirected to the specified path.
|
|
If the folder does not exist, it will be created.
|
|
If the file already exists, it will be overwritten.
|
|
If the PackageId and PackageVersion are provided, the results will be directed to a file with the name format of "{package id}.{version}.log" in the specified folder.
|
|
Otherwise the log file will be written to a file named after the MigrationTypeName value with the Process.ID appended like so "{migration type name}.{process id}.log"
|
|
NOTE: This parameter should not be used in a TeamCity process as it will not emit anything to the TeamCity process.
|
|
|
|
.PARAMETER WhatIf
|
|
Supply this parameter to see what would happen if the utility were to run to completion.
|
|
|
|
.PARAMETER Tags
|
|
Supply this parameter to FluentMigrations for ex: SDK
|
|
|
|
.PARAMETER LegacyFluentMigratorContext
|
|
Provided for legacy SDK migration compatability
|
|
|
|
.PARAMETER LogTeamCityMessages
|
|
Required to log team city control messages at all
|
|
Omitting the LogTeamCityMessages flag will not cause messages to be ommitted,
|
|
(for that you should set the global logging to NONE)
|
|
but will instead omit the use of TeamCity Service Messages, such as ##teamcity(message...
|
|
|
|
.PARAMETER NoTeamCityBlockMessages
|
|
Will prevent OpenBlock and CloseBlock messages from happening
|
|
|
|
.PARAMETER NoTeamCityBuildProblems
|
|
Will prevent BuildProblems from emitting as a build problem
|
|
|
|
.PARAMETER NoTeamCityMessages
|
|
Will prevent Messages from being written (you should probably just not /LogTeamCityMessages if you get to this point)
|
|
|
|
.PARAMETER LogErrorsAsWarn
|
|
Will not use the ERROR message format, all will goto WARN, this is to prevent certain TC job steps from stopping the pipeline
|
|
|
|
.OUTPUTS
|
|
This cmdlet does not return anything directly, but there will be a $EXITCODE value set,
|
|
and this process will emit TeamCity BuildError and Message when run on TeamCity servers.
|
|
|
|
On any other environment, logs will be emitted to the console (standard output) and may be captured
|
|
|
|
.LINK
|
|
Get-MigrationRunnerExe
|
|
|
|
#>
|
|
[CmdletBinding(DefaultParameterSetName = 'TeamCityInstallPackages')]
|
|
[OutputType([void])]
|
|
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSShouldProcess", "", Justification = "Use of WhatIf flag intentional so we track the presence of it")]
|
|
param (
|
|
[Parameter(Mandatory = $true, ParameterSetName = 'TeamCityInstallPackages')]
|
|
[Parameter(Mandatory = $true, ParameterSetName = 'TeamCityInstallPackagesByPackage')]
|
|
[Parameter(Mandatory = $false, ParameterSetName = 'GrantRoleTenants')]
|
|
[Parameter(Mandatory = $false, ParameterSetName = 'DbUserCreate')]
|
|
[Parameter(Mandatory = $false, ParameterSetName = 'GrantRole')]
|
|
[Parameter(Mandatory = $false, ParameterSetName = 'ORB')]
|
|
[ValidateNotNullOrEmpty()]
|
|
[string]$MigrationRunnerPath,
|
|
|
|
[Parameter(Mandatory = $true, ParameterSetName = 'TeamCityInstallPackages')]
|
|
[Parameter(Mandatory = $true, ParameterSetName = 'TeamCityInstallPackagesByPackage')]
|
|
[Parameter(Mandatory = $true, ParameterSetName = 'GrantRoleTenants')]
|
|
[Parameter(Mandatory = $true, ParameterSetName = 'DbUserCreate')]
|
|
[Parameter(Mandatory = $true, ParameterSetName = 'GrantRole')]
|
|
[Parameter(Mandatory = $true, ParameterSetName = 'ORB')]
|
|
[ValidateSet('choco', 'orb', 'GrantRoleTenants', 'DbUserCreate','GrantRole')]
|
|
[string]$MigrationTypeName,
|
|
|
|
[Parameter(Mandatory = $true, ParameterSetName = 'DeveloperEnvironment')]
|
|
[ValidateNotNullOrEmpty()]
|
|
[string]$Runtime,
|
|
|
|
[Parameter(Mandatory = $true, ParameterSetName = 'TeamCityInstallPackages')]
|
|
[Parameter(Mandatory = $true, ParameterSetName = 'DeveloperEnvironment')]
|
|
[ValidateNotNullOrEmpty()]
|
|
[string]$PackageId,
|
|
|
|
[Parameter(Mandatory = $true, ParameterSetName = 'TeamCityInstallPackages')]
|
|
[Parameter(Mandatory = $true, ParameterSetName = 'DeveloperEnvironment')]
|
|
[ValidateNotNullOrEmpty()]
|
|
[string]$PackageVersion,
|
|
|
|
# Required = false because on a developer machine this can be found locally sometimes as an installed package.
|
|
# Required = false because we default to the choco dev feed.
|
|
[Parameter(Mandatory = $true, ParameterSetName = 'TeamCityInstallPackages')]
|
|
[Parameter(Mandatory = $false, ParameterSetName = 'DeveloperEnvironment')]
|
|
[Alias("Feed")]
|
|
[string]$PackageFeed,
|
|
|
|
[Parameter(Mandatory = $true, ParameterSetName = 'TeamCityInstallPackagesByPackage')]
|
|
[object]$Package,
|
|
|
|
[Parameter(Mandatory = $true, ParameterSetName = 'ManuallyApplyServiceAccount')]
|
|
[Parameter(Mandatory = $true, ParameterSetName = 'ORB')]
|
|
# Required = false because on a developer machine this can be found locally
|
|
[Parameter(Mandatory = $true, ParameterSetName = 'TeamCityInstallPackages')]
|
|
[Parameter(Mandatory = $true, ParameterSetName = 'TeamCityInstallPackagesByPackage')]
|
|
[Parameter(Mandatory = $false, ParameterSetName = 'DeveloperEnvironment')]
|
|
[Parameter(Mandatory = $true, ParameterSetName = 'GrantRoleTenants')]
|
|
[Parameter(Mandatory = $true, ParameterSetName = 'GrantRole')]
|
|
[string]$ConnectionString,
|
|
|
|
# Required = false because on a developer machine this can be found locally
|
|
[Parameter(Mandatory = $true, ParameterSetName = 'TeamCityInstallPackages')]
|
|
[Parameter(Mandatory = $true, ParameterSetName = 'TeamCityInstallPackagesByPackage')]
|
|
[Parameter(Mandatory = $false, ParameterSetName = 'DeveloperEnvironment')]
|
|
[Parameter(Mandatory = $true, ParameterSetName = 'DbUserCreate')]
|
|
[string[]]$DbmsUser,
|
|
|
|
# Required = false because on a developer machine this can be found locally
|
|
[Parameter(Mandatory = $true, ParameterSetName = 'TeamCityInstallPackages')]
|
|
[Parameter(Mandatory = $true, ParameterSetName = 'TeamCityInstallPackagesByPackage')]
|
|
[Parameter(Mandatory = $false, ParameterSetName = 'DeveloperEnvironment')]
|
|
[string]$SubscriptionHost,
|
|
|
|
# Required = false because we default to the system temp folder.
|
|
[Parameter(Mandatory = $true, ParameterSetName = 'TeamCityInstallPackages')]
|
|
[Parameter(Mandatory = $true, ParameterSetName = 'TeamCityInstallPackagesByPackage')]
|
|
[Parameter(Mandatory = $false, ParameterSetName = 'DeveloperEnvironment')]
|
|
[string]$TempFolder,
|
|
|
|
# Required = false because on a developer machine this can be found locally
|
|
[Parameter(Mandatory = $true, ParameterSetName = 'TeamCityInstallPackages')]
|
|
[Parameter(Mandatory = $true, ParameterSetName = 'TeamCityInstallPackagesByPackage')]
|
|
[Parameter(Mandatory = $false, ParameterSetName = 'DeveloperEnvironment')]
|
|
[string]$EnvironmentType,
|
|
|
|
[Parameter(Mandatory = $false, ParameterSetName = 'TeamCityInstallPackages')]
|
|
[Parameter(Mandatory = $false, ParameterSetName = 'TeamCityInstallPackagesByPackage')]
|
|
[Parameter(Mandatory = $false, ParameterSetName = 'DeveloperEnvironment')]
|
|
[Parameter(Mandatory = $false, ParameterSetName = 'ORB')]
|
|
[Parameter(Mandatory = $false, ParameterSetName = 'GrantRoleTenants')]
|
|
[Parameter(Mandatory = $false, ParameterSetName = 'GrantRole')]
|
|
[string[]]$BankGuids,
|
|
|
|
[Parameter(Mandatory = $true, ParameterSetName = 'ORB')]
|
|
[ValidateNotNullOrEmpty()]
|
|
[string]$OrbMigrateFolderPath,
|
|
|
|
[Parameter(Mandatory = $true, ParameterSetName = 'ManuallyApplyServiceAccount')]
|
|
[Parameter(Mandatory = $true, ParameterSetName = 'GrantRoleTenants')]
|
|
[Parameter(Mandatory = $true, ParameterSetName = 'GrantRole')]
|
|
[string[]]$DatabaseServiceAccount,
|
|
|
|
[Parameter(Mandatory = $true, ParameterSetName = 'GrantRole')]
|
|
[string[]]$RoleName,
|
|
|
|
[Parameter(Mandatory = $true, ParameterSetName = 'GrantRoleTenants')]
|
|
[string[]]$TenantRoleName,
|
|
|
|
[Parameter(Mandatory = $true, ParameterSetName = 'DbUserCreate')]
|
|
[string]$DataSource,
|
|
|
|
[Parameter(Mandatory = $true, ParameterSetName = 'DbUserCreate')]
|
|
[string]$DatabaseName,
|
|
|
|
# Has a default value in the app already, no need to configure it unless desired
|
|
[Parameter(Mandatory = $false)]
|
|
[int]$Parallelism,
|
|
|
|
# Has a default value in the app already, no need to configure it unless desired
|
|
[Parameter(Mandatory = $false)]
|
|
[int]$SqlTimeout,
|
|
|
|
[Parameter(Mandatory = $false)]
|
|
[string]$LogFileFolder,
|
|
|
|
[Parameter(Mandatory = $false)]
|
|
[switch]$WhatIf,
|
|
|
|
[Parameter(Mandatory = $false)]
|
|
[string[]]$Tags,
|
|
|
|
[Parameter(Mandatory = $false)]
|
|
[string[]]$LegacyFluentMigratorContext,
|
|
|
|
[Parameter(Mandatory = $false)]
|
|
[Alias('EnableTeamCityServiceMessages')]
|
|
[switch]$LogTeamCityMessages,
|
|
|
|
[Parameter(Mandatory = $false)]
|
|
[Alias("PreventTeamCityBlocks")]
|
|
[switch]$NoTeamCityBlockMessages,
|
|
|
|
[Parameter(Mandatory = $false)]
|
|
[Alias("PreventTeamCityBuildProblems")]
|
|
[switch]$NoTeamCityBuildProblems,
|
|
|
|
[Parameter(Mandatory = $false)]
|
|
[Alias("PreventTeamCityMessages")]
|
|
[switch]$NoTeamCityMessages,
|
|
|
|
[Parameter(Mandatory = $false)]
|
|
[Alias("LogTeamCityErrorMessagesAsWarn")]
|
|
[switch]$LogErrorsAsWarn
|
|
)
|
|
|
|
$logLead = Get-LogLeadName
|
|
Write-Host "$loglead : running Invoke-AlkamiMigrationRunner on $($env:COMPUTERNAME) for $($env:USERNAME) at $(Get-Date)"
|
|
|
|
$overriddenParameterSetName = $PSCmdlet.ParameterSetName
|
|
|
|
if ($overriddenParameterSetName -eq 'TeamCityInstallPackagesByPackage') {
|
|
$PackageId = $Package.Name
|
|
$PackageVersion = $Package.Version
|
|
$PackageFeed = $Package.Feed.Source
|
|
|
|
# Same path aside from the above variables
|
|
$overriddenParameterSetName = 'TeamCityInstallPackages'
|
|
}
|
|
|
|
$writeToLog = $false
|
|
$logFilePath = ""
|
|
if (-not [string]::IsNullOrWhiteSpace($LogFileFolder)) {
|
|
if (-not (Test-Path -Path $LogFileFolder)) {
|
|
New-Item -ItemType Directory -Path $LogFileFolder -Force -WhatIf:$WhatIf | Out-Null
|
|
}
|
|
|
|
# $PID is a magic variable
|
|
$logFilename = "$MigrationTypeName.$PID.log"
|
|
|
|
if ((-not [string]::IsNullOrWhiteSpace($PackageId)) -and (-not [string]::IsNullOrWhiteSpace($PackageVersion))) {
|
|
$logFilename = "$PackageId.$PackageVersion.log"
|
|
}
|
|
|
|
$logFilePath = Join-Path -Path $LogFileFolder -ChildPath $logFilename
|
|
Write-Host "$logLead : Writing the output of this function to [$logFilePath]"
|
|
$writeToLog = $true
|
|
}
|
|
|
|
$finalMigrationRunnerPath = $MigrationRunnerPath
|
|
$finalMigrationTypeName = $MigrationTypeName
|
|
|
|
# Validate or set parameter information
|
|
switch ($overriddenParameterSetName) {
|
|
'TeamCityInstallPackages' {
|
|
Write-Host "$logLead : Running in packages mode"
|
|
$allRequiredParametersSupplied = $true
|
|
$requiredParameters = @('ConnectionString', 'DbmsUser', 'EnvironmentType', 'PackageFeed', 'SubscriptionHost', 'TempFolder')
|
|
foreach ($requiredParameter in $requiredParameters) {
|
|
if ([string]::IsNullOrWhiteSpace($PSCmdlet.MyInvocation.BoundParameters[$requiredParameter])) {
|
|
$allRequiredParametersSupplied = $false
|
|
Write-Warning "$logLead : Required parameter $requiredParameter was not provided. Please provide this value."
|
|
}
|
|
}
|
|
if (-not $allRequiredParametersSupplied) {
|
|
throw "$logLead : Please provide all required parameters."
|
|
}
|
|
}
|
|
'ORB' {
|
|
Write-Host "$loglead : Running in ORB mode"
|
|
$finalMigrationTypeName = 'ORB'
|
|
if ([string]::IsNullOrWhiteSpace($MigrationRunnerPath)) {
|
|
$finalMigrationRunnerPath = Get-MigrationRunnerExe -Runtime 'framework'
|
|
} else {
|
|
if (-not (Test-Path -Path $MigrationRunnerPath)) {
|
|
throw "$logLead : MigrationRunnerPath invalid or not present. Please ensure the runner exists"
|
|
}
|
|
$finalMigrationRunnerPath = $MigrationRunnerPath
|
|
}
|
|
|
|
if ([string]::IsNullOrWhiteSpace($ConnectionString)) {
|
|
throw "$logLead : Connection string must be supplied. Value provided was invalid."
|
|
}
|
|
if (-not (Test-Path -Path $OrbMigrateFolderPath)) {
|
|
throw "$logLead : OrbMigrateFolderPath invalid or not present. Please ensure the folder exists"
|
|
}
|
|
}
|
|
'DeveloperEnvironment' {
|
|
Write-Host "$loglead : Running in Developer Environment"
|
|
$finalMigrationTypeName = 'choco'
|
|
$validatedRuntime = Get-ValidatedRuntimeParameter -Runtime $Runtime
|
|
$finalMigrationRunnerPath = Get-MigrationRunnerExe -Runtime $validatedRuntime
|
|
}
|
|
'ManuallyApplyServiceAccount' {
|
|
$finalMigrationTypeName = 'ManuallyApplyServiceAccount'
|
|
}
|
|
'GrantRoleTenants' {
|
|
Write-Host "$loglead : Running in GrantRoleTenants mode"
|
|
$finalMigrationTypeName = 'GrantRoleTenants'
|
|
if ([string]::IsNullOrWhiteSpace($MigrationRunnerPath)) {
|
|
$finalMigrationRunnerPath = Get-MigrationRunnerExe -Runtime 'dotnetcore'
|
|
} else {
|
|
if (-not (Test-Path -Path $MigrationRunnerPath)) {
|
|
throw "$logLead : MigrationRunnerPath invalid or not present. Please ensure the runner exists"
|
|
}
|
|
$finalMigrationRunnerPath = $MigrationRunnerPath
|
|
}
|
|
if ([string]::IsNullOrWhiteSpace($ConnectionString)) {
|
|
throw "$logLead : Connection string must be supplied. Value provided was invalid."
|
|
}
|
|
}
|
|
'GrantRole' {
|
|
Write-Host "$loglead : Running in GrantRole mode"
|
|
$finalMigrationTypeName = 'GrantRole'
|
|
if ([string]::IsNullOrWhiteSpace($MigrationRunnerPath)) {
|
|
$finalMigrationRunnerPath = Get-MigrationRunnerExe -Runtime 'dotnetcore'
|
|
} else {
|
|
if (-not (Test-Path -Path $MigrationRunnerPath)) {
|
|
throw "$logLead : MigrationRunnerPath invalid or not present. Please ensure the runner exists"
|
|
}
|
|
$finalMigrationRunnerPath = $MigrationRunnerPath
|
|
}
|
|
if ([string]::IsNullOrWhiteSpace($ConnectionString)) {
|
|
throw "$logLead : Connection string must be supplied. Value provided was invalid."
|
|
}
|
|
}
|
|
'DbUserCreate' {
|
|
Write-Host "$loglead : Running in DbUserCreate mode"
|
|
$finalMigrationTypeName = 'DbUserCreate'
|
|
if ([string]::IsNullOrWhiteSpace($MigrationRunnerPath)) {
|
|
$finalMigrationRunnerPath = Get-MigrationRunnerExe -Runtime 'dotnetcore'
|
|
} else {
|
|
if (-not (Test-Path -Path $MigrationRunnerPath)) {
|
|
throw "$logLead : MigrationRunnerPath invalid or not present. Please ensure the runner exists"
|
|
}
|
|
$finalMigrationRunnerPath = $MigrationRunnerPath
|
|
}
|
|
if ([string]::IsNullOrWhiteSpace($DataSource)) {
|
|
throw "$logLead : Connection string must be supplied. Value provided was invalid."
|
|
}
|
|
if ([string]::IsNullOrWhiteSpace($DatabaseName)) {
|
|
throw "$logLead : Connection string must be supplied. Value provided was invalid."
|
|
}
|
|
if ([string]::IsNullOrWhiteSpace($DbmsUser)) {
|
|
throw "$logLead : Connection string must be supplied. Value provided was invalid."
|
|
}
|
|
}
|
|
}
|
|
|
|
$argumentList = @()
|
|
$argumentList += "MigrationTypeName=$finalMigrationTypeName"
|
|
|
|
# Convert potential array to a comma separated list of values
|
|
# When presented with a single string, does nothing. Yay auto-boxing.
|
|
# Depending on if you are using the pipeline and other things. Maybe, maybe not.
|
|
$finalDbmsUser = $DbmsUser -join ','
|
|
$finalDatabaseServiceAccount = $DatabaseServiceAccount -join ','
|
|
|
|
switch ($finalMigrationTypeName) {
|
|
'choco' {
|
|
$argumentList += "PackageId=`"$PackageId`""
|
|
$argumentList += "PackageVersion=`"$PackageVersion`""
|
|
|
|
if (-not [string]::IsNullOrWhiteSpace($PackageFeed)) {
|
|
$argumentList += "Feed=`"$PackageFeed`""
|
|
}
|
|
|
|
if (-not [string]::IsNullOrWhiteSpace($ConnectionString)) {
|
|
$argumentList += "ConnectionString=`"$ConnectionString`""
|
|
}
|
|
|
|
if (-not [string]::IsNullOrWhiteSpace($finalDbmsUser)) {
|
|
$argumentList += "DbmsUser=`"$finalDbmsUser`""
|
|
}
|
|
|
|
if (-not [string]::IsNullOrWhiteSpace($SubscriptionHost)) {
|
|
$argumentList += "SubscriptionHost=`"$SubscriptionHost`""
|
|
}
|
|
|
|
if (-not [string]::IsNullOrWhiteSpace($EnvironmentType)) {
|
|
$argumentList += "EnvironmentType=`"$EnvironmentType`""
|
|
}
|
|
|
|
if (($Parallelism -gt 0) -or ($Parallelism -eq -1)) {
|
|
$argumentList += "Parallelism=$Parallelism"
|
|
}
|
|
|
|
if (-not [string]::IsNullOrWhiteSpace($TempFolder)) {
|
|
$argumentList += "TempFolder=$TempFolder"
|
|
}
|
|
}
|
|
'orb' {
|
|
$argumentList += "ConnectionString=$ConnectionString"
|
|
$argumentList += "OrbMigrateFolderPath=$OrbMigrateFolderPath"
|
|
}
|
|
'ManuallyApplyServiceAccount' {
|
|
$argumentList += "ConnectionString=$ConnectionString"
|
|
$argumentList += "DatabaseServiceAccount=$finalDatabaseServiceAccount"
|
|
}
|
|
'GrantRoleTenants' {
|
|
$argumentList += "ConnectionString=$ConnectionString"
|
|
$argumentList += "DatabaseUserName=$finalDatabaseServiceAccount"
|
|
$argumentList += "RoleName=$($TenantRoleName -join ",")"
|
|
}
|
|
'GrantRole' {
|
|
$argumentList += "ConnectionString=$ConnectionString"
|
|
$argumentList += "DatabaseUserName=$finalDatabaseServiceAccount"
|
|
$argumentList += "RoleName=$($RoleName -join ",")"
|
|
}
|
|
'DbUserCreate' {
|
|
$argumentList += "DataSource=$DataSource"
|
|
$argumentList += "DatabaseName=$DatabaseName"
|
|
$argumentList += "UserNames=$DbmsUser"
|
|
}
|
|
default {
|
|
# Can't get here since we use ValidateSet, but all the same, clarity helps
|
|
throw "Unrecognized migration type specified."
|
|
}
|
|
}
|
|
if (($SqlTimeout -gt 0) -or ($SqlTimeout -eq -1)) {
|
|
$argumentList += "SqlTimeout=$SqlTimeout"
|
|
}
|
|
if (-not [string]::IsNullOrWhiteSpace($BankGuids)) {
|
|
$argumentList += "BankGuids=`"$BankGuids`""
|
|
}
|
|
|
|
if (-not (Test-Path -Path $finalMigrationRunnerPath)) {
|
|
throw "$logLead : Could not find the migration runner path [$finalMigrationRunnerPath]"
|
|
}
|
|
|
|
if ($null -ne $Tags) {
|
|
$argumentList += "Tags=$($Tags -join ',')"
|
|
}
|
|
|
|
if ($null -ne $LegacyFluentMigratorContext) {
|
|
$argumentList += "LegacyFluentMigratorContext=$($LegacyFluentMigratorContext -join ',')"
|
|
}
|
|
|
|
if ($WhatIf) {
|
|
$argumentList += "WhatIf=$WhatIf"
|
|
Write-Warning "$loglead : WHAT-IF MODE ENABLED!"
|
|
}
|
|
|
|
if ($LogTeamCityMessages) {
|
|
$argumentList += "LogTeamCityMessages=true"
|
|
}
|
|
|
|
if ($NoTeamCityBlockMessages) {
|
|
$argumentList += "NoTeamCityBlockMessages=true"
|
|
}
|
|
|
|
if ($NoTeamCityBuildProblems) {
|
|
$argumentList += "NoTeamCityBuildProblems=true"
|
|
}
|
|
|
|
if ($NoTeamCityMessages) {
|
|
$argumentList += "NoTeamCityMessages=true"
|
|
}
|
|
|
|
if ($LogErrorsAsWarn) {
|
|
$argumentList += "LogErrorsAsWarn=true"
|
|
}
|
|
|
|
$safeOutputString = ($argumentList -join "`n") -replace "password=.+;", "SECRET"
|
|
Write-Host "$loglead : Calling Invoke-CallOperatorWithPathAndParameters $finalMigrationRunnerPath with params:`n$safeOutputString"
|
|
if ($writeToLog) {
|
|
$results = Invoke-CallOperatorWithPathAndParameters $finalMigrationRunnerPath $argumentList
|
|
$results | ForEach-Object { if ($_.Contains("Error") -or $_.Contains("Fatal")) { Write-Host $_ } }
|
|
$results | Out-File -FilePath $logFilePath -Force -Encoding UTF8
|
|
Write-Host "$logLead : Log file written to the following path`n`n`t$logFilePath`n`n"
|
|
} else {
|
|
Invoke-CallOperatorWithPathAndParameters $finalMigrationRunnerPath $argumentList
|
|
}
|
|
|
|
if ($WhatIf -and -not $writeToLog) {
|
|
Write-Warning "$loglead : WHAT-IF MODE ENABLED!"
|
|
}
|
|
|
|
<#
|
|
This is what we would add to Install_Packages to make reading things easier, and to make it easier to copy-paste by producing it now
|
|
$tcSplat = @{
|
|
MigrationRunnerPath = $migratorExe
|
|
MigrationTypeName = 'choco'
|
|
PackageId = $package.Name
|
|
PackageVersion = $package.Version
|
|
Feed = $feed
|
|
ConnectionString = $masterDbConnectionString
|
|
DbmsUser = $DbmsUserString
|
|
SubscriptionHost = $subscriptionIP
|
|
EnvironmentType = $environmentType
|
|
TempFolder = $downloadDirectory
|
|
Parallelism = $parallelism
|
|
# Not accounted for in the new system (yet)
|
|
# Could cause issues for SDK developers tho ...
|
|
# Should not, because the package will already be installed on the system by the time this kicks off
|
|
# -FeedUserName $NugetCredential.UserName -FeedPassword (Get-PasswordFromCredential $NugetCredential)
|
|
}
|
|
|
|
Invoke-AlkamiMigrationRunner @tcSplat
|
|
#>
|
|
|
|
<#
|
|
This is what we add to TDC/Update-AlkamiDatabaseWithMigrationTool.ps1
|
|
$tcSplat = @{
|
|
MigrationRunnerPath = $migratorExe
|
|
MigrationTypeName = 'orb'
|
|
OrbMigrateFolderPath = $OrbMigrateFolderPath
|
|
ConnectionString = $masterDbConnectionString
|
|
Parallelism = $parallelism
|
|
}
|
|
|
|
Invoke-AlkamiMigrationRunner @tcSplat
|
|
#>
|
|
|
|
<#
|
|
# cole's debugging line from testing locally
|
|
--MigrationTypeName choco --packageId="Alkami.Migrations.UserReporting.Service.Host" packageVersion="1.2.4" feed="https://packagerepo.orb.alkamitech.com/nuget/choco.dev/" connectionString="Server=localhost;Database=AlkamiMaster;Integrated Security=true;" dbUser="corp\\dev.dbms$" SubscriptionHost=127.0.0.1 tempFolder="c:\temp" WhatIf=true EnvironmentType=Sandbox
|
|
# stuff from Install_Packages
|
|
& $migratorExe choco $package.Name $package.Version $feed $masterDbConnectionString $DbmsUserString $subscriptionIP $environmentType $downloadDirectory $parallelism -FeedUserName $NugetCredential.UserName -FeedPassword (Get-PasswordFromCredential $NugetCredential)
|
|
# TDC/Update-AlkamiDatabaseWithMigrationTool.ps1
|
|
& $migratorExe "orb" "$masterDbConnectionString" -OrbMigrateFolderPath "$dbMigrationPath"
|
|
#>
|
|
} |