From e655fc9e6b8c6df4c4a14bce4e0f73f14fa36b0c Mon Sep 17 00:00:00 2001 From: Julia Eskew Date: Wed, 7 Jul 2021 12:47:22 -0400 Subject: [PATCH] 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. --- ...rough_model_for_user_partition_groups_2.py | 21 +++++++++++++++++++ .../content/learning_sequences/models.py | 4 ---- 2 files changed, 21 insertions(+), 4 deletions(-) create mode 100644 openedx/core/djangoapps/content/learning_sequences/migrations/0016_through_model_for_user_partition_groups_2.py diff --git a/openedx/core/djangoapps/content/learning_sequences/migrations/0016_through_model_for_user_partition_groups_2.py b/openedx/core/djangoapps/content/learning_sequences/migrations/0016_through_model_for_user_partition_groups_2.py new file mode 100644 index 000000000000..ecc1e4157e24 --- /dev/null +++ b/openedx/core/djangoapps/content/learning_sequences/migrations/0016_through_model_for_user_partition_groups_2.py @@ -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', + ), + ] diff --git a/openedx/core/djangoapps/content/learning_sequences/models.py b/openedx/core/djangoapps/content/learning_sequences/models.py index 6674a2dcea36..de0881abe5f6 100644 --- a/openedx/core/djangoapps/content/learning_sequences/models.py +++ b/openedx/core/djangoapps/content/learning_sequences/models.py @@ -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,