Entity Framework 6 Code First 迁移 - 生产的多个分支 [英] Entity Framework 6 Code First migrations - multiple branches for production

查看:32
本文介绍了Entity Framework 6 Code First 迁移 - 生产的多个分支的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的项目中,我们有一个分支模型,它有一个单独的开发分支,并且每个版本都有一个单独的分支.它可能看起来像这样:

In my project we have a branch model that has a separate development branch and has a separate branch for each release. It may look like this:

dev         ______       ______
           /           /      
master  --+---+----+---+---+----+----+--- (...)
           r1  \______/  r2 \_______/

所以我们在 dev 上开发,将它合并到 master,然后我们创建一个发布分支(r1,r2,...).

So we develop on dev merge it to master and then we create a release branch (r1, r2, ...).

我们想使用 EF 6(手动而非自动)迁移,但我们有一个不知道如何回答的问题.

We want to use EF 6 (manual not automatic) migrations but we have a question that we don't know how to answer.

想象一下:

dev         _(1)__       ____(4)
           /           /      
master  --+---+----+---+---+----+-(5)*-+--- (...)
           r1  \_(2)__/  r2 (3)______/

每个数字都是一次迁移.它们已添加到每个分支的源代码控制中,并已应用于我们项目的生产实例的数据库(我们支持多个版本一段时间只是为了修复)所以我们不能降级它们,它们只能使用 Up().星号标记了我们要分析的时间点.我们希望迁移以这种方式工作:

Each number is a migration. They have been added to the source control on each branch AND have been applied to the databases of production instances of our project (we support multiple releases for some time just for fixes) so we cannot downgrade them, they can go only Up(). Asterisk marks the point in time we want to analyze. We want migrations to work this way:

  • r1 数据库仅应用了迁移 (2)
  • r2 数据库已应用 (1)、(2) 和 (3)
  • 主数据库已应用 (1)、(2)、(4) 和 (5)
  • 开发数据库已应用 (1)、(2) 和 (4)

此外:

  • 我们不能丢失数据库中的一点数据
  • r1 数据库必须可以无错误地更新到 r2(或任何其他未来版本)数据库,因此它具有与所有对应的 r2 数据库(创建为 r2 或从早期版本更新)相同的数据库结构到它的代码优先模型.

可以吗?如果是,怎么做?

Can that be done? If yes, how?

如果您需要更多详细信息,请询问.

If you need more details, please ask.

推荐答案

我可以尝试解释在每种情况下你可以做什么,但它非常复杂,我无法像这里解释的那样解释它:

I could try to explain what you can do in each case, but it's quite complex and I would not be able to explain it as well as it's explained here:

团队环境中的代码优先迁移

虽然它很复杂,并且您必须经常参考此文档来合并分支,但如果您遵循此文档,您会发现它可以解决您的所有问题.

Although it's complex and you'll have to refer to this document frequently to merge the branches, if you follow this document you'll see that it solves all your questions.

免责声明:我知道 SO 应该是自包含的,但解释是如此复杂和冗长,以至于我什至无法在此处添加摘要.我希望链接的 MSDN 文档不会消失.

Disclaimer: I know SO should be self contained, but the explanation is so complex and long that I can't even add an abstract here. I hope that the linked MSDN docs don't dissapear.

这篇关于Entity Framework 6 Code First 迁移 - 生产的多个分支的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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