Slinky
Slinky

Reputation: 5832

MVC 3 EF Migrations on Multiple Database Instances

All,

I am trying to solve a seemingly very common problem of updating our development database and our production database simultaneously, whenever a change is made to our development database.

Something like this:

PM > Add-Migration AddMyNewColumnColumnToMyTable
PM > update-database - dev
PM > update-database - prod 

I've seen solutions while researching this but nothing yet that is as simple and straight forward as running SQLCompare on the dev and production databases and then exporting and running a SQL script on the production database.

How are you all doing this?

Thanks

Upvotes: 1

Views: 125

Answers (1)

Admir Tuzović
Admir Tuzović

Reputation: 11177

Well as long as both of your databases are following the same migration stream meaning both are created from same migration and updated in same chronological order, you should not have any issues with using same migrations.

What you can do is create two connection strings in your web.config (or app.config) and when you are updating database use the following syntax:

update-database -connectionStringName YourProdDbContextConnectionStringName

So assume you have 5 migrations total: Migration1, Migration2, Migration3, Migration4 and Migration 5.

If your production is updated up to Migration3, and you've made Migration4 and Migration5 on your dev database, issuing update-command with different connection string to your production will apply Migration4 and Migration5 at the same time, without any problems.

Upvotes: 1

Related Questions