迁移总表时间

This commit is contained in:
huang 2015-08-29 17:09:44 +08:00
parent 2a17cfc741
commit 43170c696c
4 changed files with 47 additions and 33 deletions

View File

@ -11,7 +11,7 @@ class CourseMessage < ActiveRecord::Base
validates :course_id,presence: true
validates :course_message_id,presence: true
validates :course_message_type, presence: true
validates :content, length: {maximum: 1000}
validates_length_of :content, :maximum => 100
after_create :add_user_message
def add_user_message

View File

@ -76,6 +76,5 @@ class ForgeMessages < ActiveRecord::Migration
end
def down
ForgeMessages.destroy_all
end
end

View File

@ -1,31 +0,0 @@
class AboutMessageAlls < ActiveRecord::Migration
def up
forge_count = ForgeMessage.all.count / 30 + 2
transaction do
for i in 1 ... forge_count do i
ForgeMessage.page(i).per(30).each do |forge_message|
message = MessageAll.new
message.message_id = forge_message.forge_message_id
message.message_type = forge_message.forge_message_type
message.user_id = forge_message.user_id
message.save
end
end
end
course_count = CourseMessage.all.count / 30 + 2
transaction do
for i in 1 ... course_count do i
CourseMessage.page(i).per(30).each do |course_message|
message = MessageAll.new
message.message_id = course_message.course_message_id
message.message_type = course_message.course_message_type
message.save
end
end
end
end
def down
end
end

View File

@ -0,0 +1,46 @@
class UpdateMessageTime < ActiveRecord::Migration
def up
course_count = CourseMessage.all.count / 30 + 1
transaction do
for i in 1 ... course_count do i
CourseMessage.page(i).per(30).each do |cmessage|
if cmessage.course_message
if cmessage.course_message.respond_to?("created_at")
cmessage.created_at = cmessage.course_message.created_at
elsif cmessage.course_message.respond_to?("created_on")
cmessage.created_at = cmessage.course_message.created_on
end
cmessage.save
course_all_message = MessageAll.where("message_type = '#{cmessage.class.to_s}' and message_id = '#{cmessage.id}'").first
course_all_message.created_at = cmessage.created_at
course_all_message.save
end
end
end
end
forge_count = ForgeMessage.all.count / 30 + 2
transaction do
for i in 1 ... forge_count do i
ForgeMessage.page(i).per(30).each do |fmessage|
if fmessage.forge_message
if fmessage.forge_message.respond_to?("created_at")
fmessage.created_at = fmessage.forge_message.created_at
elsif fmessage.forge_message.respond_to?("created_on")
fmessage.created_at = fmessage.forge_message.created_on
end
fmessage.save
forge_all_message = MessageAll.where("message_type = '#{fmessage.class.to_s}' and message_id = '#{fmessage.id}'").first
forge_all_message.created_at = fmessage.created_at
forge_all_message.save
end
end
end
end
end
def down
end
end