From 64f972770fce3a99931c9f69589d65ba4885fc52 Mon Sep 17 00:00:00 2001 From: huang Date: Fri, 15 Jan 2016 10:41:34 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0board=E5=92=8Cattachment?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=E8=BF=81=E7=A7=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../20160115023749_update_boards_attach.rb | 32 +++++++++++++++++++ db/schema.rb | 2 +- 2 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 db/migrate/20160115023749_update_boards_attach.rb diff --git a/db/migrate/20160115023749_update_boards_attach.rb b/db/migrate/20160115023749_update_boards_attach.rb new file mode 100644 index 000000000..06f5097f8 --- /dev/null +++ b/db/migrate/20160115023749_update_boards_attach.rb @@ -0,0 +1,32 @@ +class UpdateBoardsAttach < 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.boards.first.nil? + boards_count = project.boards.first.topics.count + project.project_score.update_attribute(:board_num, boards_count) + end + # update attach + unless project.attachments.nil? + attachments_count = project.attachments.count + project.project_score.update_attribute(:attach_num, attachments_count) + end + + end + end + end + end + end + + def down + end +end diff --git a/db/schema.rb b/db/schema.rb index 045455bb7..d27ee5da3 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 => 20160114131753) do +ActiveRecord::Schema.define(:version => 20160115023749) do create_table "activities", :force => true do |t| t.integer "act_id", :null => false