Entity Framework Core migrations through CI and CD in Azure DevOps

azure-devops entity-framework-core

Question

I have created an Entity Framework Core project and it is working fine and I am able to generate migrations through Visual Studio.

But I want to generate SQL scripts through Azure Devops CI and deployment through CD. I am unable to do it.

By adding this command

dotnet ef migrations script --project $(Build.SourcesDirectory)\SampleEFCoreApplication\SampleEFCoreApplication.csproj -o $(build.artifactstagingdirectory)\migrations\scripts.sql

This generates the entire SQL script. But next time, if I have to make any changes in my model, it again regenerates the entire SQL script. But I only want the changes to appear if I make any model changes. How can I do that ?

This is how my CI looks in Azure DevOps

enter image description here

1
0
9/20/2019 12:24:28 PM

Accepted Answer

You can use the --idempotent option which will add code to the script so that only the appropriate migrations are applied to the database. This effectively makes the sql script the equivalent of running update-database in the package manager console.

3
10/3/2019 4:59:28 PM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow