为activities表添加created_at字段,并导入数据

This commit is contained in:
cxt 2015-08-11 14:49:32 +08:00
parent 21f81a931a
commit a872692984
4 changed files with 40 additions and 16 deletions

View File

@ -42,10 +42,10 @@ en:
label_member: "Members" label_member: "Members"
project_module_attachments: "Resources" project_module_attachments: "Resources"
label_project_mail_attachments: Project Resources label_project_mail_attachments: "Project Resources"
label_project_mail_upload: had uploaded project resources label_project_mail_upload: "had uploaded project resources"
label_invite: Invitation label_invite: "Invitation"
label_invite_new_user: "Send email to invite new user" label_invite_new_user: "Send email to invite new user"
label_invite_trustie_user: "Invite the Trustie registered user" label_invite_trustie_user: "Invite the Trustie registered user"

View File

@ -0,0 +1,8 @@
class AddCreatedAtToActivities < ActiveRecord::Migration
def up
add_column :activities, :created_at, :timestamp
end
def end
remove_column :activities, :created_at
end
end

View File

@ -0,0 +1,21 @@
class UpdateActivitiesData < ActiveRecord::Migration
def up
count = Activity.all.count / 10 + 1
transaction do
for i in 1 ... count do i
Activity.all.each do |activity|
type = activity.act_type
if type=='Contest' || type=='Message' || type=='News'|| type=='Journal'|| type=='Issue'|| type=='Principal'||type=='JournalsForMessage'
activity.created_at = activity.act.created_on if activity.act
elsif type=='Contestnotification' || type=='HomeworkCommon' || type=='Poll'
activity.created_at = activity.act.created_at if activity.act
end
activity.save
end
end
end
end
def down
end
end

View File

@ -11,7 +11,7 @@
# #
# It's strongly recommended to check this file into your version control system. # It's strongly recommended to check this file into your version control system.
ActiveRecord::Schema.define(:version => 20150801034945) do ActiveRecord::Schema.define(:version => 20150810064247) do
create_table "activities", :force => true do |t| create_table "activities", :force => true do |t|
t.integer "act_id", :null => false t.integer "act_id", :null => false
@ -19,6 +19,7 @@ ActiveRecord::Schema.define(:version => 20150801034945) do
t.integer "user_id", :null => false t.integer "user_id", :null => false
t.integer "activity_container_id" t.integer "activity_container_id"
t.string "activity_container_type", :default => "" t.string "activity_container_type", :default => ""
t.datetime "created_at"
end end
add_index "activities", ["act_id", "act_type"], :name => "index_activities_on_act_id_and_act_type" add_index "activities", ["act_id", "act_type"], :name => "index_activities_on_act_id_and_act_type"
@ -454,13 +455,6 @@ ActiveRecord::Schema.define(:version => 20150801034945) do
add_index "delayed_jobs", ["priority", "run_at"], :name => "delayed_jobs_priority" add_index "delayed_jobs", ["priority", "run_at"], :name => "delayed_jobs_priority"
create_table "discuss_demos", :force => true do |t|
t.string "title"
t.text "body"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
end
create_table "documents", :force => true do |t| create_table "documents", :force => true do |t|
t.integer "project_id", :default => 0, :null => false t.integer "project_id", :default => 0, :null => false
t.integer "category_id", :default => 0, :null => false t.integer "category_id", :default => 0, :null => false
@ -863,6 +857,7 @@ ActiveRecord::Schema.define(:version => 20150801034945) do
t.datetime "created_on" t.datetime "created_on"
t.integer "comments_count", :default => 0, :null => false t.integer "comments_count", :default => 0, :null => false
t.integer "course_id" t.integer "course_id"
t.datetime "updated_on"
end end
add_index "news", ["author_id"], :name => "index_news_on_author_id" add_index "news", ["author_id"], :name => "index_news_on_author_id"