BigW Consortium Gitlab

20130403003950_add_last_activity_column_into_project.rb 633 Bytes
Newer Older
1 2 3 4 5 6
class AddLastActivityColumnIntoProject < ActiveRecord::Migration
  def up
    add_column :projects, :last_activity_at, :datetime
    add_index :projects, :last_activity_at

    Project.find_each do |project|
7 8 9 10 11 12 13
      last_activity_date = if project.last_activity
                             project.last_activity.created_at
                           else
                             project.updated_at
                           end

      project.update_attribute(:last_activity_at, last_activity_date)
14 15 16 17 18 19 20 21
    end
  end

  def down
    remove_index :projects, :last_activity_at
    remove_column :projects, :last_activity_at
  end
end