代码优先迁移的命名约定 [英] Naming conventions for Code First migrations

查看:113
本文介绍了代码优先迁移的命名约定的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们正在使用代码优先迁移来保持数据库和模型的同步。目前,我们将版本号作为迁移的名称,显然无法实现。
问题是,具有相同名称的多个迁移由不同开发人员独立于其本地数据库创建。这导致了一些奇怪的行为,因为 IMigrationMetadata.Id 因为时间戳而不同,但是类是部分同名的。



调用这些迁移的方法是什么?这些例子总是可笑地过于简单:例如添加属性读者导致迁移 AddReaders



还是应该将迁移细分为这些小的变化?而不是将所有的变化积累成一个大的迁移。如果有依赖关系怎么办?

解决方案

是的,我认为最好的方法是将描述性名称的小单位分解。与git一样,您应该经常进行迁移,您应该经常迁移。不一定是财产财产,但包含一个合理的工作单位。如果您需要为某些功能添加两个表,就像在一次迁移中添加这两个表一样,



在创建迁移之前,避免进行大量迁移,您的工作将在几天内更改模型。时间是避免冲突的关键。



如果有依赖关系,一个迁移应该包含相关的更改,所以如果另一个开发人员应用迁移,应用程序仍然可以工作。 >

当开发人员进行迁移时,应立即提交并同步(与其他开发人员共享,以防您不使用git)。



当您使用小型变更单元时,合并和解决冲突变得更加容易。


We are using code first migrations to keep our database and model in sync. At the moment we have the version number as name for the migration which clearly doesn't work out. The problem is that multiple migrations with the same name where created by different developers independent of each other for their local database. This led to some weird behavior as the IMigrationMetadata.Id was different because of the time stamp but the classes are partial with the same name.

What is the way to go to call these migrations? The examples are always ridiculously oversimplified: e.g. adding a property Readers result in migration AddReaders.

Or should the migrations be broken down to these little changes? Instead of having accumulate all the changes into one big migration. What if there are dependencies?

解决方案

Yes, I think the best way is to break down changes to small units, with descriptive names. As with git, where you should commit often, with migrations you should migrate often. Not necessarily property by property, but containing a logical unit of work.

Like if you need to add two tables for some feature, add those two tables in one migration. Avoid making big migrations where your work for days changing models before creating a migration. Time is essential with avoiding conflicts.

If there are dependencies, one migration should contain related changes, so if another developer applies the migration, the application still works.

When a developer makes a migration, it should be immediately committed and synced (shared with other devs, in case you are not using git).

When you work with small units of change, merging and resolving conflicts becomes much easier.

这篇关于代码优先迁移的命名约定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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