Skip to content

Commit

Permalink
fix: Use a "through" model for the ManyToManyField fields in CourseSe…
Browse files Browse the repository at this point in the history
…ction

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.
  • Loading branch information
Julia Eskew authored and Julia Eskew committed Jul 13, 2021
1 parent 1b0b703 commit a68bfe2
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -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',
),
]
4 changes: 0 additions & 4 deletions openedx/core/djangoapps/content/learning_sequences/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit a68bfe2

Please sign in to comment.