Skip to content

Commit

Permalink
Updated migrations to migrate old data
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesbiggs committed Dec 19, 2024
1 parent a47bea9 commit 0b60d78
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 25 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# Generated by Django 5.1.2 on 2024-12-19 16:48
# etna:allowRemoveField

import django.utils.timezone
from django.db import migrations, models
Expand All @@ -11,31 +10,25 @@ class Migration(migrations.Migration):
("articles", "0112_alter_articlepage_body_alter_focusedarticlepage_body"),
]

def migrate_data(apps, schema_editor):
Article = apps.get_model("articles.ArticlePage")
FocusedArticle = apps.get_model("articles.FocusedArticlePage")
RecordArticle = apps.get_model("articles.RecordArticlePage")
for page in Article.objects.all():
if page.newly_published_at:
page.published_date = page.newly_published_at or page.first_published_at or django.utils.timezone.now()
page.save()
for page in FocusedArticle.objects.all():
if page.newly_published_at:
page.published_date = page.newly_published_at or page.first_published_at or django.utils.timezone.now()
page.save()
for page in RecordArticle.objects.all():
if page.newly_published_at:
page.published_date = page.newly_published_at or page.first_published_at or django.utils.timezone.now()
page.save()


operations = [
migrations.RemoveField(
model_name="articlepage",
name="mark_new_on_next_publish",
),
migrations.RemoveField(
model_name="articlepage",
name="newly_published_at",
),
migrations.RemoveField(
model_name="focusedarticlepage",
name="mark_new_on_next_publish",
),
migrations.RemoveField(
model_name="focusedarticlepage",
name="newly_published_at",
),
migrations.RemoveField(
model_name="recordarticlepage",
name="mark_new_on_next_publish",
),
migrations.RemoveField(
model_name="recordarticlepage",
name="newly_published_at",
),
migrations.AddField(
model_name="articlepage",
name="published_date",
Expand Down Expand Up @@ -63,4 +56,5 @@ class Migration(migrations.Migration):
verbose_name="Published date",
),
),
migrations.RunPython(migrate_data),
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Generated by Django 5.1.2 on 2024-12-19 17:51
# etna:allowRemoveField

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
("articles", "0113_remove_articlepage_mark_new_on_next_publish_and_more"),
]

operations = [
migrations.RemoveField(
model_name="articlepage",
name="mark_new_on_next_publish",
),
migrations.RemoveField(
model_name="articlepage",
name="newly_published_at",
),
migrations.RemoveField(
model_name="focusedarticlepage",
name="mark_new_on_next_publish",
),
migrations.RemoveField(
model_name="focusedarticlepage",
name="newly_published_at",
),
migrations.RemoveField(
model_name="recordarticlepage",
name="mark_new_on_next_publish",
),
migrations.RemoveField(
model_name="recordarticlepage",
name="newly_published_at",
),
]

0 comments on commit 0b60d78

Please sign in to comment.