Because of the lacking of foreign_key constraint, some of the records are not valid but still stores in db, to fix: - [x] Add `null: false` to question_assessments, question_id and assessment_id, there are `question_assessments` with nil assessment_id - [x] ~Handle question_assessments with deleted_assessments~ - [x] Tag and Tag group id inconsistent, probably can be fixed by: ``` Tag set course_id same as tag_group course_id # Tag.where(course_id: nil).each { |t| id = t.tag_group.course_id; t.update_column(:course_id, id)} ``` - [x] Tag and Taggable in different courses. Should drop the taggable instead. - [x] ~Drop answers with null submission and question, add null: false~ - [x] inconsistent folders (folders and subfolder belong to differernt course) ``` def fix_course_id(folder, course_id) return if folder.nil? if folder.course_id != course_id puts "Update folder #{folder.name} #{folder.id} to course #{course_id}, origin: #{folder.course_id}" folder.update_column(:course_id, course_id) end folder.subfolders.each { |f| fix_course_id(f, course_id) } end ```
Because of the lacking of foreign_key constraint, some of the records are not valid but still stores in db, to fix:
null: falseto question_assessments, question_id and assessment_id, there arequestion_assessmentswith nil assessment_idHandle question_assessments with deleted_assessmentsTag and Taggable in different courses. Should drop the taggable instead.
Drop answers with null submission and question, add null: falseinconsistent folders (folders and subfolder belong to differernt course)