Page 63 - MSDN Magazine, November 2017
P. 63
Figure 6 The Advanced Publish Settings Dialog Box
When you perform an incremental deployment over an existing database, there’s a chance that the latest script will need a migration. That means I have to deploy the migration database, as well. I’ll do this by deploying the AdventureWorks.Database.Migration project first, followed by AdventureWorks.Database. Be sure the “Always re-create database” option is unchecked under the Advanced Deployment Options area of the Advanced Publish Settings dia- log box, as shown in Figure 6.
If you’re running from the command prompt, the command is:
SqlPackage.exe /Action:Publish /SourceFile:"AdventureWorks.Migration. Database.dacpac" /tdn:<<DatabaseName>> /tsn:"<<SQL Instance>>" /p:CreateNewDatabase = False
SqlPackage.exe /Action:Publish /SourceFile:"AdventureWorks.Database.dacpac" /tdn:<<DatabaseName>> /tsn:"<<SQL Instance>>" /p:CreateNewDatabase = False
Configuring the TFS
Build to Deploy
Continuous Migration
The goal is to automate migrations just like continuous integration, so that the build server does the data migration and makes it available to developers and testers once the build is triggered. The next step is to configure the build’s release tasks.
To create tasks for the build, you should first be aware of creating a Continuous Integration build. If you aren’t, be sure to read through the tutorial posted on the Microsoft Visual Studio site at bit.ly/2xWqtUx.
Once you’ve created the build tasks, you need to create the deploy tasks for the database. In this exam- ple, you must add two deploy tasks: one for the AdventureWorks.Data- base.Migration project and the other
for the AdventureWorks.Database project. The deploy task will look something like Figure 7.
Fill in the detail and set up the trigger based on your require- ment. Once the build is up and running you will have set up a Continuous Data Migration for your application.
Wrapping Up
In this article, I explained the importance of continuous data migra- tion on a project that involves multiple phases of release, and how to achieve it using Visual Studio and TFS. Continuous data migra- tion helps you reduce both development effort and migration bugs. In my experience, I’ve been able to gain as much as 40 percent of migration effort in terms of development. It also got rid of the
Migration Phase in the project. Integration of migration scripts to TFS is as important as the migration scripts themselves. The continuous data migration process is of no use if you aren’t deploying it as a part of daily build. “Fail early, fail fast” is the man- tra to remember in software develop- ment, and continuous data migration setsyouuptodoexactlythat. n
Jebarson Jebamony is a senior consultant with Microsoft Services and designs and builds solutions for Microsoft, its partners and customers. He has more than 14 years of technical experience and has worked on many Microsoft technologies in that time.
Thanks to the following Microsoft tech- nical experts for reviewing this article: Sagar Dheram and Shrenik Jhaveri
November 2017 59
Figure 7 The Deploy Task msdnmagazine.com