6
votes

I want to add Build and Release pipelines in Azure Devops for my .Net Core application. Application uses EF Core migrations.

I used the solution provided for example here: https://blog.clear-measure.com/2019/01/07/run-ef-core-migrations-in-azure-devops/

It works fine. I generate script during build, publish it as another artifact and then use it to run against database during release step.

But how to deal with a situation that I want to revert the changes. Here I see two scenerios:

  1. It would be great if somehow I could just click Deploy on the previous release and this way get back to the previous working version of the app (and revert the DB as well).

  2. Revert the changes in the repo, deleting migrations that might have been created between releases and start build and deploy process again. How to revert already added migration to the DB?

Is even the first approach possible ?

Thanks for you help!

2

2 Answers

0
votes

You would revert the migration via EF Core similar to the way you add a migration. Then commit and push and run the pipeline.

enter image description here

https://docs.microsoft.com/en-us/ef/core/managing-schemas/migrations/#revert-a-migration

0
votes

First scenario is possible.

In your release pipeline, you can find the retained historical releases. enter image description here

Select the previous release you want to revert back to, click redeploy and it will roll back to the previous version.enter image description here