don't try and eager load in a data fixup

fixes CNVS-21318

eager load will try and select all the columns of the joined table by
name. but due to race conditions, being in the middle of running
migrations, it's possible the process will know of a column that hasn't
been created yet. naming it in the select will break the query.

Change-Id: I71ddd01c77f8f6157e36a01103dff52b7b967284
test-plan: N/A
Reviewed-on: https://gerrit.instructure.com/63902
Reviewed-by: Cody Cutrer <cody@instructure.com>
Tested-by: Jenkins
Product-Review: Jacob Fugal <jacob@instructure.com>
QA-Review: Jacob Fugal <jacob@instructure.com>
This commit is contained in:
Jacob Fugal 2015-09-23 16:35:40 -06:00
parent 5b35fc9246
commit e2f11f5542
3 changed files with 19 additions and 2 deletions

View File

@ -0,0 +1,17 @@
module RuboCop
module Cop
module Datafixup
class EagerLoad < Cop
def on_send(node)
_receiver, method_name, *_args = *node
if method_name.to_s == 'eager_load'
add_offense(node,
:expression,
"eager_load in a data fixup causes errors",
:error)
end
end
end
end
end
end

View File

@ -2,7 +2,7 @@ module DataFixup::ExcludeDeletedEntriesFromUnreadCount
def self.run
# Deleted all partipant entries for deleted discussion entries
DiscussionEntryParticipant.
eager_load(:discussion_entry).
joins(:discussion_entry).preload(:discussion_entry).readonly(false).
where(:discussion_entries => { :workflow_state => 'deleted' }).
destroy_all

View File

@ -1,6 +1,6 @@
module DataFixup::FixInvalidCourseIdsOnEnrollments
def self.run
Enrollment.joins(:course_section).eager_load(:course_section).
Enrollment.joins(:course_section).preload(:course_section).
where("course_sections.course_id<>enrollments.course_id").
find_each do |e|
Enrollment.where(id: e).update_all(course_id: e.course_section.course_id)