LP#1671150 Fix unqualified unaccent call
authorJeff Godin <jgodin@tadl.org>
Fri, 23 Jun 2017 00:03:29 +0000 (20:03 -0400)
committerJeff Godin <jgodin@tadl.org>
Tue, 7 Nov 2017 20:57:00 +0000 (15:57 -0500)
Fix index creation failures when using pg_restore by qualifying the
unaccent() function call and tsearch dictionary argument in the
evergreen.unaccent_and_squash() function.

Signed-off-by: Jeff Godin <jgodin@tadl.org>
Open-ILS/src/sql/Pg/000.functions.general.sql
Open-ILS/src/sql/Pg/upgrade/XXXX.schema.qualify_unaccent_refs.sql [new file with mode: 0644]

index 8b0dd63..e0aae8d 100644 (file)
@@ -89,7 +89,7 @@ LANGUAGE plpgsql;
 CREATE OR REPLACE FUNCTION evergreen.unaccent_and_squash ( IN arg text) RETURNS text
     IMMUTABLE STRICT AS $$
        BEGIN
-       RETURN evergreen.lowercase(unaccent(regexp_replace(arg, '[\s[:punct:]]','','g')));
+       RETURN evergreen.lowercase(public.unaccent('public.unaccent', regexp_replace(arg, '[\s[:punct:]]','','g')));
        END;
 $$ LANGUAGE PLPGSQL;
 
diff --git a/Open-ILS/src/sql/Pg/upgrade/XXXX.schema.qualify_unaccent_refs.sql b/Open-ILS/src/sql/Pg/upgrade/XXXX.schema.qualify_unaccent_refs.sql
new file mode 100644 (file)
index 0000000..575bb5a
--- /dev/null
@@ -0,0 +1,32 @@
+-- Evergreen DB patch XXXX.schema.qualify_unaccent_refs.sql
+--
+-- LP#1671150 Fix unaccent() function call in evergreen.unaccent_and_squash()
+--
+BEGIN;
+
+
+-- check whether patch can be applied
+-- FIXME: uncomment when we have an upgrade number
+-- SELECT evergreen.upgrade_deps_block_check('XXXX', :eg_version);
+
+CREATE OR REPLACE FUNCTION evergreen.unaccent_and_squash ( IN arg text) RETURNS text
+    IMMUTABLE STRICT AS $$
+        BEGIN
+        RETURN evergreen.lowercase(public.unaccent('public.unaccent', regexp_replace(arg, '[\s[:punct:]]','','g')));
+        END;
+$$ LANGUAGE PLPGSQL;
+
+-- Drop indexes if present, so that we can re-create them
+DROP INDEX IF EXISTS actor.actor_usr_first_given_name_unaccent_idx;
+DROP INDEX IF EXISTS actor.actor_usr_second_given_name_unaccent_idx;
+DROP INDEX IF EXISTS actor.actor_usr_family_name_unaccent_idx;
+DROP INDEX IF EXISTS actor.actor_usr_usrname_unaccent_idx;
+
+-- Create (or re-create) indexes -- they may have been missing to begin with if pg_restore
+-- failed to create them due to the previously unqualified call to unaccent()
+CREATE INDEX actor_usr_first_given_name_unaccent_idx ON actor.usr (evergreen.unaccent_and_squash(first_given_name));
+CREATE INDEX actor_usr_second_given_name_unaccent_idx ON actor.usr (evergreen.unaccent_and_squash(second_given_name));
+CREATE INDEX actor_usr_family_name_unaccent_idx ON actor.usr (evergreen.unaccent_and_squash(family_name));
+CREATE INDEX actor_usr_usrname_unaccent_idx ON actor.usr (evergreen.unaccent_and_squash(usrname));
+
+COMMIT;