Powershell Deployment speed
AdamBowler
Posts: 8 New member
I'm trying to speed up our automated releases but the biggest chunk is taken up by the powershell deployment with SQL Change Automation.
We have a project for our customer databases and loop through these databases running the powershell deployment script in our release. but this is gradually increasing in time as we add more scripts. We are aware we can rebase or consolidate the scripts but having to do this too regularly is a maintenance burden.
Has any encountered this or have an alternative solution?
Thanks,
Adam
Tagged:
Answers
Redgate Software
Redgate Software
It will also depend, of course, on what's in the scripts to be deployed. If one of them does a massive index rebuild, fox example, it's bound by the performance of SQL Server itself.
Redgate Software
Redgate Software
Redgate Software
Write-host "customercont=" + ($customers.length)
write-host $customers
$i = 1
foreach ($customer in $customers)
{
Write-Host "Executing script for $($customer.dbname) ($i of $($customers.length))"
write-host "dbname=$($customer.dbname)"
& { $DatabaseServer=$($customer.hostname); $DatabaseName = $($customer.dbname); $ReleaseVersion = $ReleaseVersion; $UseWindowsAuth = $false; $DatabaseUserName = $($customer.dbusername); $DatabasePassword = $DatabasePassword; $ForceDeployWithoutBaseline = $ForceDeployWithoutBaseline; & $PathToDatabaseScript}
$i++
}
dbname=databaseName
If you require that all SqlCmd variable values be passed in explicitly, specify UseSqlCmdVariableDefaults=False.
Using SQL Server Authentication
Using default value for DefaultFilePrefix variable: ReadyRollCustomer
Using default value for DefaultDataPath variable: S:\Databases\
Using default value for DefaultLogPath variable: S:\Databases\
Using default value for DefaultBackupPath variable: S:\Backups\
Starting 'databaseName' Database Deployment to 'server ip'
Sqlcmd.exe -b -S "serverIp" -v DatabaseName="databaseName" ReleaseVersion="version" DeployPath="S:\Release Supporting Functions\RrDatabaseScripts\solution name\version\projectName\" ForceDeployWithoutBaseline="True" DefaultFilePrefix="ReadyRollCustomer" DefaultDataPath="S:\Databases\" DefaultLogPath="S:\Databases\" DefaultBackupPath="S:\Backups\" -d "databaseName" -i "S:\Release Supporting Functions\RrDatabaseScripts\solution name\version\ReadyRollCustomer\ReadyRollCustomer_Package.sql" -U "username"
The database already exists. An incremental deployment will be performed.
----- executing pre-deployment script "Pre-Deployment\01_Create_Database.sql" -----
# Beginning transaction
***** EXECUTING MIGRATION "Migrations\1.1.0-Changes\file_name.sql", ID: {5d53085d-0483-4717-bca2-3f1b5dd7b1dd} *****
***** FINISHED EXECUTING MIGRATION "Migrations\1.1.0-Changes\file_name.sql", ID: {5d53085d-0483-4717-bca2-3f1b5dd7b1dd} *****
***** EXECUTING MIGRATION "Migrations\1.1.0-Changes\file_name.sql", ID: {405ab026-2d9f-404d-a52a-e01efd8863c3} *****
***** FINISHED EXECUTING MIGRATION "Migrations\1.1.0-Changes\file_name.sql", ID: {405ab026-2d9f-404d-a52a-e01efd8863c3} *****
***** EXECUTING MIGRATION "Migrations\1.1.0-Changes\file_name.sql", ID: {e78b1b52-ed7c-4eef-9983-e95f0cb20be5} *****
***** FINISHED EXECUTING MIGRATION "Migrations\1.1.0-Changes\file_name.sql", ID: {e78b1b52-ed7c-4eef-9983-e95f0cb20be5} *****
***** EXECUTING MIGRATION "Migrations\1.1.0-Changes\file_name.sql", ID: {2de357b0-23da-487c-9ec8-e4a8016feaa0} *****
***** FINISHED EXECUTING MIGRATION "Migrations\1.1.0-Changes\file_name.sql", ID: {2de357b0-23da-487c-9ec8-e4a8016feaa0} *****
***** EXECUTING MIGRATION "Migrations\1.1.0-Changes\file_name.sql", ID: {773ca2a1-2d39-41c1-9e79-25d527c9e308} *****
***** FINISHED EXECUTING MIGRATION "Migrations\1.1.0-Changes\file_name.sql", ID: {773ca2a1-2d39-41c1-9e79-25d527c9e308} *****
***** EXECUTING MIGRATION "Migrations\1.1.0-Changes\file_name.sql", ID: {cce6ade6-1600-4b65-9f1c-64af76b484c5} *****
***** FINISHED EXECUTING MIGRATION "Migrations\1.1.0-Changes\file_name.sql", ID: {cce6ade6-1600-4b65-9f1c-64af76b484c5} *****
***** EXECUTING MIGRATION "Migrations\1.1.0-Changes\file_name.sql", ID: {72544fa5-1d47-4613-98ab-4886c9473099} *****
***** FINISHED EXECUTING MIGRATION "Migrations\1.1.0-Changes\file_name.sql", ID: {72544fa5-1d47-4613-98ab-4886c9473099} *****
***** EXECUTING MIGRATION "Migrations\1.1.0-Changes\file_name.sql", ID: {d1e08785-05ce-4b83-94ee-9ab72b9fb4e3} *****
***** FINISHED EXECUTING MIGRATION "Migrations\1.1.0-Changes\file_name.sql", ID: {d1e08785-05ce-4b83-94ee-9ab72b9fb4e3} *****
***** EXECUTING MIGRATION "Migrations\1.1.0-Changes\file_name.sql", ID: {c6994e6e-117c-445c-81a5-55d90554048a} *****
***** FINISHED EXECUTING MIGRATION "Migrations\1.1.0-Changes\file_name.sql", ID: {c6994e6e-117c-445c-81a5-55d90554048a} *****
***** EXECUTING MIGRATION "Migrations\1.1.0-Changes\file_name.sql", ID: {851bda30-3808-4736-bb73-fe8ab396b1b9} *****
***** FINISHED EXECUTING MIGRATION "Migrations\1.1.0-Changes\file_name.sql", ID: {851bda30-3808-4736-bb73-fe8ab396b1b9} *****
***** EXECUTING MIGRATION "Migrations\1.1.0-Changes\file_name.sql", ID: {4d4f4a23-0da8-4c91-b23c-c53369170629} *****
***** FINISHED EXECUTING MIGRATION "Migrations\1.1.0-Changes\file_name.sql", ID: {4d4f4a23-0da8-4c91-b23c-c53369170629} *****
***** EXECUTING MIGRATION "Migrations\1.1.0-Changes\file_name.sql", ID: {5e64a6f2-f49d-400c-a53d-50a503943a34} *****
***** FINISHED EXECUTING MIGRATION "Migrations\1.1.0-Changes\file_name.sql", ID: {5e64a6f2-f49d-400c-a53d-50a503943a34} *****
# Committing transaction
----- executing post-deployment script "Post-Deployment\01_Finalize_Deployment.sql" -----
Deployment completed successfully.
Skipping schema snapshot deployment as a snapshot file could not be found. As a result, preview/drift reports will be unavailable for the next deployment. To enable schema snapshot creation, specify the ShadowServer property in your build configuration https://www.red-gate.com/sca/continuous-integration
I would suggest using the SQL Change Automation PowerShell cmdlets (https://documentation.red-gate.com/sca3/automating-database-changes). You'd use the build/package cmdlets to create a single deployment package, and then use the release cmdlets for each target database to create and execute a targeted deployment script for each one that will only contain the undeployed migrations for that database.
Redgate Software