Skip to content

Instantly share code, notes, and snippets.

@prcongithub
Last active September 28, 2016 07:56
Show Gist options
  • Save prcongithub/33e73c4d1702c94d676a13be63fbd695 to your computer and use it in GitHub Desktop.
Save prcongithub/33e73c4d1702c94d676a13be63fbd695 to your computer and use it in GitHub Desktop.
Categories and Groups Migration
# Mark existing incomplete content as incomplete regardless of status and schedule
Sq::CheatSheet.all.each do |cheat_sheet|
if cheat_sheet.items.empty?
cheat_sheet.status = Sq::CheatSheet::Status::INCOMPLETE
cheat_sheet.save!
end
end
# Before Deployment
Sq::Lesson.all.each do |lesson|
if lesson.flash_cards.empty?
lesson.status = Sq::Lesson::Status::INCOMPLETE
lesson.save!
end
lesson.flash_cards.each_with_index do |f,i|
f.card_order = i+1
f.template ||= "template-1"
f.data ||= "-"
end
lesson.questions.each_with_index do |q,i|
q.question_order = i+1
q.template ||= "template-1"
q.options.each_with_index do |o,oi|
o.option_order = oi+1
end
end
puts lesson.id
lesson.save!
end
Sq::Quiz.all.each do |quiz|
if quiz.questions.empty?
quiz.status = Sq::Quiz::Status::INCOMPLETE
quiz.save!
end
quiz.questions.each_with_index do |q,i|
q.question_order = i+1
q.template ||= "template-1"
q.category = quiz.categories.first || quiz.company_record.categories.first
end
puts quiz.id
quiz.save
puts quiz.error_messages
quiz.questions.each do |q|
q.save!
end
raise "Invalid quiz #{quiz.id}" if !quiz.valid?
end
# After Deployment
Sq::Lesson.all.each do |lesson|
if lesson.cheat_sheet
lesson.cheat_sheet.category_ids = lesson.category_ids
lesson.cheat_sheet.category_id = lesson.category_ids.first
lesson.cheat_sheet.save!
end
lesson.category_id = lesson.category_ids.first
lesson.save!
end
Sq::CheatSheet.all.each do |cheat_sheet|
cheat_sheet.category_id = cheat_sheet.category_ids.first
cheat_sheet.save!
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment