user1037747
user1037747

Reputation: 1373

Entity Framework Core migrations through CI and CD in Azure DevOps

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

Upvotes: 7

Views: 6105

Answers (1)

Joe Brinkman
Joe Brinkman

Reputation: 1892

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.

Upvotes: 12

Related Questions