Work around for lack of dynamic variables - rollback
jtucker@inflexxion.com
Posts: 20
Red Gate DM is a fine tool, but lacks dynamic variables. That is, a variable that is set at the time of deployment. We need the ability to run a deployment and if it doesn't work properly, revert it. To do so we package up the deployment once and have special code to revert if a variable $IsRollback is true. We simply look at the $RedGateDeploymentComments variable (that IS dynamic - the only one) for a special string.
# This IsRollingBack routine looks at whether the current project is rolling back the deployment just done. # It should be called by ALL Deploy, PreDeploy or PostDeploy scripts. # It utilizes a side-database hosted by ILBUILD02 called DynamicDeployment on SQL2012 instance # Signature is IsRollingBack($environment, $projectName, $packageDirectoryPath, $forceImportSQLPS) # where $environment is {Local, Dev, QA, Staging, Live} # projectName is the name found in Red Gate DM {painCAS, Assessment Platform, InsideADHD, ...} # packageDirectoryPath is the path to which we extract binaries for deployment on the target web server without a trailing backslash (see Variables for your project) # forceImportSQLPS should be "true" unless testing this locally function IsRollingBack($environment, $projectName, $packageDirectoryPath, $forceImportSQLPS) { # These values are constant since we only look at dev for these settings "Entering Powershell Library: IsRollingBack function..." | Write-Host "PackageDirectoryPath is " + $packageDirectoryPath | Write-Host "Project is " + $projectName | Write-Host "Environment is " + $environment | Write-Host if ([string]::IsNullOrEmpty($packageDirectoryPath)) { $packageDirectoryPath = "D:\On Deck Circle" } $cur = Get-Location set-location $packageDirectoryPath $IsRollbackResultsFile = $packageDirectoryPath + "\IsRollbackResults.txt" "Output of IsRollback in " + $IsRollbackResultsFile | Write-host $RedGateDeploymentComments | Select-String -Pattern "DoRollbackSaveTheWhales " -AllMatches | out-file $IsRollbackResultsFile -Force # this stored procedure call will query all the dynamic deployment settings for this environment and project, but we only are concerned with rollback # We attempt to select just that row. If there are no rows in the output file, then rollback is false (but we better flag it). If True is found in the row, then # rollback is true. $IsRollingBackTrueRowCount = (Get-Content $IsRollbackResultsFile | Select-String "DoRollbackSaveTheWhales" | Measure-Object).Count if ($IsRollingBackTrueRowCount -eq 1) { return 1 } return 0 }