gpt4 book ai didi

ruby-on-rails - 编辑现有的 Rails 迁移是个好主意吗?

转载 作者:数据小太阳 更新时间:2023-10-29 06:58:54 24 4
gpt4 key购买 nike

当开始一个新项目时,模型会发生很多变化,我发现编辑现有迁移并运行 db:cleandb:reset 很容易而不是创建新的迁移。我在应用程序尚未投入生产时执行此操作,这意味着我可以毫无后顾之忧地重置/清理数据库,而且我是单独工作或作为小团队的一员工作。

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

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.

我想知道:

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

最佳答案

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

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

既然你清理了数据库并重置了它,那么每个人都会做同样的事情,否则如果他们尝试迁移就会遇到问题。

关于ruby-on-rails - 编辑现有的 Rails 迁移是个好主意吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10812111/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com