From a830ce9aa5ea68ac6e1039ef586cccf8410368c7 Mon Sep 17 00:00:00 2001 From: Chris Sharp Date: Mon, 12 Jan 2015 08:51:38 -0500 Subject: [PATCH] adding another patron merge script --- patron-merge-tools/mark_potential_merges.sql | 55 ++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 patron-merge-tools/mark_potential_merges.sql diff --git a/patron-merge-tools/mark_potential_merges.sql b/patron-merge-tools/mark_potential_merges.sql new file mode 100644 index 0000000..def4b75 --- /dev/null +++ b/patron-merge-tools/mark_potential_merges.sql @@ -0,0 +1,55 @@ +DO $FUNC$ + DECLARE + match_data ums.duplicates_matched_with_lead%ROWTYPE; + BEGIN + FOR match_data IN SELECT udmwl.* + FROM ums.duplicates_excluding_outreach udmwl + LOOP + IF (match_data.usr = match_data.lead_usr) THEN + RAISE NOTICE 'Adding alert to lead user %', match_data.usr; + UPDATE actor.usr + SET alert_message = array_to_string( + array[ + 'CANDIDATE FOR MERGE: This account is identified as the lead account for the following library cards: ', + (array_to_string( + array[ + (select string_agg(barcode, ', ') + from actor.card cd + where cd.id in ( + select card + from actor.usr u + where u.id in ( + select usr + from ums.duplicates_excluding_outreach + where usr <> lead_usr + and grouping_id = match_data.grouping_id + ) + ) + ) + ], ', ') + ), alert_message + ], ' ' + ) + WHERE id = match_data.lead_usr; + ELSE + RAISE NOTICE 'Adding alert to duplicate user %', match_data.usr; + UPDATE actor.usr + SET alert_message = array_to_string( + array[ + 'CANDIDATE FOR MERGE: This account is identified as a duplicate to account ', ( + select barcode + from actor.card cd + where cd.id in ( + select card + from actor.usr u + where u.id = match_data.lead_usr + ) + ), + alert_message + ], ' ' + ) + WHERE id = match_data.usr; + END IF; + END LOOP; + END; +$FUNC$; -- 2.11.0