2018-05-31 04:53:47 +02:00
|
|
|
from django.conf import settings
|
2020-01-14 21:59:46 +01:00
|
|
|
from django.db import migrations
|
2018-05-31 04:53:47 +02:00
|
|
|
|
|
|
|
|
|
|
|
class Migration(migrations.Migration):
|
|
|
|
atomic = False
|
|
|
|
|
|
|
|
dependencies = [
|
2021-02-12 08:20:45 +01:00
|
|
|
("pgroonga", "0002_html_escape_subject"),
|
2018-05-31 04:53:47 +02:00
|
|
|
]
|
|
|
|
|
|
|
|
database_setting = settings.DATABASES["default"]
|
|
|
|
operations = [
|
2021-05-28 02:39:59 +02:00
|
|
|
# This migration does the following things:
|
|
|
|
# * Undoes the `search_path` changes from the original migration 0001,
|
|
|
|
# which are no longer necessary with the modern PGroonga API.
|
|
|
|
# (Note that we've deleted those changes from the current version of the
|
|
|
|
# 0001 migration).
|
|
|
|
# * Drops a legacy-format v1 index if present (will be only if upgrading
|
|
|
|
# an old server).
|
|
|
|
# * Does a CREATE INDEX CONCURRENTLY to add a PGroonga v2 search index
|
|
|
|
# on the message.search_pgroonga column (which was populated in
|
|
|
|
# migration 0002).
|
2021-02-12 08:19:30 +01:00
|
|
|
migrations.RunSQL(
|
|
|
|
[
|
|
|
|
(
|
|
|
|
"""
|
2020-06-14 04:05:38 +02:00
|
|
|
DO $$BEGIN
|
|
|
|
EXECUTE format('ALTER ROLE %%I SET search_path TO %%L,public', %(USER)s, %(SCHEMA)s);
|
2018-05-31 04:53:47 +02:00
|
|
|
|
|
|
|
SET search_path = %(SCHEMA)s,public;
|
|
|
|
|
2021-05-28 02:39:59 +02:00
|
|
|
DROP INDEX IF EXISTS zerver_message_search_pgroonga;
|
2020-06-14 04:05:38 +02:00
|
|
|
END$$
|
2021-02-12 08:19:30 +01:00
|
|
|
""",
|
|
|
|
database_setting,
|
|
|
|
),
|
|
|
|
"""
|
2018-05-31 04:53:47 +02:00
|
|
|
|
|
|
|
CREATE INDEX CONCURRENTLY zerver_message_search_pgroonga ON zerver_message
|
|
|
|
USING pgroonga(search_pgroonga pgroonga_text_full_text_search_ops_v2);
|
2021-02-12 08:19:30 +01:00
|
|
|
""",
|
|
|
|
],
|
|
|
|
[
|
|
|
|
(
|
|
|
|
"""
|
2020-06-14 04:05:38 +02:00
|
|
|
DO $$BEGIN
|
|
|
|
EXECUTE format('ALTER ROLE %%I SET search_path TO %%L,public,pgroonga,pg_catalog', %(USER)s, %(SCHEMA)s);
|
2018-05-31 04:53:47 +02:00
|
|
|
|
|
|
|
SET search_path = %(SCHEMA)s,public,pgroonga,pg_catalog;
|
|
|
|
|
2021-05-28 02:39:59 +02:00
|
|
|
DROP INDEX IF EXISTS zerver_message_search_pgroonga;
|
2020-06-14 04:05:38 +02:00
|
|
|
END$$
|
2021-02-12 08:19:30 +01:00
|
|
|
""",
|
|
|
|
database_setting,
|
|
|
|
),
|
|
|
|
"""
|
2018-05-31 04:53:47 +02:00
|
|
|
|
|
|
|
CREATE INDEX CONCURRENTLY zerver_message_search_pgroonga ON zerver_message
|
|
|
|
USING pgroonga(search_pgroonga pgroonga.text_full_text_search_ops);
|
2021-02-12 08:19:30 +01:00
|
|
|
""",
|
|
|
|
],
|
|
|
|
),
|
2018-05-31 04:53:47 +02:00
|
|
|
]
|