diff --git a/db/migrate/20191204030230_migrate_exercise_single_question_score.rb b/db/migrate/20191204030230_migrate_exercise_single_question_score.rb index ddb9a2794..c71fea157 100644 --- a/db/migrate/20191204030230_migrate_exercise_single_question_score.rb +++ b/db/migrate/20191204030230_migrate_exercise_single_question_score.rb @@ -7,7 +7,7 @@ class MigrateExerciseSingleQuestionScore < ActiveRecord::Migration[5.2] ActiveRecord::Base.connection.execute sql # 更新成绩 - exercise_answers = ExerciseAnswer.joins(:exercise_question).where("exercise_answers.created_at > '2019-11-01 00:00:00'").where(score: -1, exercise_questions: {question_type: [0, 2]}) + exercise_answers = ExerciseAnswer.joins(:exercise_question).where(score: -1, exercise_questions: {question_type: [0, 2]}) exercise_answers.includes(:exercise_choice, exercise_question: :exercise_standard_answers).find_each do |answer| question = answer.exercise_question diff --git a/db/migrate/20191204062733_add_temp_migration.rb b/db/migrate/20191204062733_add_temp_migration.rb deleted file mode 100644 index 691e5e5ca..000000000 --- a/db/migrate/20191204062733_add_temp_migration.rb +++ /dev/null @@ -1,10 +0,0 @@ -class AddTempMigration < ActiveRecord::Migration[5.2] - def change - # 删除判断、单选题中生成多条记录,但exercise_choice_id不同的数据 - sql = %Q(delete from exercise_answers where (exercise_question_id, user_id) in - (select * from (select exercise_question_id, user_id from exercise_answers join exercise_questions eq on exercise_question_id = eq.id where eq.question_type in (0, 2) group by exercise_question_id, user_id having count(*) > 1) a) - and id not in (select * from (select min(exercise_answers.id) from exercise_answers join exercise_questions eq on exercise_question_id = eq.id where eq.question_type in (0, 2) group by exercise_question_id, user_id having count(*) > 1 order by exercise_answers.id) b)) - ActiveRecord::Base.connection.execute sql - - end -end diff --git a/db/migrate/20191204063225_add_exercise_temp_migration.rb b/db/migrate/20191204063225_add_exercise_temp_migration.rb deleted file mode 100644 index 7f9428911..000000000 --- a/db/migrate/20191204063225_add_exercise_temp_migration.rb +++ /dev/null @@ -1,10 +0,0 @@ -class AddExerciseTempMigration < ActiveRecord::Migration[5.2] - def change - # 删除判断、单选题中生成多条记录,但exercise_choice_id不同的数据 - sql = %Q(delete from exercise_answers where (exercise_question_id, user_id) in - (select * from (select exercise_question_id, user_id from exercise_answers join exercise_questions eq on exercise_question_id = eq.id where eq.question_type in (0, 2) group by exercise_question_id, user_id having count(*) > 1) a) - and id not in (select * from (select min(exercise_answers.id) from exercise_answers join exercise_questions eq on exercise_question_id = eq.id where eq.question_type in (0, 2) group by exercise_question_id, user_id having count(*) > 1 order by exercise_answers.id) b)) - ActiveRecord::Base.connection.execute sql - - end -end