Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to migrate Entity Framework DB on publish via MsDeploy

For my current project i would prefer to update my database to the correct version on publish instead of first run via the App_Start.

It seems that there is support for manual upgrades via a commandline tool 'migrate.exe' which is supplied together with Entity Framework (5.0 rc2). But i can not find any information about how other people have combined this tool together with msdeploy to upgrade the database on publish instead of first run.

I have found the following page which explains how to use the migrate.exe tool: http://blog.overridethis.com/blog/post/2012/03/13/Automating-EF-43x-Data-Migrations-in-your-Build.aspx

But this forces me to somehow 'know' the connectionstring information.

My optimal solution would be something like:

  1. connectionstring is configured in setParameters.xml file for replacement on publish
  2. on publish after publish of codebase migrate.exe gets called with correct connectionstring

It seems that what i search for is an 'entity framework MSDeploy provider' (see: http://blogs.msdn.com/b/adonet/archive/2012/01/12/ef-4-3-beta-1-released.aspx) but it seems that they abandoned that option some time ago

like image 323
Mark van Straten Avatar asked Aug 21 '12 19:08

Mark van Straten


People also ask

How do I migrate in Entity Framework?

Step 1 − Before running the application you need to enable migration. Step 2 − Open Package Manager Console from Tools → NuGet Package Manger → Package Manger Console. Step 3 − Migration is already enabled, now add migration in your application by executing the following command.

How do I move my EF core database?

Adding a Migration So, firstly, you need to create a migration. Open the Package Manager Console from the menu Tools -> NuGet Package Manager -> Package Manager Console in Visual Studio and execute the following command to add a migration.

How do I update my database in migration?

After creating a migration file using the add-migration command, you have to update the database. Execute the Update-Database command to create or modify a database schema. Use the –verbose option to view the SQL statements being applied to the target database.


1 Answers

You have two options:

  1. Configure Visual Studio Databases option in the Publish Profile; or
  2. Configure your project properties on Package/Publish SQL Tab.

I didn't use any of them yet but I was researching because I'll have the exactly same scenario.

like image 188
Douglas Gandini Avatar answered Nov 15 '22 21:11

Douglas Gandini