From 6dff29f93155acc4dc6994318c96f0387525f82e Mon Sep 17 00:00:00 2001 From: huang Date: Mon, 31 Aug 2015 17:45:14 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=97=B6=E9=97=B4=E8=BF=81?= =?UTF-8?q?=E7=A7=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- db/migrate/20150831085920_update_memo_time.rb | 26 +++++++++++++++++++ ...20150831090338_update_userfeedback_time.rb | 26 +++++++++++++++++++ ...0831093918_about_user_feedback_message.rb} | 4 +-- 3 files changed, 54 insertions(+), 2 deletions(-) create mode 100644 db/migrate/20150831085920_update_memo_time.rb create mode 100644 db/migrate/20150831090338_update_userfeedback_time.rb rename db/migrate/{20150831030041_user_feedback_message.rb => 20150831093918_about_user_feedback_message.rb} (93%) diff --git a/db/migrate/20150831085920_update_memo_time.rb b/db/migrate/20150831085920_update_memo_time.rb new file mode 100644 index 000000000..c2ecd0144 --- /dev/null +++ b/db/migrate/20150831085920_update_memo_time.rb @@ -0,0 +1,26 @@ +class UpdateMemoTime < ActiveRecord::Migration + def up + memo_count = Memo.all.count / 30 + 1 + transaction do + for i in 1 ... memo_count do i + MemoMessage.page(i).per(30).each do |memo_message| + if memo_message.memo + if memo_message.memo.respond_to?("created_at") + memo_message.created_at = memo_message.memo.created_at + elsif memo_message.memo.respond_to?("created_on") + memo_message.created_at = memo_message.memo.created_on + end + memo_message.save + + memo_messages = MemoMessage.where("message_type = '#{memo_message.class.to_s}' and message_id = '#{memo_message.id}'").first + memo_messages.created_at = memo_message.created_at + memo_messages.save + end + end + end + end + end + + def down + end +end diff --git a/db/migrate/20150831090338_update_userfeedback_time.rb b/db/migrate/20150831090338_update_userfeedback_time.rb new file mode 100644 index 000000000..860a4881a --- /dev/null +++ b/db/migrate/20150831090338_update_userfeedback_time.rb @@ -0,0 +1,26 @@ +class UpdateUserfeedbackTime < ActiveRecord::Migration + def up + user_feedback_count = UserFeedbackMessage.all.count / 30 + 1 + transaction do + for i in 1 ... user_feedback_count do i + UserFeedbackMessage.page(i).per(30).each do |ufm| + if ufm.course_message + if ufm.course_message.respond_to?("created_at") + ufm.created_at = ufm.course_message.created_at + elsif ufm.course_message.respond_to?("created_on") + ufm.created_at = ufm.course_message.created_on + end + ufm.save + + user_feedbach_messages = MessageAll.where("message_type = '#{ufm.class.to_s}' and message_id = '#{ufm.id}'").first + user_feedbach_messages.created_at = ufm.created_at + user_feedbach_messages.save + end + end + end + end + end + + def down + end +end diff --git a/db/migrate/20150831030041_user_feedback_message.rb b/db/migrate/20150831093918_about_user_feedback_message.rb similarity index 93% rename from db/migrate/20150831030041_user_feedback_message.rb rename to db/migrate/20150831093918_about_user_feedback_message.rb index 24723fc0a..870795966 100644 --- a/db/migrate/20150831030041_user_feedback_message.rb +++ b/db/migrate/20150831093918_about_user_feedback_message.rb @@ -1,5 +1,4 @@ -# encoding: UTF-8 -class UserFeedbackMessage < ActiveRecord::Migration +class AboutUserFeedbackMessage < ActiveRecord::Migration def up JournalsForMessage.all.each do |jour_for_message| transaction do @@ -23,6 +22,7 @@ class UserFeedbackMessage < ActiveRecord::Migration end unless receivers.blank? receivers.each do |r| + puts jour_for_message.id jour_for_message.user_feedback_messages << UserFeedbackMessage.new(:user_id => r.id, :journals_for_message_id => jour_for_message.id, :journals_for_message_type => "Principal", :viewed => false) end end