diff --git a/lms/djangoapps/courseware/migrations/0015_add_courseware_stats_index.py b/lms/djangoapps/courseware/migrations/0015_add_courseware_stats_index.py new file mode 100644 index 0000000000..f92418c9a9 --- /dev/null +++ b/lms/djangoapps/courseware/migrations/0015_add_courseware_stats_index.py @@ -0,0 +1,17 @@ +# Generated by Django 2.2.18 on 2021-02-18 17:35 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('courseware', '0014_fix_nan_value_for_global_speed'), + ] + + operations = [ + migrations.AddIndex( + model_name='studentmodule', + index=models.Index(fields=['module_state_key', 'grade', 'student'], name='courseware_stats'), + ), + ] diff --git a/lms/djangoapps/courseware/models.py b/lms/djangoapps/courseware/models.py index 714d2f2afc..8d2087b137 100644 --- a/lms/djangoapps/courseware/models.py +++ b/lms/djangoapps/courseware/models.py @@ -103,6 +103,9 @@ class StudentModule(models.Model): class Meta(object): app_label = "courseware" unique_together = (('student', 'module_state_key', 'course_id'),) + indexes = [ + models.Index(fields=['module_state_key', 'grade', 'student'], name="courseware_stats") + ] # Internal state of the object state = models.TextField(null=True, blank=True)