From 35102fbdd47c73240f0e1d9d43ae86bcb2f0079b Mon Sep 17 00:00:00 2001 From: Andrew Godwin Date: Sun, 18 Dec 2022 09:22:15 -0700 Subject: [PATCH] Merge timelineevent, urls and post type migration --- activities/migrations/0001_initial.py | 1 + .../0005_post_type_post_type_data.py | 36 -------- .../0005_post_type_timeline_urls.py | 85 +++++++++++++++++++ activities/models/timeline_event.py | 4 + 4 files changed, 90 insertions(+), 36 deletions(-) delete mode 100644 activities/migrations/0005_post_type_post_type_data.py create mode 100644 activities/migrations/0005_post_type_timeline_urls.py diff --git a/activities/migrations/0001_initial.py b/activities/migrations/0001_initial.py index f7961df..875b2ae 100644 --- a/activities/migrations/0001_initial.py +++ b/activities/migrations/0001_initial.py @@ -323,6 +323,7 @@ class Migration(migrations.Migration): ("liked", "Liked"), ("followed", "Followed"), ("boosted", "Boosted"), + ("announcement", "Announcement"), ], max_length=100, ), diff --git a/activities/migrations/0005_post_type_post_type_data.py b/activities/migrations/0005_post_type_post_type_data.py deleted file mode 100644 index ca53677..0000000 --- a/activities/migrations/0005_post_type_post_type_data.py +++ /dev/null @@ -1,36 +0,0 @@ -# Generated by Django 4.1.4 on 2022-12-16 02:52 - -from django.db import migrations, models - - -class Migration(migrations.Migration): - - dependencies = [ - ("activities", "0004_emoji_post_emojis"), - ] - - operations = [ - migrations.AddField( - model_name="post", - name="type", - field=models.CharField( - choices=[ - ("Article", "Article"), - ("Audio", "Audio"), - ("Event", "Event"), - ("Image", "Image"), - ("Note", "Note"), - ("Page", "Page"), - ("Question", "Question"), - ("Video", "Video"), - ], - default="Note", - max_length=20, - ), - ), - migrations.AddField( - model_name="post", - name="type_data", - field=models.JSONField(blank=True, null=True), - ), - ] diff --git a/activities/migrations/0005_post_type_timeline_urls.py b/activities/migrations/0005_post_type_timeline_urls.py new file mode 100644 index 0000000..103d0a6 --- /dev/null +++ b/activities/migrations/0005_post_type_timeline_urls.py @@ -0,0 +1,85 @@ +# Generated by Django 4.1.4 on 2022-12-16 02:52 +import datetime + +from django.db import migrations, models + + +def timeline_event_populate(apps, schema_editor): + """ + Populates all timeline events with a published date before 2001 + with their created date instead + """ + TimelineEvent = apps.get_model("activities", "timelineevent") + TimelineEvent.objects.filter( + published__lt=datetime.datetime(2001, 1, 1, tzinfo=datetime.timezone.utc) + ).update(published=models.F("created")) + + +class Migration(migrations.Migration): + + dependencies = [ + ("activities", "0004_emoji_post_emojis"), + ] + + operations = [ + migrations.AddField( + model_name="post", + name="type", + field=models.CharField( + choices=[ + ("Article", "Article"), + ("Audio", "Audio"), + ("Event", "Event"), + ("Image", "Image"), + ("Note", "Note"), + ("Page", "Page"), + ("Question", "Question"), + ("Video", "Video"), + ], + default="Note", + max_length=20, + ), + ), + migrations.AddField( + model_name="post", + name="type_data", + field=models.JSONField(blank=True, null=True), + ), + migrations.AddField( + model_name="timelineevent", + name="published", + field=models.DateTimeField( + default=datetime.datetime( + 2000, 1, 1, 0, 0, tzinfo=datetime.timezone.utc + ) + ), + preserve_default=False, + ), + migrations.AddField( + model_name="timelineevent", + name="seen", + field=models.BooleanField(default=False), + ), + migrations.AlterField( + model_name="post", + name="object_uri", + field=models.CharField(blank=True, max_length=2048, null=True, unique=True), + ), + migrations.AlterField( + model_name="post", + name="type_data", + field=models.JSONField( + blank=True, + null=True, + ), + ), + migrations.AlterField( + model_name="post", + name="url", + field=models.CharField(blank=True, max_length=2048, null=True), + ), + migrations.RunPython( + code=timeline_event_populate, + reverse_code=lambda a, s: None, + ), + ] diff --git a/activities/models/timeline_event.py b/activities/models/timeline_event.py index 16f8632..90b37eb 100644 --- a/activities/models/timeline_event.py +++ b/activities/models/timeline_event.py @@ -16,6 +16,7 @@ class TimelineEvent(models.Model): liked = "liked" # Someone liking one of our posts followed = "followed" boosted = "boosted" # Someone boosting one of our posts + announcement = "announcement" # Server announcement # The user this event is for identity = models.ForeignKey( @@ -50,6 +51,9 @@ class TimelineEvent(models.Model): related_name="timeline_events_about_us", ) + published = models.DateTimeField() + seen = models.BooleanField(default=False) + created = models.DateTimeField(auto_now_add=True) class Meta: