models: Manage index from migration 0095 with Django.

Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
Anders Kaseorg
2022-02-22 22:44:03 -08:00
committed by Tim Abbott
parent ddd217efdf
commit 001a310d75
2 changed files with 16 additions and 8 deletions

View File

@@ -1,4 +1,5 @@
from django.db import migrations from django.db import migrations, models
from django.db.models import Q
class Migration(migrations.Migration): class Migration(migrations.Migration):
@@ -8,12 +9,13 @@ class Migration(migrations.Migration):
] ]
operations = [ operations = [
migrations.RunSQL( migrations.AddIndex(
""" model_name="usermessage",
CREATE INDEX zerver_usermessage_unread_message_id index=models.Index(
ON zerver_usermessage (user_profile_id, message_id) "user_profile",
WHERE (flags & 1) = 0; "message",
""", condition=Q(flags__andz=1),
reverse_sql="DROP INDEX zerver_usermessage_unread_message_id;", name="zerver_usermessage_unread_message_id",
),
), ),
] ]

View File

@@ -3128,6 +3128,12 @@ class UserMessage(AbstractUserMessage):
class Meta(AbstractUserMessage.Meta): class Meta(AbstractUserMessage.Meta):
indexes = [ indexes = [
models.Index(
"user_profile",
"message",
condition=Q(flags__andz=AbstractUserMessage.flags.read.mask),
name="zerver_usermessage_unread_message_id",
),
models.Index( models.Index(
"user_profile", "user_profile",
"message", "message",