fix: Use a "through" model for the ManyToManyField fields in CourseSection

and CourseSectionSequence to ensure that cascading deletes will occur to delete
the relation upon deletion of a foreign-keyed object.

This commit is phase 3 of 4 in order to ensure a smooth deploy. The phases:
1) Add separate through models for user partition groups, add fields to point to the
   separate models, and start writing to those fields as well. (COMPLETE)
2) After all models have been re-generated, switch code over to use separate through
   model fields backed by the separate through models *and* stop writing to the original
   ManyToManyField field. (COMPLETE)
3) After phase 2 is deployed smoothly, remove the original ManyToManyField fields. (This PR!)
4) After phase 3 is deployed smoothly, rename the new fields to have the same name
   as the old fields, so new_user_partition_groups -> user_partition_groups.

This PR is designed to be able to easily be rolled-back if anything goes wrong.
This commit is contained in:
Julia Eskew
2021-07-07 12:47:22 -04:00
committed by Julia Eskew
parent 1b0b703144
commit a68bfe28b9
2 changed files with 21 additions and 4 deletions

View File

@@ -0,0 +1,21 @@
# Generated by Django 2.2.24 on 2021-07-07 16:45
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('learning_sequences', '0015_add_user_partition_group_unique_constraint'),
]
operations = [
migrations.RemoveField(
model_name='coursesection',
name='user_partition_groups',
),
migrations.RemoveField(
model_name='coursesectionsequence',
name='user_partition_groups',
),
]

View File

@@ -202,8 +202,6 @@ class CourseSection(CourseContentVisibilityMixin, TimeStampedModel):
# What is our position within the Course? (starts with 0)
ordering = models.PositiveIntegerField(null=False)
user_partition_groups = models.ManyToManyField(UserPartitionGroup)
new_user_partition_groups = models.ManyToManyField(
UserPartitionGroup,
db_index=True,
@@ -266,8 +264,6 @@ class CourseSectionSequence(CourseContentVisibilityMixin, TimeStampedModel):
# sequences across 20 sections, the numbering here would be 0-199.
ordering = models.PositiveIntegerField(null=False)
user_partition_groups = models.ManyToManyField(UserPartitionGroup)
new_user_partition_groups = models.ManyToManyField(
UserPartitionGroup,
db_index=True,