Files
zulip/zerver/management/commands/audit_fts_indexes.py
Mateusz Mandera c231d88d9f upgrade: Add management command to fix FTS indexes.
Upgrading the base OS's dictionary files can corrupt our FTS
indexes. We add a command for fixing them.

Fixes #14982.
2020-07-13 12:40:44 -07:00

20 lines
673 B
Python

from typing import Any
from django.db import connection
from zerver.lib.management import ZulipBaseCommand
class Command(ZulipBaseCommand):
def handle(self, *args: Any, **kwargs: str) -> None:
with connection.cursor() as cursor:
cursor.execute("""
UPDATE zerver_message
SET search_tsvector =
to_tsvector('zulip.english_us_search', subject || rendered_content)
WHERE to_tsvector('zulip.english_us_search', subject || rendered_content) != search_tsvector
""")
fixed_message_count = cursor.rowcount
print(f"Fixed {fixed_message_count} messages.")