编辑现有的 Rails 迁移是个好主意? [英] Editing Existing Rails Migrations is a good idea?

查看:31
本文介绍了编辑现有的 Rails 迁移是个好主意?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当开始一个新项目时,模型有很多变化,我发现编辑现有的迁移很容易 &运行 db:cleandb:reset 然后创建一个新的迁移.当应用程序尚未投入生产时,我会这样做,这意味着我可以毫无顾虑地重置/清理数据库我独自工作或作为小团队的一部分工作.

When starting out a new project, there are lot of changes in models that I find it easy to edit an existing migration & run db:clean or db:reset than create a new migration. I do this when app has not hit production which means I can reset/clean database without worries & I am working solo or part of a small team.

但是今天,我在 Rails Guide 中看到以下建议,说这不是一个好主意&不鼓励编辑现有迁移:

But Today, I came across the following advice in Rails Guide saying its not a good idea & discourages editing existing migrations:

编辑现有迁移不是一个好主意:您将创建给你自己和你的同事带来额外的工作,并导致严重的头痛如果现有版本的迁移已经运行生产机器.相反,您应该编写一个新的迁移执行您需要的更改.编辑新生成的尚未承诺进行源代码控制的迁移(或更多通常,这还没有传播到您的开发之外机)相对无害.

Editing existing migrations is not a good idea: you will be creating extra work for yourself and your co-workers and cause major headaches if the existing version of the migration has already been run on production machines. Instead, you should write a new migration that performs the changes you require. Editing a freshly generated migration that has not yet been committed to source control (or, more generally, which has not been propagated beyond your development machine) is relatively harmless.

我想知道:

  • 我可能会遇到哪些潜在的陷阱?
  • 这些陷阱是否适用于我的案例(开发阶段,单独工作)?

推荐答案

如果您正在与团队合作并且您提交了迁移,则否.

If you are working with a team and you committed the migration then NO.

如果它仅在您的本地环境中,那么只需创建一个新的迁移来修复您需要的内容.您可以删除表\列并执行您需要的操作.

If it is only on your local environment then just create a new migration fixing what you need. You can drop tables\columns and do what you need.

由于您清理了数据库并重置了它,因此每个人都会这样做,否则如果他们尝试迁移,就会遇到问题.

Since you clean the db and reset it, then everyone will be doing the same or they will have issues if they try to migrate.

这篇关于编辑现有的 Rails 迁移是个好主意?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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