如何管理多个分支的一个项目迁移? [英] How to manage Migrations in a project with multiple branches?

查看:155
本文介绍了如何管理多个分支的一个项目迁移?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用实体框架4.3与code-第一种方法的ASP.NET MVC3项目。我用迁移,以保持数据库保持最新。

I have an ASP.NET MVC3 project that uses Entity Framework 4.3 with the code-first approach. I use Migrations to keep the database up-to-date.

该项目是源代码控制之下,我有多家分公司。我刚刚意识到的是,将会有一个问题,当我要合并我的树枝插入主之一。既然我已经在这两个分支创建迁移文件,会有重叠的迁移,当我合并,这可能会导致冲突。

The project is under source-control and I have a number of branches. What I just realized is that there will be a problem when I want to merge one of my branches into the master. Since I have created migration-files in both branches, there will be overlapping migrations when I merge, which will probably cause conflicts.

是否有多个分支的一个项目来管理迁移的好办法?

Is there a good way to manage Migrations in a project with multiple branches?

更新

一种方法是合并,然后删除创建的,而部门是分开的所有迁移文件,然后创建一个拥有分支的创建,直到它被合并了。这时候所有的变化之一新的迁移文件对于开发环境,你可以转储数据库,并与所有迁移文件的重新构建它的工作。那么问题将是带电的环境。既然你不能回退分支而不丢失数据的风险的创建时间,就会有冲突,当您尝试使用新的迁移文件以更新活动数据库。

One way would be to merge, then delete all migration-files created while the branches were separate, and then create one new migration file that holds all changes from the time the branch was created until it was merged back in. This would work for the dev-environment where you can dump the database and re-build it with all the migration-files. The problem then would be the live-environment. Since you couldn't roll back to the time the branch was created without the risk of loosing data, there will be a conflict when you try to use your new migration-file to update the live database.

推荐答案

我想接受的答案是不正确。有一个<一href=\"http://stackoverflow.com/questions/10171658/lose-ef-$c$c-first-migration-when-working-on-different-tfs-branches\">much用于处理实体框架迁移合并冲突的一个类似的问题的更好的解决方案。

I think the accepted answer is incorrect. There is a much better solution for handling entity framework migration merge conflicts on a similar question.

所有你需要做后合并为目标分支重新脚手架迁移的元数据。那是你不rescaffold向上/向下code,就在国家的RESX文件。

All you need to do after a merge is to re-scaffold the meta data of the migration in the target branch. That is you do not rescaffold the up/down code, just the state in the resx-file.

add-migration [the_migration_to_rescaffold_metadata_for]

虽然如果在合并不同的迁移以这样的方式改变了数据库的迁移不再可运行或给出了意想不到的结果此过程将失败。话虽这么说 - 我相信这是一个非常罕见的情况下大多数迁移应该是自动生成的,或者至少是不依赖于未在迁移本身变化以及其他表。非常小的问题,而是一个需要注意的。

This procedure will fail though if a different migration in the merge have changed the database in such a way that the migration is no longer runnable or gives an unexpected result. That being said - I belive that to be a very rare case as most migrations should be auto-generated, or at least not be dependent on other tables that are not changed in the migration itself as well. Very minor issue but one to be aware of.

这样一个案例可能是FXP(我想不出一个更好的例子)

One such case could be fxp (I couldn't think of a better example)


  • 列foo是一个int和行包含在[0,1,2]

  • Column foo is an int and rows contain [0, 1, 2]

迁徙之改变foo的布尔值(0将自动成为虚假和> 0
将成真)

Migration A from branch A change foo to boolean (0 will become false automatically and > 0 will become true)

从支路B变富串迁移B点。它希望它是一个int,但它是一个布尔值,迁移将成功,虽然。的数据将丢失,因为迁移B在创建时的行将包含[0,1,2]。当迁移改变列布尔(并且做得很成功,并与预期结果)的行现在将包含[0,1,1],而不是和迁移B就必须比所观察到的不同的结局支路B。

Migration B from branch B change foo to string. It expects it to be an int but it is a boolean, the migration will succeed though. Data will be lost since when migration B was created the rows would contain ["0", "1", "2"]. When migration A altered column to boolean (and did so successfully and with expected result) the rows will now contain ["0", "1", "1"] instead and Migration B will have a different end result than what was observed in Branch B.

有可能更多的优势情况下的东西可以去错的解决方案。但是,如果迁移上/下code是不依赖于事物所的合并另一迁移改变了它应该工作以及刚刚更新在迁移的元数据。

There are probably more edge cases where things could go wrong with the solution. But if migrations up/down code is not dependent on things changed by another migration in the merge it should work well to just update the metadata in the migrations.

这篇关于如何管理多个分支的一个项目迁移?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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