socialforge/db/migrate/20160415030447_sync_rep_sta...

27 lines
898 B
Ruby

class SyncRepStatics < ActiveRecord::Migration
def up
g = Gitlab.client
# projects = Project.find_by_sql("SELECT p.* FROM projects p, project_scores ps where p.id = ps.project_id and p.gpid is not null and ps.changeset_num > 0")
projects = Project.where("gpid is not null")
count = projects.count / 30 + 2
transaction do
for i in 1 ... count do i
projects.page(i).per(30).each do |project|
begin
puts project.id
g.rep_stats(project.gpid).each do |static|
puts static.uname
RepStatics.create(:project_id => project.id, :uname => static.uname, :commits_num => static.commits_num, :email => static.email, :add => static.add, :del => static.del, :changeset => static.changes)
end
rescue
logger.error("Sync rep failed!")
end
end
end
end
end
def down
end
end