chore: add script to delete student records incorrectly created by teacher responses

This commit is contained in:
Nelson Jovel 2024-11-25 17:39:40 -08:00
parent f1eaad62c8
commit 0f5c0b280d

View file

@ -140,6 +140,13 @@ namespace :one_off do
academic_year.delete
end
end
desc "delete all student records incorrectly created by teacher responses"
task delete_errant_student_records: :environment do
wrong_response_ids = SurveyItemResponse.where(survey_item: SurveyItem.teacher_survey_items).pluck(:response_id).uniq
StudentRace.where(student: Student.where(response_id: wrong_response_ids)).delete_all
Student.where(response_id: wrong_response_ids).delete_all
SurveyItemResponse.where(response_id: wrong_response_ids).update_all(student_id: nil)
end
desc "print out percentage of nil values for range"
task nil_grades: :environment do