pgroonga: Remove unnecessary code from first migration.

This avoids doing a bunch of extra work, including a downtime-risky
`CREATE INDEX` without CONCURRENTLY, when migrating a modern Zulip
system to PGroonga the first time.
This commit is contained in:
Tim Abbott 2021-05-27 17:39:59 -07:00 committed by Tim Abbott
parent e0992c85fb
commit 1103720f45
2 changed files with 17 additions and 39 deletions

View File

@ -11,43 +11,11 @@ class Migration(migrations.Migration):
database_setting = settings.DATABASES["default"]
operations = [
# This previously had additional operations, but they are all
# undone in migration 0003 because we switched to using the
# PGroonga v2 API.
migrations.RunSQL(
[
(
"""
DO $$BEGIN
EXECUTE format('ALTER ROLE %%I SET search_path TO %%L,public,pgroonga,pg_catalog', %(USER)s, %(SCHEMA)s);
SET search_path = %(SCHEMA)s,public,pgroonga,pg_catalog;
ALTER TABLE zerver_message ADD COLUMN search_pgroonga text;
-- TODO: We want to use CREATE INDEX CONCURRENTLY but it can't be used in
-- transaction. Django uses transaction implicitly.
-- Django 1.10 may solve the problem.
CREATE INDEX zerver_message_search_pgroonga ON zerver_message
USING pgroonga(search_pgroonga pgroonga.text_full_text_search_ops);
END$$
""",
database_setting,
)
],
[
(
"""
DO $$BEGIN
SET search_path = %(SCHEMA)s,public,pgroonga,pg_catalog;
DROP INDEX zerver_message_search_pgroonga;
ALTER TABLE zerver_message DROP COLUMN search_pgroonga;
SET search_path = %(SCHEMA)s,public;
EXECUTE format('ALTER ROLE %%I SET search_path TO %%L,public', %(USER)s, %(SCHEMA)s);
END$$
""",
database_setting,
)
],
sql="ALTER TABLE zerver_message ADD COLUMN search_pgroonga text;",
reverse_sql="ALTER TABLE zerver_message DROP COLUMN search_pgroonga;",
),
]

View File

@ -11,6 +11,16 @@ class Migration(migrations.Migration):
database_setting = settings.DATABASES["default"]
operations = [
# 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).
migrations.RunSQL(
[
(
@ -20,7 +30,7 @@ EXECUTE format('ALTER ROLE %%I SET search_path TO %%L,public', %(USER)s, %(SCHEM
SET search_path = %(SCHEMA)s,public;
DROP INDEX zerver_message_search_pgroonga;
DROP INDEX IF EXISTS zerver_message_search_pgroonga;
END$$
""",
database_setting,
@ -39,7 +49,7 @@ EXECUTE format('ALTER ROLE %%I SET search_path TO %%L,public,pgroonga,pg_catalog
SET search_path = %(SCHEMA)s,public,pgroonga,pg_catalog;
DROP INDEX zerver_message_search_pgroonga;
DROP INDEX IF EXISTS zerver_message_search_pgroonga;
END$$
""",
database_setting,