2016-04-24 17:08:51 +02:00
|
|
|
from django.conf import settings
|
2020-01-14 21:59:46 +01:00
|
|
|
from django.db import migrations
|
2016-04-24 17:08:51 +02:00
|
|
|
|
|
|
|
|
|
|
|
class Migration(migrations.Migration):
|
|
|
|
|
|
|
|
dependencies = [
|
2021-02-12 08:20:45 +01:00
|
|
|
("zerver", "0001_initial"),
|
2016-04-24 17:08:51 +02:00
|
|
|
]
|
|
|
|
|
|
|
|
database_setting = settings.DATABASES["default"]
|
|
|
|
if "postgres" in database_setting["ENGINE"]:
|
|
|
|
operations = [
|
2021-02-12 08:19:30 +01:00
|
|
|
migrations.RunSQL(
|
|
|
|
[
|
|
|
|
(
|
|
|
|
"""
|
2020-06-14 03:48:07 +02:00
|
|
|
DO $$BEGIN
|
|
|
|
EXECUTE format('ALTER ROLE %%I SET search_path TO %%L,public,pgroonga,pg_catalog', %(USER)s, %(SCHEMA)s);
|
2016-04-24 17:08:51 +02:00
|
|
|
|
|
|
|
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);
|
2020-06-14 03:48:07 +02:00
|
|
|
END$$
|
2021-02-12 08:19:30 +01:00
|
|
|
""",
|
|
|
|
database_setting,
|
|
|
|
)
|
|
|
|
],
|
|
|
|
[
|
|
|
|
(
|
|
|
|
"""
|
2020-06-14 03:48:07 +02:00
|
|
|
DO $$BEGIN
|
2016-04-24 17:08:51 +02:00
|
|
|
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;
|
|
|
|
|
2020-06-14 03:48:07 +02:00
|
|
|
EXECUTE format('ALTER ROLE %%I SET search_path TO %%L,public', %(USER)s, %(SCHEMA)s);
|
|
|
|
END$$
|
2021-02-12 08:19:30 +01:00
|
|
|
""",
|
|
|
|
database_setting,
|
|
|
|
)
|
|
|
|
],
|
|
|
|
),
|
2016-04-24 17:08:51 +02:00
|
|
|
]
|
|
|
|
else:
|
|
|
|
operations = []
|