When you develop web application you often have this scenario. Some people are testers, they are testing the application in dev all day, and they want always to test latest version. Moreover testers usually fills data into web application, so they want their data to be preserved between various deploy. If you simply clear all data in test database you will end with a lot of furious tester so do not even think to do this.
If a developer needs to change database schema, we need to automate not only the deploy of the web application, but we need also to sync test database with the latest changes. This is necessary so the test site can work with the new version, but old data is preserved for the happiness of the testers.
This is quite simple using TFS and Database project. The situation is this one
When a developer does a check-in, the build server grabs the tip from TFS, then it runs the builds script and deploy the new version of the site in the test web server. At the same time test database gets updated with the latest database schema.
Next we need the ability to automatically deploy changes to a specific database, this task is quite simple and you can find some details here in msdn, but we need to insert this command into the msbuild script. Here is the code:
<Target Name="AfterDropBuild"><Message Text="Deploy of project database" /> <MSBuild Projects="$(SolutionRoot)srcDbEditionNorthwindTestNorthwindTestNorthwindTest.dbproj" Properties="OutDir=$(DropLocation)$(BuildNumber)debug; TargetDatabase=NorthwindCiTest; DefaultDataPath=C:Program FilesMicrosoft SQL ServerMSSQL.4MSSQLData; TargetConnectionString=Data Source=VM2003R2_1SQLTEST%3Buser=sa%3Bpwd=Pa$$w0rd; DeployToDatabase=true;" Targets="Deploy"/> </Target>
Original post from Ricci Gian Maria