Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add indexes to LearnerCourseGradeMetrics fields #288

Merged
merged 1 commit into from
Dec 3, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11.29 on 2020-12-02 21:08
"""
Hand edited to run separate database and state migrations to add indexes to
LearnerCourseGradeMetrics
"""
from __future__ import unicode_literals

from django.db import migrations, models
from django.db import connection


def compat_drop_index(index, table):
"""Compatibility function to drop a database index

Because MySQL requires the table name in the drop statement and SQLite
fails if the `ON table_name` is provided
"""
if connection.vendor == 'mysql':
return 'DROP INDEX {index} ON {table}'.format(index=index, table=table)
else:
return 'DROP INDEX {index}'.format(index=index)


class Migration(migrations.Migration):

atomic = False

dependencies = [
('figures', '0012_alter_pipelineerror_field'),
]

operations = [
migrations.SeparateDatabaseAndState(
state_operations=[
migrations.AlterField(
model_name='learnercoursegrademetrics',
name='course_id',
field=models.CharField(blank=True, db_index=True, max_length=255),
),
migrations.AlterField(
model_name='learnercoursegrademetrics',
name='date_for',
field=models.DateField(db_index=True),
),
],
database_operations=[
migrations.RunSQL(sql="""
CREATE INDEX figures_learnercoursegrademetrics_course_id_599c26b2
ON figures_learnercoursegrademetrics (course_id);
""", reverse_sql=compat_drop_index(
index='figures_learnercoursegrademetrics_course_id_599c26b2',
table='figures_learnercoursegrademetrics')),
migrations.RunSQL(sql="""
CREATE INDEX figures_learnercoursegrademetrics_date_for_3872d749
ON figures_learnercoursegrademetrics (date_for);
""", reverse_sql=compat_drop_index(
index='figures_learnercoursegrademetrics_date_for_3872d749',
table='figures_learnercoursegrademetrics')
)
]
)
]
4 changes: 2 additions & 2 deletions figures/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -302,14 +302,14 @@ class LearnerCourseGradeMetrics(TimeStampedModel):
"""
# TODO: Review the most appropriate on_delete behaviour
site = models.ForeignKey(Site, on_delete=models.CASCADE)
date_for = models.DateField()
date_for = models.DateField(db_index=True)
# TODO: We should require the user
# TODO: Review the most appropriate on_delete behaviour
user = models.ForeignKey(settings.AUTH_USER_MODEL,
blank=True,
null=True,
on_delete=models.CASCADE)
course_id = models.CharField(max_length=255, blank=True)
course_id = models.CharField(max_length=255, blank=True, db_index=True)
points_possible = models.FloatField()
points_earned = models.FloatField()
sections_worked = models.IntegerField()
Expand Down