实训作业迁移文件

dev_haigong
cxt 6 years ago
parent 08accb32db
commit 312403cfc3

@ -0,0 +1,30 @@
class MigrationShixunStudentWork < ActiveRecord::Migration
def up
works = StudentWork.where("myshixun_id != 0 and myshixun_id not in (select id from myshixuns) and (work_score is null or work_score = 0)")
works.update_all(:myshixun_id => 0, :work_status => 0, :work_score => nil, :final_score => nil,
:cost_time => 0, :update_time => nil, :compelete_status => 0, :commit_time => nil)
shixun_works = StudentWork.where("myshixun_id != 0 and myshixun_id not in (select id from myshixuns) and work_score > 0")
shixun_works.each do |work|
if work.homework_common && work.homework_common.homework_commons_shixuns.try(:shixun)
shixun = work.homework_common.homework_commons_shixuns.try(:shixun)
# 创建新的myshixun和games
myshixun = nil
work_score = work.final_score
work.homework_common.homework_challenge_settings.each do |setting|
if work_score > 1
myshixun.games.where(:challenge_id => setting.challenge_id).first.update_attributes(:status => 2)
work_score -= setting.score
end
end
work.update_column("myshixun_id", myshixun.id)
end
end
end
def down
end
end
Loading…
Cancel
Save