adding another patron merge script
authorChris Sharp <csharp@georgialibraries.org>
Mon, 12 Jan 2015 13:51:38 +0000 (08:51 -0500)
committerChris Sharp <csharp@georgialibraries.org>
Mon, 12 Jan 2015 13:51:38 +0000 (08:51 -0500)
patron-merge-tools/mark_potential_merges.sql [new file with mode: 0644]

diff --git a/patron-merge-tools/mark_potential_merges.sql b/patron-merge-tools/mark_potential_merges.sql
new file mode 100644 (file)
index 0000000..def4b75
--- /dev/null
@@ -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$;