From b52f607b683937e8ee0f60183f5cebff4070e503 Mon Sep 17 00:00:00 2001 From: sw <939547590@qq.com> Date: Thu, 20 Aug 2015 11:19:26 +0800 Subject: [PATCH] =?UTF-8?q?=E7=94=A8=E6=88=B7=E5=8A=A8=E6=80=81=20=3D=20?= =?UTF-8?q?=E5=8F=82=E4=B8=8E=E8=AF=BE=E7=A8=8B=E5=8A=A8=E6=80=81=20+=20?= =?UTF-8?q?=E5=8F=82=E4=B8=8E=E8=AF=BE=E7=A8=8B=E5=8A=A8=E6=80=81=20?= =?UTF-8?q?=E8=A1=A8=E5=88=9B=E5=BB=BA=E4=BB=A5=E5=8F=8A=E7=9B=B8=E5=85=B3?= =?UTF-8?q?=E5=85=B3=E7=B3=BB=E7=9A=84=E6=90=AD=E5=BB=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/user_activity.rb | 7 ++++ .../20150820022416_create_user_activity.rb | 16 ++++++++ .../20150820025358_about_user_activities.rb | 37 +++++++++++++++++++ db/schema.rb | 11 +++++- 4 files changed, 70 insertions(+), 1 deletion(-) create mode 100644 app/models/user_activity.rb create mode 100644 db/migrate/20150820022416_create_user_activity.rb create mode 100644 db/migrate/20150820025358_about_user_activities.rb diff --git a/app/models/user_activity.rb b/app/models/user_activity.rb new file mode 100644 index 000000000..1af1dc017 --- /dev/null +++ b/app/models/user_activity.rb @@ -0,0 +1,7 @@ +class UserActivity < ActiveRecord::Base + attr_accessible :act_type,:act_id,:container_type,:container_id + # 虚拟关联---项目动态表/课程动态表 + belongs_to :act ,:polymorphic => true + # 虚拟关联---项目/课程 + belongs_to :container ,:polymorphic => true +end diff --git a/db/migrate/20150820022416_create_user_activity.rb b/db/migrate/20150820022416_create_user_activity.rb new file mode 100644 index 000000000..7d6a978d1 --- /dev/null +++ b/db/migrate/20150820022416_create_user_activity.rb @@ -0,0 +1,16 @@ +class CreateUserActivity < ActiveRecord::Migration + def up + create_table :user_activities do |t| + t.string :act_type + t.integer :act_id + t.string :container_type + t.integer :container_id + + t.timestamps + end + end + + def down + drop_table :user_activities + end +end diff --git a/db/migrate/20150820025358_about_user_activities.rb b/db/migrate/20150820025358_about_user_activities.rb new file mode 100644 index 000000000..f3916cff3 --- /dev/null +++ b/db/migrate/20150820025358_about_user_activities.rb @@ -0,0 +1,37 @@ +class AboutUserActivities < ActiveRecord::Migration + def up + forge_count = ForgeActivity.all.count / 30 + 2 + transaction do + for i in 1 ... forge_count do i + ForgeActivity.page(i).per(30).each do |activity| + user_activity = UserActivity.new + user_activity.act_id = activity.id + user_activity.act_type = activity.class.to_s + user_activity.container_type = "Project" + user_activity.container_id = activity.project_id + user_activity.created_at = activity.created_at + user_activity.save + end + end + end + + course_count = CourseActivity.all.count / 30 + 2 + transaction do + for i in 1 ... course_count do i + CourseActivity.page(i).per(30).each do |activity| + user_activity = UserActivity.new + user_activity.act_id = activity.id + user_activity.act_type = activity.class.to_s + user_activity.container_type = "Course" + user_activity.container_id = activity.course_id + user_activity.created_at = activity.created_at + user_activity.save + end + end + end + end + + def down + + end +end diff --git a/db/schema.rb b/db/schema.rb index 8d78a9ca0..7e3743b0e 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 => 20150815030833) do +ActiveRecord::Schema.define(:version => 20150820025358) do create_table "activities", :force => true do |t| t.integer "act_id", :null => false @@ -1394,6 +1394,15 @@ ActiveRecord::Schema.define(:version => 20150815030833) do t.integer "fields_bits", :default => 0 end + create_table "user_activities", :force => true do |t| + t.string "act_type" + t.integer "act_id" + t.string "container_type" + t.integer "container_id" + t.datetime "created_at", :null => false + t.datetime "updated_at", :null => false + end + create_table "user_extensions", :force => true do |t| t.integer "user_id", :null => false t.date "birthday"