j-obaw
Last Updated: February 25, 2016
·
180
· dpaluy
3129de6b479cc965513311f1ddcc268a

Reversible migration in Rails 4

Suppose you want to add an additional function to update all models during the migration. You can do this:

def change
  add_column :users, :activity, :datetime
  reversible do |direction|
    direction.up {
      User.update_all(activity: Time.now.utc) 
    }
  end
end
Say Thanks
Respond