I'm coming from asp.net Web Forms switching to MVC and entity framework code first approach. I have a question. How can I set up my environment to deploy to production?
I'm using Visual Studio 2012 and deploys a web deploy package. Locally I have SQL Express and in production, I have SQL Server 2008.
What I want is to develop an test locally on my pc and from time to time deploy my solution to production with a web deploy package. I don't want to run migrations in the production system, instead, I want to generate scripts from visual studio which I then can append to production SQL.
I tried to:
- Create Initial migration in dev.
- Update database locally
- Generate script, update-database -script -sourcemigration:InitialCreate
- Apply this script in production
- Deploy the application to production
Is this the correct approach? What about my migrations that will run locally, will they not in production to when I deploy because of my migrations code?
In global.asax
Migrator.RunMigrations();
where RunMigrations is a static method in a custom Migrator class like this
public class Migrator
{
public static void RunMigrations()
{
var migrator = new Configuration();
var dbMigrator = new System.Data.Entity.Migrations.DbMigrator(migrator);
if (dbMigrator.GetPendingMigrations().Any())
{
dbMigrator.Update();
}
}
}