From: Galen Charlton Date: Tue, 4 Sep 2018 21:46:49 +0000 (-0400) Subject: LP#1514085: sync schema update script to reflect changes in master X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=889898936925335c545091721b6db008148625b3;p=evergreen%2Fpines.git LP#1514085: sync schema update script to reflect changes in master Signed-off-by: Galen Charlton --- diff --git a/Open-ILS/src/sql/Pg/upgrade/XXXX.schema.vandelay-state-tracking.sql b/Open-ILS/src/sql/Pg/upgrade/XXXX.schema.vandelay-state-tracking.sql index 8c2f7655df..bce64d0c7d 100644 --- a/Open-ILS/src/sql/Pg/upgrade/XXXX.schema.vandelay-state-tracking.sql +++ b/Open-ILS/src/sql/Pg/upgrade/XXXX.schema.vandelay-state-tracking.sql @@ -367,6 +367,37 @@ BEGIN -- do nothing END; + -- propagate preferred name values from the source user to the + -- destination user, but only when values are not being replaced. + WITH susr AS (SELECT * FROM actor.usr WHERE id = src_usr) + UPDATE actor.usr SET + pref_prefix = + COALESCE(pref_prefix, (SELECT pref_prefix FROM susr)), + pref_first_given_name = + COALESCE(pref_first_given_name, (SELECT pref_first_given_name FROM susr)), + pref_second_given_name = + COALESCE(pref_second_given_name, (SELECT pref_second_given_name FROM susr)), + pref_family_name = + COALESCE(pref_family_name, (SELECT pref_family_name FROM susr)), + pref_suffix = + COALESCE(pref_suffix, (SELECT pref_suffix FROM susr)) + WHERE id = dest_usr; + + -- Copy and deduplicate name keywords + -- String -> array -> rows -> DISTINCT -> array -> string + WITH susr AS (SELECT * FROM actor.usr WHERE id = src_usr), + dusr AS (SELECT * FROM actor.usr WHERE id = dest_usr) + UPDATE actor.usr SET name_keywords = ( + WITH keywords AS ( + SELECT DISTINCT UNNEST( + REGEXP_SPLIT_TO_ARRAY( + COALESCE((SELECT name_keywords FROM susr), '') || ' ' || + COALESCE((SELECT name_keywords FROM dusr), ''), E'\\s+' + ) + ) AS parts + ) SELECT ARRAY_TO_STRING(ARRAY_AGG(kw.parts), ' ') FROM keywords kw + ) WHERE id = dest_usr; + -- Finally, delete the source user DELETE FROM actor.usr WHERE id = src_usr;