优化数据迁移效率

This commit is contained in:
sw 2014-12-29 11:53:26 +08:00
parent 259799eb89
commit 0a58fce251
1 changed files with 17 additions and 13 deletions

View File

@ -1,23 +1,27 @@
class ChangeSeemsRateableRates < ActiveRecord::Migration class ChangeSeemsRateableRates < ActiveRecord::Migration
def up def up
SeemsRateableRates.where("rateable_type = 'HomeworkAttach'").each do |rate| Course.all.each do |course|
homework = HomeworkAttach.find_by_id rate.rateable_id teachers = []
if homework course.members.each do |m|
course = homework.bid.courses.first teachers << m.user_id if m && m.user && m.user.allowed_to?(:as_teacher,course)
if course end
teachers = [] course.homeworks.each do |bid|
course.members.each do |m| bid.homeworks.each do |homework|
teachers << m.user_id if m && m.user && m.user.allowed_to?(:as_teacher,course) SeemsRateableRates.where("rateable_type = 'HomeworkAttach' and rateable_id = #{homework.id}").each do |rate|
end if teachers.include?(rate.rater_id)
if teachers.include?(rate.rater_id) rate.is_teacher_score = 1
rate.is_teacher_score = 1 rate.save
rate.save end
end
end end
end end
end end
end
end end
def down def down
SeemsRateableRates.where("is_teacher_score = 1").each do |rate|
rate.is_teacher_score = 0
rate.save
end
end end
end end