Merge lp:~wgrant/launchpad/no-tsearch2 into lp:launchpad

Proposed by William Grant
Status: Merged
Merged at revision: 18659
Proposed branch: lp:~wgrant/launchpad/no-tsearch2
Merge into: lp:launchpad
Diff against target: 89 lines (+73/-1)
2 files modified
database/schema/patch-2209-84-0.sql (+72/-0)
database/schema/security.cfg (+1/-1)
To merge this branch: bzr merge lp:~wgrant/launchpad/no-tsearch2
Reviewer Review Type Date Requested Status
Stuart Bishop (community) Approve
Launchpad code reviewers Pending
Review via email: mp+345508@code.launchpad.net

Commit message

Drop the tsearch2 extension and ts2 schema.

Description of the change

PostgreSQL 10 removes contrib/tsearch2.

From the extension only ts2.tsvector survives, as
public.ts2_tsvector. It's an alias for pg_catalog.tsvector, but we
can't change existing column types without table rewrites or catalog
hackery.

ts2.ftiupdate() and the ts2.default text search config move into
public.

To post a comment you must log in.
Revision history for this message
Stuart Bishop (stub) wrote :

Looks sane and not scary. It should either just work, or cause staging to explode with unexpected fallout.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== added file 'database/schema/patch-2209-84-0.sql'
2--- database/schema/patch-2209-84-0.sql 1970-01-01 00:00:00 +0000
3+++ database/schema/patch-2209-84-0.sql 2018-05-15 06:11:27 +0000
4@@ -0,0 +1,72 @@
5+-- Copyright 2018 Canonical Ltd. This software is licensed under the
6+-- GNU Affero General Public License version 3 (see the file LICENSE).
7+
8+SET client_min_messages=ERROR;
9+
10+-- Drop the tsearch2 extension and ts2 schema.
11+--
12+-- PostgreSQL 10 removes contrib/tsearch2.
13+--
14+-- From the extension only ts2.tsvector survives, as
15+-- public.ts2_tsvector. It's an alias for pg_catalog.tsvector, but we
16+-- can't change existing column types without table rewrites or catalog
17+-- hackery.
18+--
19+-- ts2.ftiupdate() and the ts2.default text search config move into
20+-- public.
21+
22+ALTER EXTENSION tsearch2 DROP DOMAIN ts2.tsvector;
23+DROP EXTENSION tsearch2;
24+
25+ALTER DOMAIN ts2.tsvector RENAME TO ts2_tsvector;
26+ALTER DOMAIN ts2.ts2_tsvector SET SCHEMA public;
27+
28+ALTER TEXT SEARCH CONFIGURATION ts2.default SET SCHEMA public;
29+
30+ALTER FUNCTION ts2.ftiupdate() SET SCHEMA public;
31+
32+-- From launchpad-2209-00-0.sql, but without ts2 schema specifiers since it's
33+-- all in pg_catalog now.
34+CREATE OR REPLACE FUNCTION ftiupdate() RETURNS trigger
35+ LANGUAGE plpythonu
36+ AS $_$
37+ new = TD["new"]
38+ args = TD["args"][:]
39+
40+ # Short circuit if none of the relevant columns have been
41+ # modified and fti is not being set to NULL (setting the fti
42+ # column to NULL is thus how we can force a rebuild of the fti
43+ # column).
44+ if TD["event"] == "UPDATE" and new["fti"] != None:
45+ old = TD["old"]
46+ relevant_modification = False
47+ for column_name in args[::2]:
48+ if new[column_name] != old[column_name]:
49+ relevant_modification = True
50+ break
51+ if not relevant_modification:
52+ return "OK"
53+
54+ # Generate an SQL statement that turns the requested
55+ # column values into a weighted tsvector
56+ sql = []
57+ for i in range(0, len(args), 2):
58+ sql.append(
59+ "setweight(to_tsvector('default', coalesce("
60+ "substring(ltrim($%d) from 1 for 2500),'')),"
61+ "CAST($%d AS \"char\"))" % (i + 1, i + 2))
62+ args[i] = new[args[i]]
63+
64+ sql = "SELECT %s AS fti" % "||".join(sql)
65+
66+ # Execute and store in the fti column
67+ plan = plpy.prepare(sql, ["text", "char"] * (len(args)/2))
68+ new["fti"] = plpy.execute(plan, args, 1)[0]["fti"]
69+
70+ # Tell PostgreSQL we have modified the data
71+ return "MODIFY"
72+$_$;
73+
74+DROP SCHEMA ts2;
75+
76+INSERT INTO LaunchpadDatabaseRevision VALUES (2209, 84, 0);
77
78=== modified file 'database/schema/security.cfg'
79--- database/schema/security.cfg 2018-04-10 13:07:25 +0000
80+++ database/schema/security.cfg 2018-05-15 06:11:27 +0000
81@@ -7,7 +7,7 @@
82 # creates new entries by first doing an insert (to get the id) and then
83 # issuing an update
84 [DEFAULT]
85-public_schemas=ts2
86+public_schemas=
87
88 [public]
89 type=group