From a04e6adc065fd294a3360bb23efaa1de0a423192 Mon Sep 17 00:00:00 2001 From: Greg Sabino Mullane Date: Tue, 19 Feb 2008 01:06:06 +0000 Subject: [PATCH] Have update.php change the functions to their new builtin tsearch2 versions if Postgres >= 8.3 --- .../postgres/archives/patch-tsearch2funcs.sql | 29 +++++++++++++++++++ maintenance/postgres/tables.sql | 1 + maintenance/updaters.inc | 7 ++++- 3 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 maintenance/postgres/archives/patch-tsearch2funcs.sql diff --git a/maintenance/postgres/archives/patch-tsearch2funcs.sql b/maintenance/postgres/archives/patch-tsearch2funcs.sql new file mode 100644 index 0000000000..c24efef3df --- /dev/null +++ b/maintenance/postgres/archives/patch-tsearch2funcs.sql @@ -0,0 +1,29 @@ +-- Should be run on Postgres 8.3 or newer to remove the 'default' + +CREATE OR REPLACE FUNCTION ts2_page_title() +RETURNS TRIGGER +LANGUAGE plpgsql AS +$mw$ +BEGIN +IF TG_OP = 'INSERT' THEN + NEW.titlevector = to_tsvector(REPLACE(NEW.page_title,'/',' ')); +ELSIF NEW.page_title != OLD.page_title THEN + NEW.titlevector := to_tsvector(REPLACE(NEW.page_title,'/',' ')); +END IF; +RETURN NEW; +END; +$mw$; + +CREATE OR REPLACE FUNCTION ts2_page_text() +RETURNS TRIGGER +LANGUAGE plpgsql AS +$mw$ +BEGIN +IF TG_OP = 'INSERT' THEN + NEW.textvector = to_tsvector(NEW.old_text); +ELSIF NEW.old_text != OLD.old_text THEN + NEW.textvector := to_tsvector(NEW.old_text); +END IF; +RETURN NEW; +END; +$mw$; diff --git a/maintenance/postgres/tables.sql b/maintenance/postgres/tables.sql index 9ea22bcfd7..500d663166 100644 --- a/maintenance/postgres/tables.sql +++ b/maintenance/postgres/tables.sql @@ -454,6 +454,7 @@ CREATE INDEX job_cmd_namespace_title ON job (job_cmd, job_namespace, job_title); -- Tsearch2 2 stuff. Will fail if we don't have proper access to the tsearch2 tables -- Note: if version 8.3 or higher, we remove the 'default' arg +-- Make sure you also change patch-tsearch2funcs.sql if the funcs below change. ALTER TABLE page ADD titlevector tsvector; CREATE FUNCTION ts2_page_title() RETURNS TRIGGER LANGUAGE plpgsql AS diff --git a/maintenance/updaters.inc b/maintenance/updaters.inc index 15a578e556..c628216056 100644 --- a/maintenance/updaters.inc +++ b/maintenance/updaters.inc @@ -1608,7 +1608,12 @@ function do_postgres_updates() { # Tweak the page_title tsearch2 trigger to filter out slashes # This is create or replace, so harmless to call if not needed - dbsource(archive("patch-ts2pagetitle.sql")); + dbsource(archive('patch-ts2pagetitle.sql')); + + ## If the server is 8.3 or higher, rewrite teh tsearch2 triggers + ## in case they have the old 'default' versions + if ( $numver >= 8.3 ) + dbsource(archive('patch-tsearch2funcs.sql')); return; } -- 2.20.1