migration: Set empty subject for DMs and GDMs from Slack.

This migration updates the `subject´ field to an empty string for
DMs and GDMs imported from Slack. This change ensures the previously
converted messages aligns with Zulip standards where private
messages don't have subjects.
This commit is contained in:
Elsa Kihlberg Gawell 2024-11-08 15:01:32 +01:00
parent fe292a4179
commit a8842cec84
1 changed files with 38 additions and 0 deletions

View File

@ -0,0 +1,38 @@
# Generated by Django 5.0.9 on 2024-11-08 13:02
from django.db import migrations
from django.db.backends.base.schema import BaseDatabaseSchemaEditor
from django.db.migrations.state import StateApps
def update_dm_and_gdm_topic_name(apps: StateApps, schema_editor: BaseDatabaseSchemaEditor) -> None:
RECIPIENT_PERSONAL = 1
RECIPIENT_HUDDLE = 3
CLIENT_ID = 1
Message = apps.get_model("zerver", "Message")
# Matches subjects like '2015-08-18 Slack thread 2'
slack_thread_pattern = r"\d{4}-\d{2}-\d{2} Slack thread \d+"
messages_to_update = Message.objects.filter(
sending_client_id=CLIENT_ID,
recipient__type__in=[RECIPIENT_PERSONAL, RECIPIENT_HUDDLE],
subject="Imported from Slack",
) | Message.objects.filter(
sending_client_id=CLIENT_ID,
recipient__type__in=[RECIPIENT_PERSONAL, RECIPIENT_HUDDLE],
subject__regex=slack_thread_pattern,
)
messages_to_update.update(subject="")
class Migration(migrations.Migration):
atomic = False
dependencies = [
("zerver", "0624_alter_realmexport_tarball_size_bytes"),
]
operations = [
migrations.RunPython(update_dm_and_gdm_topic_name),
]