2011-11-09 08:42:48 +08:00
|
|
|
class FixUngradedCounts < ActiveRecord::Migration
|
2015-11-05 05:38:51 +08:00
|
|
|
tag :predeploy
|
|
|
|
|
2011-11-09 08:42:48 +08:00
|
|
|
def self.up
|
2015-09-01 02:09:52 +08:00
|
|
|
update <<-SQL
|
|
|
|
UPDATE #{Assignment.quoted_table_name} SET needs_grading_count = COALESCE((
|
2011-11-09 08:42:48 +08:00
|
|
|
SELECT COUNT(DISTINCT s.id)
|
2015-09-01 02:09:52 +08:00
|
|
|
FROM #{Submission.quoted_table_name} s
|
|
|
|
INNER JOIN #{Enrollment.quoted_table_name} e ON e.user_id = s.user_id AND e.workflow_state = 'active'
|
2011-11-09 08:42:48 +08:00
|
|
|
WHERE s.assignment_id = assignments.id
|
|
|
|
AND e.course_id = assignments.context_id
|
|
|
|
AND s.submission_type IS NOT NULL
|
|
|
|
AND (s.score IS NULL
|
|
|
|
OR NOT grade_matches_current_submission
|
|
|
|
OR s.workflow_state IN ('submitted', 'pending_review')
|
|
|
|
)
|
|
|
|
), 0)
|
|
|
|
SQL
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.down
|
|
|
|
end
|
|
|
|
end
|