2020-01-14 21:59:46 +01:00
|
|
|
from django.db import connection, migrations
|
2023-03-04 01:40:40 +01:00
|
|
|
from django.db.backends.base.schema import BaseDatabaseSchemaEditor
|
2018-05-19 05:39:13 +02:00
|
|
|
from django.db.migrations.state import StateApps
|
2020-05-04 01:15:36 +02:00
|
|
|
from psycopg2.sql import SQL
|
2020-01-14 21:59:46 +01:00
|
|
|
|
2018-05-31 02:34:15 +02:00
|
|
|
from zerver.lib.migrate import do_batch_update
|
2018-05-19 05:39:13 +02:00
|
|
|
|
2020-01-14 21:59:46 +01:00
|
|
|
|
2022-05-27 23:33:51 +02:00
|
|
|
def rebuild_pgroonga_index(apps: StateApps, schema_editor: BaseDatabaseSchemaEditor) -> None:
|
2018-05-19 05:39:13 +02:00
|
|
|
with connection.cursor() as cursor:
|
2020-05-04 01:15:36 +02:00
|
|
|
do_batch_update(
|
|
|
|
cursor,
|
|
|
|
"zerver_message",
|
|
|
|
[SQL("search_pgroonga = escape_html(subject) || ' ' || rendered_content")],
|
|
|
|
batch_size=10000,
|
|
|
|
)
|
2018-05-19 05:39:13 +02:00
|
|
|
|
2021-02-12 08:19:30 +01:00
|
|
|
|
2018-05-19 05:39:13 +02:00
|
|
|
class Migration(migrations.Migration):
|
|
|
|
atomic = False
|
|
|
|
|
|
|
|
dependencies = [
|
2021-02-12 08:20:45 +01:00
|
|
|
("pgroonga", "0001_enable"),
|
2018-05-19 05:39:13 +02:00
|
|
|
]
|
|
|
|
|
|
|
|
operations = [
|
2021-02-12 08:19:30 +01:00
|
|
|
migrations.RunPython(rebuild_pgroonga_index, reverse_code=migrations.RunPython.noop),
|
2018-05-19 05:39:13 +02:00
|
|
|
]
|