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"