Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the best way to run EF migration on production server?

What I have:

  • VS2015
  • ASP.NET 5 MVC 6 Project
  • EF 7
  • Some migrations for my project
  • Azure website
  • I publish via VS "Publish.." wizzard.

What I need:

  • I need to know what is the best way to run migrations on the production DB.
  • I prefer something that can be automated. The best solution will be something integrated in the "Publish" wizard.

Notes:

  • I'm running my migrations on my dev station with "dnx ef database update". I guess I can use the webapp PS console but... doesn't seems like the proper way.

  • I know I can generate a SQL script for the migration but this seems to be too manual.

  • I remember that the "Publish" wizard had option "Execute EF migrations" in the past. Can't see it now.

like image 339
f0rt Avatar asked Apr 17 '16 18:04

f0rt


People also ask

Is entity framework used in production?

Entity Framework can be useful for getting up and running quickly with a database application, but when it comes to deployment, EF's built-in data migration feature doesn't inspire confidence.

How do I run down EF core migration?

Delete your Migrations folder. Create a new migration and generate a SQL script for it. In your database, delete all rows from the migrations history table. Insert a single row into the migrations history, to record that the first migration has already been applied, since your tables are already there.


1 Answers

It depends on who has control over the production DB (dev team or separate DBA team).

In a customer project that I worked on, each developer had their own copy of the DB, where they tested all their migrations. Once the application code and migration code got checked in, we used TeamCity as a CI server to deploy the website, update the staging DB, and run unit tests & integration tests.

We provided the SQL scripts (generated by EF) to the DBA team to run against the production DB. Our dev team never touched the production DB.

If you're allowed to update the production DB, you can do it yourself. But I would highly recommend inspecting and then running EF-generated scripts that you can roll back if necessary. Also, don't forget to back up the production DB as needed.

Since you want automation (and if you are comfortable with it), you can use your CI system to update your production DB, the way my team and I updated our staging DB.

Hope that helps!

like image 142
Shahed C - MSFT Avatar answered Oct 14 '22 01:10

Shahed C - MSFT