Commit 4a1ef73c authored by Robert Speicher's avatar Robert Speicher

Merge branch 'fix-project-last-activity-at-migration' into 'master'

Use raw SQL instead of Rails models in 20130403003950 migration

Closes gitlab-org/gitlab-development-kit#109

Closes https://github.com/gitlabhq/gitlabhq/issues/10123

See merge request !3638
parents dfe4c69e 66102e50
...@@ -3,14 +3,16 @@ class AddLastActivityColumnIntoProject < ActiveRecord::Migration ...@@ -3,14 +3,16 @@ class AddLastActivityColumnIntoProject < ActiveRecord::Migration
add_column :projects, :last_activity_at, :datetime add_column :projects, :last_activity_at, :datetime
add_index :projects, :last_activity_at add_index :projects, :last_activity_at
Project.find_each do |project| select_all('SELECT id, updated_at FROM projects').each do |project|
last_activity_date = if project.last_activity project_id = project['id']
project.last_activity.created_at update_date = project['updated_at']
else event = select_one("SELECT created_at FROM events WHERE project_id = #{project_id} ORDER BY created_at DESC LIMIT 1")
project.updated_at
end
project.update_attribute(:last_activity_at, last_activity_date) if event && event['created_at']
update_date = event['created_at']
end
execute("UPDATE projects SET last_activity_at = '#{update_date}' WHERE id = #{project_id}")
end end
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment