在Azure DevOps中通过CI和CD进行实体框架核心迁移 [英] Entity Framework Core migrations through CI and CD in Azure DevOps

查看:78
本文介绍了在Azure DevOps中通过CI和CD进行实体框架核心迁移的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经创建了一个Entity Framework Core项目,并且工作正常,并且能够通过Visual Studio生成迁移.

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

但是我想通过Azure Devops CI生成SQL脚本,并通过CD进行部署.我做不到.

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

通过添加此命令

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

这将生成整个SQL脚本.但是下次,如果我必须对模型进行任何更改,它将再次重新生成整个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 ?

这是我的配置项在Azure DevOps中的外观

This is how my CI looks in Azure DevOps

推荐答案

您可以使用--idempotent选项,该选项会将代码添加到脚本中,以便仅将适当的迁移应用于数据库.这实际上使sql脚本等效于在程序包管理器控制台中运行 update-database .

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.

这篇关于在Azure DevOps中通过CI和CD进行实体框架核心迁移的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆