Skip to content

Commit

Permalink
Addons: split model and data migrations (#11744)
Browse files Browse the repository at this point in the history
humitos authored Nov 5, 2024

Unverified

This commit is not signed, but one or more authors requires that any commit attributed to them is signed.
1 parent 6169e5f commit 7c51438
Showing 3 changed files with 34 additions and 26 deletions.
25 changes: 0 additions & 25 deletions readthedocs/projects/migrations/0128_addons_notifications.py
Original file line number Diff line number Diff line change
@@ -4,30 +4,6 @@
from django_safemigrate import Safe


def forward_add_fields(apps, schema_editor):
AddonsConfig = apps.get_model("projects", "AddonsConfig")
for addons in AddonsConfig.objects.filter(project__isnull=False):
addons.notifications_show_on_latest = (
addons.stable_latest_version_warning_enabled
)
addons.notifications_show_on_non_stable = (
addons.stable_latest_version_warning_enabled
)
addons.notifications_show_on_external = addons.external_version_warning_enabled
addons.save()


def reverse_remove_fields(apps, schema_editor):
AddonsConfig = apps.get_model("projects", "AddonsConfig")
for addons in AddonsConfig.objects.filter(project__isnull=False):
addons.stable_latest_version_warning_enabled = (
addons.notifications_show_on_latest
or addons.notifications_show_on_non_stable
)
addons.external_version_warning_enabled = addons.notifications_show_on_external
addons.save()


class Migration(migrations.Migration):
safe = Safe.before_deploy

@@ -76,5 +52,4 @@ class Migration(migrations.Migration):
name="notifications_show_on_non_stable",
field=models.BooleanField(default=True),
),
migrations.RunPython(forward_add_fields, reverse_remove_fields),
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Generated by Django 4.2.16 on 2024-11-05 17:33

from django.db import migrations
from django.db.models import F
from django_safemigrate import Safe


def forward_add_fields(apps, schema_editor):
AddonsConfig = apps.get_model("projects", "AddonsConfig")
AddonsConfig.objects.filter(project__isnull=False).update(
notifications_show_on_latest=F("stable_latest_version_warning_enabled"),
notifications_show_on_non_stable=F("stable_latest_version_warning_enabled"),
notifications_show_on_external=F("external_version_warning_enabled"),
)


def reverse_remove_fields(apps, schema_editor):
AddonsConfig = apps.get_model("projects", "AddonsConfig")
AddonsConfig.objects.filter(project__isnull=False).update(
stable_latest_version_warning_enabled=F("notifications_show_on_latest"),
external_version_warning_enabled=F("notifications_show_on_external"),
)

class Migration(migrations.Migration):
safe = Safe.before_deploy

dependencies = [
("projects", "0128_addons_notifications"),
]

operations = [
migrations.RunPython(forward_add_fields, reverse_remove_fields),
]
Original file line number Diff line number Diff line change
@@ -8,7 +8,7 @@ class Migration(migrations.Migration):
safe = Safe.after_deploy

dependencies = [
("projects", "0128_addons_notifications"),
("projects", "0129_addons_notification_data_migration"),
]

operations = [

0 comments on commit 7c51438

Please sign in to comment.