消息总表数据迁移

This commit is contained in:
huang 2015-08-29 19:26:23 +08:00
parent 43170c696c
commit 7ed93c1d80
2 changed files with 29 additions and 30 deletions

View File

@ -76,35 +76,34 @@ class CourseMessages < ActiveRecord::Migration
end end
# 作品评阅 # 作品评阅
course.homework_commons.each do |homework_common| # course.homework_commons.each do |homework_common|
if homework_common.student_works # if homework_common.student_works
homework_common.student_works.each do |student_work| # homework_common.student_works.each do |student_work|
if student_work.student_works_scores # if student_work.student_works_scores
student_work.student_works_scores.each do |student_works_score| # student_work.student_works_scores.each do |student_works_score|
receiver = student_works_score.student_work.user # receiver = student_works_score.student_work.user
if student_works_score.created_at == student_works_score.updated_at # if student_works_score.created_at == student_works_score.updated_at
if student_works_score.comment.nil? # if student_works_score.comment.nil?
student_works_score.course_messages << CourseMessage.new(:user_id => receiver.id, :course_id => course.id, # student_works_score.course_messages << CourseMessage.new(:user_id => receiver.id, :course_id => course.id,
:viewed => true, :content => "作业评分:#{student_works_score.score}", :status=> true) # :viewed => true, :content => "作业评分:#{student_works_score.score}", :status=> true)
else # else
student_works_score.course_messages << CourseMessage.new(:user_id => receiver.id, :course_id => course.id, # student_works_score.course_messages << CourseMessage.new(:user_id => receiver.id, :course_id => course.id,
:viewed => true, :content => "作业评分:#{student_works_score.score}&nbsp;&nbsp;&nbsp; 评语:#{student_works_score.comment}", :status=> true) # :viewed => true, :content => "作业评分:#{student_works_score.score}&nbsp;&nbsp;&nbsp; 评语:#{student_works_score.comment}", :status=> true)
end # end
else # 更新 # else # 更新
if student_works_score.comment.nil? # if student_works_score.comment.nil?
student_works_score.course_messages << CourseMessage.new(:user_id => receiver.id, :course_id => course.id, # student_works_score.course_messages << CourseMessage.new(:user_id => receiver.id, :course_id => course.id,
:viewed => true, :content => "作业评分:#{student_works_score.score}", :status=> true) # :viewed => true, :content => "作业评分:#{student_works_score.score}", :status=> true)
else # else
student_works_score.course_messages << CourseMessage.new(:user_id => receiver.id, :course_id => course.id, # student_works_score.course_messages << CourseMessage.new(:user_id => receiver.id, :course_id => course.id,
:viewed => true, :content => "作业评分:#{student_works_score.score}&nbsp;&nbsp;&nbsp; 评语:#{student_works_score.comment}", :status=> true) # :viewed => true, :content => "作业评分:#{student_works_score.score}&nbsp;&nbsp;&nbsp; 评语:#{student_works_score.comment}", :status=> true)
end # end
end # end
end # end
end # end
end # end
end # end
end # end
# 作品讨论 # 作品讨论
end end

View File

@ -20,7 +20,7 @@ class UpdateMessageTime < ActiveRecord::Migration
end end
end end
forge_count = ForgeMessage.all.count / 30 + 2 forge_count = ForgeMessage.all.count / 30 + 1
transaction do transaction do
for i in 1 ... forge_count do i for i in 1 ... forge_count do i
ForgeMessage.page(i).per(30).each do |fmessage| ForgeMessage.page(i).per(30).each do |fmessage|