Commit ceb0814f by Calen Pennington

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

parent 0faa6837
......@@ -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'),
......
......@@ -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
......
......@@ -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),
......
......@@ -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):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment