Skip to content

Commit 7bbc019

Browse files
authored
fix: Make container_type backfill reversible
This is trivial and will be helpful for devs who need to move back and forth across this migrations step for whatever reason (switching branches, resolving DB issues).
1 parent 435f380 commit 7bbc019

1 file changed

Lines changed: 12 additions & 1 deletion

File tree

src/openedx_content/migrations/0005_containertypes.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,14 @@ def backfill_container_types(apps, schema_editor):
2929
raise ValueError(f"container {unknown_containers[0]} is of unknown container type. Cannot apply migration.")
3030

3131

32+
def clear_container_types(apps, schema_editor):
33+
"""
34+
Drop the contents of the container_type field for the reverse migration.
35+
"""
36+
Container = apps.get_model("openedx_content", "Container")
37+
Container.objects.update(container_type=None)
38+
39+
3240
class Migration(migrations.Migration):
3341
dependencies = [
3442
("openedx_content", "0004_componenttype_constraint"),
@@ -68,7 +76,10 @@ class Migration(migrations.Migration):
6876
),
6977
),
7078
# 3. Populate the container_type column, which is currently NULL for all existing containers
71-
migrations.RunPython(backfill_container_types),
79+
migrations.RunPython(
80+
code=backfill_container_types,
81+
reverse_code=clear_container_types,
82+
),
7283
# 4. disallow NULL values from now on
7384
migrations.AlterField(
7485
model_name="container",

0 commit comments

Comments
 (0)