Force the CourseKey alter tables to be noops from the SQL perspective

This commit is contained in:
Calen Pennington
2017-08-24 11:38:05 -04:00
parent 0faa683776
commit ceb0814fff
4 changed files with 33 additions and 5 deletions

View File

@@ -5,6 +5,16 @@ from django.db import migrations, models
import openedx.core.djangoapps.xmodule_django.models
# This should only be used for migrations that have be verified to have a net-neutral sql
# change generated by Django
class NoSqlAlterField(migrations.AlterField):
def database_forwards(self, app_label, schema_editor, from_state, to_state):
return
def database_backwards(self, app_label, schema_editor, from_state, to_state):
return
class Migration(migrations.Migration):
dependencies = [
@@ -32,7 +42,7 @@ class Migration(migrations.Migration):
# name to above).
# We deliberately leave db_constraint set to False because the column
# isn't currently constrained
migrations.AlterField(
NoSqlAlterField(
model_name='coursemode',
name='course',
field=models.ForeignKey(related_name='modes', db_constraint=False, default=None, to='course_overviews.CourseOverview'),

View File

@@ -41,7 +41,12 @@ class CourseMode(models.Model):
class Meta(object):
app_label = "course_modes"
course = models.ForeignKey(CourseOverview, db_constraint=False, db_index=True, related_name='modes')
course = models.ForeignKey(
CourseOverview,
db_constraint=False,
db_index=True,
related_name='modes',
)
# Django sets the `course_id` property in __init__ with the value from the database
# This pair of properties converts that into a proper CourseKey

View File

@@ -6,6 +6,16 @@ import django.db.models.deletion
import openedx.core.djangoapps.xmodule_django.models
# This should only be used for migrations that have be verified to have a net-neutral sql
# change generated by Django
class NoSqlAlterField(migrations.AlterField):
def database_forwards(self, app_label, schema_editor, from_state, to_state):
return
def database_backwards(self, app_label, schema_editor, from_state, to_state):
return
class Migration(migrations.Migration):
dependencies = [
@@ -41,13 +51,13 @@ class Migration(migrations.Migration):
# Alter the fields to make them ForeignKeys (leaving off the db_constraint so
# that we don't create it at migration time). The db_column is left off because
# it defaults to ${field_name}_id, which we pinned it to up above.
migrations.AlterField(
NoSqlAlterField(
model_name='courseenrollment',
name='course',
field=models.ForeignKey(db_constraint=False, to='course_overviews.CourseOverview'),
preserve_default=True,
),
migrations.AlterField(
NoSqlAlterField(
model_name='historicalcourseenrollment',
name='course',
field=models.ForeignKey(related_name='+', on_delete=django.db.models.deletion.DO_NOTHING, db_constraint=False, blank=True, to='course_overviews.CourseOverview', null=True),

View File

@@ -996,7 +996,10 @@ class CourseEnrollment(models.Model):
user = models.ForeignKey(User)
course = models.ForeignKey(CourseOverview, db_constraint=False)
course = models.ForeignKey(
CourseOverview,
db_constraint=False,
)
@property
def course_id(self):