Skip to content

Addons: split model and data migrations #11744

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Nov 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 0 additions & 25 deletions readthedocs/projects/migrations/0128_addons_notifications.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Up @@ -8,7 +8,7 @@ class Migration(migrations.Migration):
safe = Safe.after_deploy

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

operations = [
Expand Down