Rails 迁移管理 - 最佳实践?

发布于 2024-07-24 02:57:40 字数 73 浏览 1 评论 0原文

迁移管理的最佳实践是什么?

例如,在调试迁移时,您是在提交到存储库之前编辑原始迁移还是添加编辑迁移? 谢谢!

What are best practices for migration management?

For instance, when debugging a migration, do you edit the original migration or add an edit migration before committing to the repository? Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

川水往事 2024-07-31 02:57:40

我倾向于编辑原始迁移,只要它是 a) 最后一次迁移并且 b) 不在源代码管理中。 这为代码的所有其他使用者提供了一条干净的迁移路径。 重要的是,无论您最早遇到什么数据库状态,您的迁移都应该能够无错误地运行。

I tend to edit the original migration as long as it is a) the last migration and b) not in source control. This presents a clean migration path for all other consumers of the code. The important thing is that your migrations should be able to run without error from whatever database state is the earliest that you can expect to encounter.

戴着白色围巾的女孩 2024-07-31 02:57:40

如果您与多个开发人员合作,编辑现有迁移可能会很危险。

如果您的同事已经迁移了原始迁移,那么当他更新时,他将不会选择新代码,并且会随之而来。 这是一个非常难以追踪的问题。 成为一个好居民并创建更新的迁移是错误的。

If you are working with multiple developers, editing an existing migration can be dangerous.

If your coworker has already migrated the original migration, then when he updates he will not pick up the new code and hilarity will ensue. This is a very difficult issue to track down. Error on the side of being a good denizen and just create an updated migration.

回忆追雨的时光 2024-07-31 02:57:40

仅当您可以验证现有迁移尚未由其他开发人员或某些自动构建设置运行时,才可以编辑现有迁移。 为了安全起见,您不应该编辑已提交的迁移文件,除非错误非常严重以至于迁移一开始就无法运行(在这种情况下为什么要提交它?)

此外,必须特别小心与从应用程序中其他地方调用代码的迁移一起进行,以便在运行它们时,使用正确版本的代码运行。 否则,模型中的细微更改可能会真正搞砸您之前的迁移。

Only ever edit an existing migration if you can verify that it has not yet been run by other developers or some automated build setup. To be on the safe side, you shouldn't edit a commited migration file unless the bug was so severe that the migration wouldn't run in the first place (in which case why did you commit it?)

Also, special care has to be taken with migrations calling code from elsewhere in your application so that when they are run, they are run using the correct version of the code. Otherwise subtle changes in your models can really screw up your earlier migrations.

一影成城 2024-07-31 02:57:40

即使在阅读了本文和下面的答案之后,我还是经历了惨痛的教训。 不对原文进行编辑。 您最终会失去对开发过程的跟踪,并且很难恢复控制。

Even after reading this and the answers below, I just learned the hard way. Not to edit the original. You end up losing track your development process and it's hard to get back under control.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文