迁移问题

dev_shixuns
huang 6 years ago
parent cf6aa09060
commit 3839e8be60

@ -14,15 +14,15 @@ class MigrateShixunWorks1 < ActiveRecord::Migration
end end
def up def up
begin 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 = 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,
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)
: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 = StudentWork.where("myshixun_id != 0 and myshixun_id not in (select id from myshixuns) and work_score > 0")
shixun_works.each do |work| shixun_works.each do |work|
shixun = work.homework_common.try(:homework_commons_shixuns).try(:shixun) shixun = work.homework_common.try(:homework_commons_shixuns).try(:shixun)
user = work.user user = work.user
begin
ActiveRecord::Base.transaction do ActiveRecord::Base.transaction do
if shixun.present? && user.present? if shixun.present? && user.present?
# 创建新的myshixun和games # 创建新的myshixun和games
@ -81,11 +81,11 @@ class MigrateShixunWorks1 < ActiveRecord::Migration
end end
end end
end end
rescue Exception => e
puts ("###failed to exec shixun: current task id is #{e}")
# g.delete_project(gshixun.id) if gshixun.try(:id).present?
raise ActiveRecord::Rollback
end end
rescue Exception => e
puts ("###failed to exec shixun: current task id is #{e}")
# g.delete_project(gshixun.id) if gshixun.try(:id).present?
raise ActiveRecord::Rollback
end end
end end

Loading…
Cancel
Save