socialforge/db/migrate/20160122023014_add_commit_t...

28 lines
726 B
Ruby

class AddCommitTime < ActiveRecord::Migration
def up
add_column :project_scores, :commit_time, :datetime, :default => nil
count = ProjectScore.all.count / 30 + 2
transaction do
for i in 1 ... count do i
ProjectScore.page(i).per(30).each do |ps|
unless ps.project.nil?
unless ps.project.gpid.nil?
g = Gitlab.client
begin
changesets = g.commits(ps.project.gpid)
ps.commit_time = changesets[0].created_at
ps.save
rescue
logger.error("The project's rep is not exit!")
end
end
end
end
end
end
end
def down
end
end