Skip to content

Commit

Permalink
Fix multiple_dropdowns_question affected by CNVS-19292
Browse files Browse the repository at this point in the history
migration 20150506164227 should be skipped on large environments and the
following command should be manually run instead.

rails console
  DataFixup::FixCorruptAssessmentQuestionsFromCnvs19292.run(
    [
      'calculated_question',
      'numerical_question',
      'matching_question',
      'multiple_dropdowns_question'
    ],
    Date.parse('2015/3/14').beginning_of_day, # Beginning of corruption
    Date.parse('2015/3/18').end_of_day        # End of corruption
  )

Fixes CNVS-19365

 - Increments AssessmentQuestion version numbers so quizzes will pull new
   data on next quiz take

Test plan
 - Effected quizzes should be fixed

Change-Id: Iafae6525ae2406a6a4b3ae88c6f61e451719dd2b
Reviewed-on: https://gerrit.instructure.com/53536
Reviewed-by: Cody Cutrer <[email protected]>
Tested-by: Jenkins
Reviewed-by: Cameron Sutter <[email protected]>
Product-Review: Brian Finney <[email protected]>
QA-Review: Brian Finney <[email protected]>
  • Loading branch information
yenif committed May 6, 2015
1 parent cc07cde commit 335f065
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 15 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
class FixCorruptAssessmentQuestionsFromCnvs19292 < ActiveRecord::Migration
tag :postdeploy

def up
DataFixup::FixCorruptAssessmentQuestionsFromCnvs19292.send_later_if_production_enqueue_args(
:run,
{
:priority => Delayed::LOW_PRIORITY,
:max_attempts => 1
},
[
'calculated_question',
'numerical_question',
'matching_question',
'multiple_dropdowns_question'
]
)
end
end
18 changes: 10 additions & 8 deletions lib/data_fixup/fix_corrupt_assessment_questions_from_cnvs19292.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
DataFixup::FixCorruptAssessmentQuestionsFromCnvs19292 = Struct.new(:bug_start_date, :bug_end_date) do
DataFixup::FixCorruptAssessmentQuestionsFromCnvs19292 = Struct.new(:question_types, :bug_start_date, :bug_end_date) do
LOG_PREFIX = "FIX_19292_CORRUPTION - "

def self.run(bug_start_date = false, bug_end_date = false, noop = false)
def self.run(question_types, bug_start_date = false, bug_end_date = false, noop = false)
if noop
# Dangerous, but noop should only be executed in isolation.
connection = ActiveRecord::Base.connection
Expand All @@ -24,7 +24,7 @@ def connection.exec_cache(sql, *args)
end
end

runner = self.new(bug_start_date, bug_end_date)
runner = self.new(question_types, bug_start_date, bug_end_date)

result = runner.fix_assessment_questions

Expand Down Expand Up @@ -87,13 +87,15 @@ def connection.exec_cache(*args)
# Update each AssessmentQuestion to increment version_number, this will
# cause associated QuizQuestions to update on next Quiz take
def fix_assessment_questions
return false unless question_types.present?

question_type_queries = question_types.map do |qt|
"assessment_questions.question_data LIKE '%#{qt}%'"
end.join(" or ")

query = AssessmentQuestion
.joins(:assessment_question_bank => {:quiz_groups => :quiz})
.where("
assessment_questions.question_data LIKE '%calculated_question%' or
assessment_questions.question_data LIKE '%numerical_question%' or
assessment_questions.question_data LIKE '%matching_question%'
")
.where(question_type_queries)

if bug_start_date && bug_end_date
query = query
Expand Down

0 comments on commit 335f065

Please sign in to comment.