Create target database
"DLM Automation works with your CI server and release management system, so you test, build, and release your database alongside your application code." Unfortunately, DLM only allows for the release of updates to existing databases -- suppose the target database doesn't yet exist? Deploying a NuGet package ought to allow for the possibility of initializing a new database.
-
AdminKendra (Admin, Redgate) commented
Apologies on the late update. As Andy commented, this is supported, so I am marking this as completed.
-
Andy Cater commented
This is supported in the current version of SQL Change Automation, unless I am missing something?
-
Steve Grier commented
I second this. I have a work-around, but I don't like it. It smells a bit like technical debt.
I ended up creating a step prior to the DLM Release that uses sqlcmd.exe to create the target database if it doesn't exist. I've included a copy of my sqlcmd call as it is fairly generic. I'm using TFS and ReleaseManagement, so this goes in a Command Line task.
Note the version of sqlcmd i'm using is older because that is what was available on my build agent, but I've successfully run this task targeting a SQL 2016 server. I'm using an on-premise TFS 2015 server.
Lastly, TFS uses build and release variables in the format $(variablename). Those will be set per release or per target environment as needed.
"C:\Program Files\Microsoft SQL Server\110\Tools\Binn\sqlcmd.exe" -S $(TargetServerName) -U $(DeploymentLoginName) -P $(DeploymentLoginKey) -Q "IF NOT EXISTS (SELECT 1 FROM sys.databases WHERE name = '$(TargetDatabaseName)') CREATE DATABASE [$(TargetDatabaseName)]"