1

I am setting up an Azure Release Pipeline and I need to execute any pending DB Migrations as part of the release.

I have been scouring the internet for over an hour and everything I can find is about dotnet Core, while the database is EF6 on .Net Framework, not dotnet Core (I've done this several times before for Core).

The problem, as I see it, is that EF6 works using Visual Studio's built in Package Manager Console - This just doesn't exist in an Azure Pipeline; It's a Visual Studio weirdness.

There seems to be several ways I can skin this cat, in my head, but I can't figure out how to start with either of them within the context of the pipeline...

OPTION 1: Run the Migrations on the Pipeline - but... how?

OPTION 2: SQL Scripts - Requires running the Package Manager to generate them so they can be run (if I could do that on the pipeline then I'd just run it anyway so these would have to be created locally and committed with the code which is somewhat backward as a solution IMO)

OPTION 3: Write a console app - Do I really have to do this??

Keith Jackson
  • 3,078
  • 4
  • 38
  • 66

2 Answers2

0

You can try Entity Framework Migration Extensions.

This task allows a Build / Release to provide database connection parameters and execute an Entity Framework 6 migration against the database.

  1. Build your project to an output folder and include the migrate.exe executable that comes with Entity Framework 6.
  2. Create an automated build that packages up your files and makes them accessible during a Release.
  3. Create a Release definition for the relevant Build
  4. Add an EF6 Migration task. Once that task is added to an environment within the release, you'll need to enter the appropriate parameters to configure it. All file path parameters should be within the file system for the build, none of them are for TFS source control paths.

You can also check this article.

Krzysztof Madej
  • 32,704
  • 10
  • 78
  • 107
  • I don;t seem to have a migrate.exe in my /packages/EntityFramework.6.4.4/tools directory, I just have ef6.exe - It appears the this replaces migrate.exe but I can't find any docs for it anywhere (typical!) – Keith Jackson Oct 13 '20 at 08:29
  • This could be useful to anyone here until Microsoft update the non-existent docs: https://github.com/dotnet/EntityFramework.Docs/issues/1740 - This contains a table with a kind of translation matrix between the two. – Keith Jackson Oct 13 '20 at 09:48
  • Thanks for the sharing, can the ef6.exe command-line run the migrations for you successfully? – LoLance Oct 16 '20 at 09:08
0

The answer here is to use the ef6.exe command line tool and make sure it gets shipped with your build.

This could be useful to anyone here until Microsoft update the non-existent docs: http://github.com/dotnet/EntityFramework.Docs/issues/1740 - This contains a table with a kind of translation matrix between the two.

Keith Jackson
  • 3,078
  • 4
  • 38
  • 66