parent
2f43296854
commit
b52f607b68
|
@ -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
|
|
@ -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
|
|
@ -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
|
11
db/schema.rb
11
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"
|
||||
|
|
Loading…
Reference in New Issue