From ed26242f94aee7335ab3b6020d0aa9d7ea72a309 Mon Sep 17 00:00:00 2001 From: huang Date: Fri, 15 Jan 2016 21:19:52 +0800 Subject: [PATCH] =?UTF-8?q?=E7=89=88=E6=9C=AC=E5=BA=93=E6=8F=90=E4=BA=A4?= =?UTF-8?q?=E6=AC=A1=E6=95=B0=E8=BF=81=E7=A7=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../20160115125217_update_rep_commits.rb | 32 +++++++++++++++++++ db/schema.rb | 2 +- 2 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 db/migrate/20160115125217_update_rep_commits.rb diff --git a/db/migrate/20160115125217_update_rep_commits.rb b/db/migrate/20160115125217_update_rep_commits.rb new file mode 100644 index 000000000..ea8e3c815 --- /dev/null +++ b/db/migrate/20160115125217_update_rep_commits.rb @@ -0,0 +1,32 @@ +class UpdateRepCommits < ActiveRecord::Migration + def up + project_count = Project.all.count / 30 + 2 + transaction do + for i in 1 ... project_count do i + Project.page(i).per(30).each do |project| + puts project.id + if ProjectScore.where("project_id=?", project.id).first.nil? + puts "create project ==>#{project.id}" + ProjectScore.create(:project_id => project.id, :score => false) + end + unless project.project_score.nil? + # update boards + unless project.gpid.nil? + g = Gitlab.client + begin + puts project.id + count = g.project(project.gpid).commit_count + rescue + logger.error("The project's rep is not exit!") + end + project.project_score.update_attribute(:changeset_num, count) + end + end + end + end + end + end + + def down + end +end diff --git a/db/schema.rb b/db/schema.rb index d27ee5da3..bac1882c5 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended to check this file into your version control system. -ActiveRecord::Schema.define(:version => 20160115023749) do +ActiveRecord::Schema.define(:version => 20160115125217) do create_table "activities", :force => true do |t| t.integer "act_id", :null => false