Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
migrations: Remove bugged Recipients in 0419.
Mateusz Manderaf6f7e4c53fa5
diff --git a/zerver/migrations/0419_backfill_message_realm.py b/zerver/migrations/0419_backfill_message_realm.pyindex daa89ac0445..c6f77ee6f45 100644--- a/zerver/migrations/0419_backfill_message_realm.py+++ b/zerver/migrations/0419_backfill_message_realm.py@@ -2,7 +2,7 @@ from django.conf import settingsfrom django.db import migrations, transactionfrom django.db.backends.postgresql.schema import BaseDatabaseSchemaEditorfrom django.db.migrations.state import StateApps-from django.db.models import Max, OuterRef, Subquery+from django.db.models import Exists, Max, OuterRef, Subquerydef backfill_message_realm(apps: StateApps, schema_editor: BaseDatabaseSchemaEditor) -> None:@@ -14,9 +14,23 @@ def backfill_message_realm(apps: StateApps, schema_editor: BaseDatabaseSchemaEdiArchivedMessage = apps.get_model("zerver", "ArchivedMessage")Recipient = apps.get_model("zerver", "Recipient")Subscription = apps.get_model("zerver", "Subscription")+ Stream = apps.get_model("zerver", "Stream")UserProfile = apps.get_model("zerver", "UserProfile")+ Huddle = apps.get_model("zerver", "Huddle")print()++ print("Deleting dangling Recipient objects and their messages, which are inaccessible.")+ Recipient.objects.annotate(+ has_object=Exists(UserProfile.objects.filter(id=OuterRef("type_id")))+ ).filter(type=RECIPIENT_PERSONAL, has_object=False).delete()+ Recipient.objects.annotate(+ has_object=Exists(Stream.objects.filter(id=OuterRef("type_id")))+ ).filter(type=RECIPIENT_STREAM, has_object=False).delete()+ Recipient.objects.annotate(+ has_object=Exists(Huddle.objects.filter(id=OuterRef("type_id")))+ ).filter(type=RECIPIENT_HUDDLE, has_object=False).delete()+BATCH_SIZE = 10000for message_model in [Message, ArchivedMessage]:lower_bound = 1