Last Updated: February 25, 2016
·
378
· dpaluy

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