简体   繁体   中英

Continuous delivery of SQL Database to Windows Azure by using Team Foundation Service

I have Continuous delivery from TFS running to Azure for the C# project and this is fine.

I now want to the Continuous delivery to work with my SQL database.

Currently I have a SQL 2008 R2 database which holds the database.

What is the best option to ensure I can deliver using Continuous delivery from TFS to include the database changes?

The important factor is it needs to be automated upon checkin to TFS.

I've just run into this problem and found guidance hard to come by but have managed it in my application, I'm very new to MVC and Azure so excuse me if this isn't too detailed.

Here's what I did;

In my Global.asax.cs Application_start() I added:

Database.SetInitializer(new MigrateDatabaseToLatestVersion<ApplicationDbContext, Configuration>());

Where ApplicationDbContext is the name of your context. Remember to add references to your Models class and Migrations classes.

When you do this, I think migrations are run on your database when the context is first called and it does not drop and recreate your database.

The one problem I had was that I was getting an error saying that objects already existed in the database because none of the migration data in the __MigrarionHistory table was in there so it tried to create the database from scratch. Luckily my application wasn't live yet so I could delete the tables and commit to TFS and it recreated everything and included all of the __MigrationHistory so now, any new code first migrations are run on the first hit and the database is updated. I wouldn't know what to do if this database was live!

Hope that helps

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM