回滚后我应该删除迁移吗 [英] Should I delete migration after rollback

查看:48
本文介绍了回滚后我应该删除迁移吗的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对 ruby​​ 和 Rails 还很陌生,我刚刚开始了解迁移.

I'm fairly new to ruby and rails and am just getting my head around migrations.

我的问题是在回滚后删除迁移的最佳实践或正确时间是什么.到目前为止,我所读的是您是否在回滚后删除迁移的意见问题,但是在团队中工作时删除迁移是否有任何重大影响,以及离开迁移文件与删除相比是否有任何好处它吗?

My question is what is the best practice or right time to delete a migration after a rollback. So far what I have read is a matter of opinion whether you delete a migration after a rollback, but is there any major implications to deleting a migration when working in a team, and are there any benefits to leaving the migration file as opposed to deleting it?

就我而言,什么最有意义?

In my case what would make most sense?

我有我的原始迁移文件 20140731141350_create_users.rb

I had my original migrate file 20140731141350_create_users.rb

class CreateUsers < ActiveRecord::Migration
  def change
    create_table :users do |t|
      t.string :email
      t.string :password

      t.timestamps
    end
  end
end

我需要向其中添加一个 salt 列,因此我创建了迁移 20140804125449_add_salt_colum_to_users.rb

To which I needed to add a salt column, so I created the migration 20140804125449_add_salt_colum_to_users.rb

class AddSaltColumToUsers < ActiveRecord::Migration
  def change
    add_column :users, :salt, :string
  end
end

但在开发过程中我意识到 salt 列不是必需的并执行

But during development I realised the salt column wasn't necessary and performed

rake db:migrate:down VERSION=20140731141350

现在我留下了一个未使用的 20140804125449_add_salt_colum_to_users.rb 迁移文件.

Now I am left with an unused 20140804125449_add_salt_colum_to_users.rb migrate file.

删除还是不删除?

推荐答案

您永远不应该更改旧的迁移.如果您意识到给定的列是不必要的,请编写一个新的迁移来删除它.

You should never change your old migrations. If you realised that given column is unnecessary, write a new migration to remove it.

这样做的原因是您可以在任何开发点恢复数据库模式.如果您在团队中工作,那么您删除迁移的事实不会改变您的团队成员的架构.更重要的是,他们现在没有要恢复的迁移!

The reason for this is so that you can restore database schema in any point of development. If you are working in a team, the fact that you removed the migration won't change your teammates' schemas. Even more, they have no migration to revert now!

这篇关于回滚后我应该删除迁移吗的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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