mirror of https://github.com/zulip/zulip.git
models: Manage index from migration 0180 with Django.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
parent
cf0eb46afc
commit
23c8a98157
|
@ -1,10 +1,12 @@
|
|||
# Generated by Django 1.11.14 on 2018-08-01 23:05
|
||||
|
||||
import bitfield.models
|
||||
from django.db import migrations
|
||||
from django.db import migrations, models
|
||||
from django.db.models import Q
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
atomic = False
|
||||
|
||||
dependencies = [
|
||||
("zerver", "0179_rename_to_digest_emails_enabled"),
|
||||
|
@ -55,12 +57,13 @@ class Migration(migrations.Migration):
|
|||
default=0,
|
||||
),
|
||||
),
|
||||
migrations.RunSQL(
|
||||
"""
|
||||
CREATE INDEX zerver_usermessage_active_mobile_push_notification_id
|
||||
ON zerver_usermessage (user_profile_id, message_id)
|
||||
WHERE (flags & 4096) != 0;
|
||||
""",
|
||||
reverse_sql="DROP INDEX zerver_usermessage_active_mobile_push_notification_id;",
|
||||
migrations.AddIndex(
|
||||
model_name="usermessage",
|
||||
index=models.Index(
|
||||
"user_profile",
|
||||
"message",
|
||||
condition=Q(flags__andnz=4096),
|
||||
name="zerver_usermessage_active_mobile_push_notification_id",
|
||||
),
|
||||
),
|
||||
]
|
||||
|
|
|
@ -3125,6 +3125,18 @@ class AbstractUserMessage(models.Model):
|
|||
class UserMessage(AbstractUserMessage):
|
||||
message: Message = models.ForeignKey(Message, on_delete=CASCADE)
|
||||
|
||||
class Meta(AbstractUserMessage.Meta):
|
||||
indexes = [
|
||||
models.Index(
|
||||
"user_profile",
|
||||
"message",
|
||||
condition=Q(
|
||||
flags__andnz=AbstractUserMessage.flags.active_mobile_push_notification.mask
|
||||
),
|
||||
name="zerver_usermessage_active_mobile_push_notification_id",
|
||||
),
|
||||
]
|
||||
|
||||
|
||||
def get_usermessage_by_message_id(
|
||||
user_profile: UserProfile, message_id: int
|
||||
|
|
Loading…
Reference in New Issue