From cf372c20aecc8513c0874d927d327eb515a96c10 Mon Sep 17 00:00:00 2001 From: Usama Sadiq Date: Thu, 15 May 2025 09:41:55 +0500 Subject: [PATCH] fix: refactor index_together to indexes for Django 5.2 support (IV) (#36716) * fix: refactor index_together to indexes for Django 5.2 support * fix: fix quality issues --- ...er_id_first_course_id_user_id_idx_and_m.py | 23 +++++++++++++++++++ lms/djangoapps/grades/models.py | 12 +++++++--- 2 files changed, 32 insertions(+), 3 deletions(-) create mode 100644 lms/djangoapps/grades/migrations/0022_rename_persistentsubsectiongrade_first_attempted_course_id_user_id_first_course_id_user_id_idx_and_m.py diff --git a/lms/djangoapps/grades/migrations/0022_rename_persistentsubsectiongrade_first_attempted_course_id_user_id_first_course_id_user_id_idx_and_m.py b/lms/djangoapps/grades/migrations/0022_rename_persistentsubsectiongrade_first_attempted_course_id_user_id_first_course_id_user_id_idx_and_m.py new file mode 100644 index 0000000000..58fdc4dcf9 --- /dev/null +++ b/lms/djangoapps/grades/migrations/0022_rename_persistentsubsectiongrade_first_attempted_course_id_user_id_first_course_id_user_id_idx_and_m.py @@ -0,0 +1,23 @@ +# Generated by Django 4.2.20 on 2025-05-14 05:53 + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('grades', '0021_rename_persistentcoursegrade_passed_timestamp_course_id_passed_timestamp_course_id_idx_and_more'), + ] + + operations = [ + migrations.RenameIndex( + model_name='persistentsubsectiongrade', + new_name='first_course_id_user_id_idx', + old_fields=('first_attempted', 'course_id', 'user_id'), + ), + migrations.RenameIndex( + model_name='persistentsubsectiongrade', + new_name='course_id_usage_key_idx', + old_fields=('modified', 'course_id', 'usage_key'), + ), + ] diff --git a/lms/djangoapps/grades/models.py b/lms/djangoapps/grades/models.py index f6266b9f82..38cfed502c 100644 --- a/lms/djangoapps/grades/models.py +++ b/lms/djangoapps/grades/models.py @@ -315,9 +315,15 @@ class PersistentSubsectionGrade(TimeStampedModel): # in a course # (first_attempted, course_id, user_id): find all attempted subsections in a course for a user # (first_attempted, course_id): find all attempted subsections in a course for all users - index_together = [ - ('modified', 'course_id', 'usage_key'), - ('first_attempted', 'course_id', 'user_id') + indexes = [ + models.Index( + fields=['modified', 'course_id', 'usage_key'], + name="course_id_usage_key_idx" + ), + models.Index( + fields=['first_attempted', 'course_id', 'user_id'], + name="first_course_id_user_id_idx" + ), ] # primary key will need to be large for this table