实体框架6代码首次迁移 - 多个生产分支 [英] Entity Framework 6 Code First migrations - multiple branches for production

本文介绍了实体框架6代码首次迁移 - 多个生产分支的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的项目中,我们有一个分支模型,它有一个单独的开发分支,每个版本都有一个单独的分支。它可能如下所示:

 开始______ ______ 
/ \ / \
主 - + --- + ---- + --- + --- + ---- + ---- + ---(...)
r1 \ ______ / r2 \ _______ /

所以我们在开发上合并它,然后我们创建一个发行版分支(r1,r2, ...)。



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



想象一下:

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

每个数字都是迁移。它们已被添加到每个分支的源代码控制中,并已被应用到我们项目的生产实例的数据库(我们支持多个版本一段时间仅用于修复),因此我们无法降级,只能使用Up()。星号标志着我们要分析的时间点。我们希望迁移工作方式如下:




  • r1数据库只应用迁移(2)

  • r2数据库应用了(1),(2)和(3)

  • 主数据库有(1),(2),(4)和(5) b $ b
  • dev数据库已应用(1),(2)和(4)



此外:




  • 我们不能在数据库中丢失一些数据

  • 必须可以更新r1数据库到r2(或任何其他未来版本)数据库,没有错误,因此它具有与所有r2数据库(创建为r2或从早期版本更新)相同的数据库结构,与其代码第一个模型相对应。



可以做到吗?如果是的话,如何?



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

解决方案>

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



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



虽然它很复杂,你必须频繁地参考这个文档来合并分支机构,如果你遵循这个文件,你会看到它解决了你所有的问题。



免责声明:我知道这应该是自包含的,但是这个解释太复杂了,我甚至不能在这里添加一个摘要。我希望链接的MSDN文档不会消失。


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 \_______/

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

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

Imagine this:

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

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 database has only migration (2) applied
  • r2 database has (1), (2) and (3) applied
  • master database has (1), (2), (4) and (5) applied
  • dev database has (1), (2) and (4) applied

Moreover:

  • we cannot lose a bit of data in our database
  • it has to be possible for r1 database to be updated to r2 (or any other future release) database with no errors so it has the same database structure as all r2 databases (created as r2 or updated from earlier versions) that corresponds to its code first model.

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:

Code First Migrations in Team Environments

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.

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.

这篇关于实体框架6代码首次迁移 - 多个生产分支的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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