Skip to content

Commit 7c51438

Browse files
authored
Addons: split model and data migrations (#11744)
1 parent 6169e5f commit 7c51438

File tree

3 files changed

+34
-26
lines changed

3 files changed

+34
-26
lines changed

readthedocs/projects/migrations/0128_addons_notifications.py

-25
Original file line numberDiff line numberDiff line change
@@ -4,30 +4,6 @@
44
from django_safemigrate import Safe
55

66

7-
def forward_add_fields(apps, schema_editor):
8-
AddonsConfig = apps.get_model("projects", "AddonsConfig")
9-
for addons in AddonsConfig.objects.filter(project__isnull=False):
10-
addons.notifications_show_on_latest = (
11-
addons.stable_latest_version_warning_enabled
12-
)
13-
addons.notifications_show_on_non_stable = (
14-
addons.stable_latest_version_warning_enabled
15-
)
16-
addons.notifications_show_on_external = addons.external_version_warning_enabled
17-
addons.save()
18-
19-
20-
def reverse_remove_fields(apps, schema_editor):
21-
AddonsConfig = apps.get_model("projects", "AddonsConfig")
22-
for addons in AddonsConfig.objects.filter(project__isnull=False):
23-
addons.stable_latest_version_warning_enabled = (
24-
addons.notifications_show_on_latest
25-
or addons.notifications_show_on_non_stable
26-
)
27-
addons.external_version_warning_enabled = addons.notifications_show_on_external
28-
addons.save()
29-
30-
317
class Migration(migrations.Migration):
328
safe = Safe.before_deploy
339

@@ -76,5 +52,4 @@ class Migration(migrations.Migration):
7652
name="notifications_show_on_non_stable",
7753
field=models.BooleanField(default=True),
7854
),
79-
migrations.RunPython(forward_add_fields, reverse_remove_fields),
8055
]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# Generated by Django 4.2.16 on 2024-11-05 17:33
2+
3+
from django.db import migrations
4+
from django.db.models import F
5+
from django_safemigrate import Safe
6+
7+
8+
def forward_add_fields(apps, schema_editor):
9+
AddonsConfig = apps.get_model("projects", "AddonsConfig")
10+
AddonsConfig.objects.filter(project__isnull=False).update(
11+
notifications_show_on_latest=F("stable_latest_version_warning_enabled"),
12+
notifications_show_on_non_stable=F("stable_latest_version_warning_enabled"),
13+
notifications_show_on_external=F("external_version_warning_enabled"),
14+
)
15+
16+
17+
def reverse_remove_fields(apps, schema_editor):
18+
AddonsConfig = apps.get_model("projects", "AddonsConfig")
19+
AddonsConfig.objects.filter(project__isnull=False).update(
20+
stable_latest_version_warning_enabled=F("notifications_show_on_latest"),
21+
external_version_warning_enabled=F("notifications_show_on_external"),
22+
)
23+
24+
class Migration(migrations.Migration):
25+
safe = Safe.before_deploy
26+
27+
dependencies = [
28+
("projects", "0128_addons_notifications"),
29+
]
30+
31+
operations = [
32+
migrations.RunPython(forward_add_fields, reverse_remove_fields),
33+
]

readthedocs/projects/migrations/0129_addons_remove_old_fields.py renamed to readthedocs/projects/migrations/0130_addons_remove_old_fields.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ class Migration(migrations.Migration):
88
safe = Safe.after_deploy
99

1010
dependencies = [
11-
("projects", "0128_addons_notifications"),
11+
("projects", "0129_addons_notification_data_migration"),
1212
]
1313

1414
operations = [

0 commit comments

Comments
 (0)