From e8e96886440c92d963eb34b58a5ab6ebdff3d8c4 Mon Sep 17 00:00:00 2001 From: huang Date: Wed, 16 Mar 2016 14:18:57 +0800 Subject: [PATCH] =?UTF-8?q?=E9=A1=B9=E7=9B=AE=E8=B5=84=E6=BA=90=E6=95=B0?= =?UTF-8?q?=E7=9B=AE=E8=BF=81=E7=A7=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...6055201_attachment_project_count_update.rb | 19 +++++++++++++++++++ db/schema.rb | 17 +++++++++-------- 2 files changed, 28 insertions(+), 8 deletions(-) create mode 100644 db/migrate/20160316055201_attachment_project_count_update.rb diff --git a/db/migrate/20160316055201_attachment_project_count_update.rb b/db/migrate/20160316055201_attachment_project_count_update.rb new file mode 100644 index 000000000..0f436aab2 --- /dev/null +++ b/db/migrate/20160316055201_attachment_project_count_update.rb @@ -0,0 +1,19 @@ +class AttachmentProjectCountUpdate < ActiveRecord::Migration + def up + Project.all.each do |project| + unless project.attachments.count.to_i == 0 + attachment_count = Attachment.find_by_sql("SELECT * FROM `attachments` where container_id = #{project.id} and container_type ='Project'").count + project_score = ProjectScore.where("project_id=?", project.id).first + if project_score.nil? + ProjectScore.create(:project_id => project.id, :attach_num => 0) + else + project_score.attach_num = attachment_count + project_score.save + end + end + end + end + + def down + end +end diff --git a/db/schema.rb b/db/schema.rb index 2dad292f4..33bf42b5b 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 => 20160225031230) do +ActiveRecord::Schema.define(:version => 20160316055201) do create_table "activities", :force => true do |t| t.integer "act_id", :null => false @@ -432,9 +432,11 @@ ActiveRecord::Schema.define(:version => 20160225031230) do t.integer "resource_num" t.integer "journal_num" t.integer "journal_reply_num" - t.datetime "created_at", :null => false - t.datetime "updated_at", :null => false + t.datetime "created_at", :null => false + t.datetime "updated_at", :null => false t.integer "total_score" + t.integer "homework_journal_num", :default => 0 + t.integer "news_num", :default => 0 end create_table "course_groups", :force => true do |t| @@ -506,6 +508,7 @@ ActiveRecord::Schema.define(:version => 20160225031230) do t.integer "is_excellent", :default => 0 t.integer "excellent_option", :default => 0 t.integer "is_copy", :default => 0 + t.integer "visits", :default => 0 end create_table "custom_fields", :force => true do |t| @@ -1282,6 +1285,7 @@ ActiveRecord::Schema.define(:version => 20160225031230) do t.datetime "created_at", :null => false t.datetime "updated_at", :null => false t.boolean "allow_guest_download", :default => true + t.integer "visits", :default => 0 end create_table "phone_app_versions", :force => true do |t| @@ -1441,6 +1445,7 @@ ActiveRecord::Schema.define(:version => 20160225031230) do t.integer "acts_count", :default => 0 t.integer "journals_count", :default => 0 t.integer "boards_reply_count", :default => 0 + t.integer "visits", :default => 0 end add_index "projects", ["lft"], :name => "index_projects_on_lft" @@ -1900,6 +1905,7 @@ ActiveRecord::Schema.define(:version => 20160225031230) do t.string "mail_notification", :default => "", :null => false t.string "salt", :limit => 64 t.integer "gid" + t.integer "visits", :default => 0 end add_index "users", ["auth_source_id"], :name => "index_users_on_auth_source_id" @@ -2013,11 +2019,6 @@ ActiveRecord::Schema.define(:version => 20160225031230) do add_index "wikis", ["project_id"], :name => "wikis_project_id" - create_table "wlcs", :force => true do |t| - t.datetime "created_at", :null => false - t.datetime "updated_at", :null => false - end - create_table "workflows", :force => true do |t| t.integer "tracker_id", :default => 0, :null => false t.integer "old_status_id", :default => 0, :null => false