diff --git a/db/migrate/20190722062800_modify_answer_for_challenges.rb b/db/migrate/20190722062800_modify_answer_for_challenges.rb new file mode 100644 index 000000000..747564d68 --- /dev/null +++ b/db/migrate/20190722062800_modify_answer_for_challenges.rb @@ -0,0 +1,11 @@ +class ModifyAnswerForChallenges < ActiveRecord::Migration[5.2] + def change + challenges = Challenge.where("answer is not null or answer != ''") + .includes(:challenge_answers).unscoped + challenges.find_each do |c| + next if c.challenge_answers.present? + puts("############challenge_id:##{c.id}") + ChallengeAnswer.create(name: "解题代码", contents: "#{c.answer}", level: 1, score: 100, challenge_id: c.id) + end + end +end