LP1830391 Warn on dupe workstation settings
authorBill Erickson <berickxx@gmail.com>
Thu, 12 Dec 2019 21:47:31 +0000 (16:47 -0500)
committerJason Boyer <JBoyer@eoli.info>
Fri, 13 Dec 2019 14:36:29 +0000 (09:36 -0500)
Check for duplication workstations (by name and workstation) before
applying the UNIQUE constraint on actor.workstation_setting.  If found,
raise a notice to the user to provide suggestions.

Signed-off-by: Bill Erickson <berickxx@gmail.com>
Signed-off-by: Jason Boyer <JBoyer@eoli.info>
Open-ILS/src/sql/Pg/upgrade/XXXX.data.hatch-enable-print.sql

index e9e8b0e..f6cc5b3 100644 (file)
@@ -12,8 +12,41 @@ VALUES (
     )
 );
 
-ALTER TABLE actor.workstation_setting
+
+DO $SQL$
+BEGIN
+
+    PERFORM COUNT(*), workstation, name 
+    FROM actor.workstation_setting GROUP BY 2, 3 HAVING COUNT(*) > 1;
+
+    IF FOUND THEN
+
+        RAISE NOTICE $NOTICE$
+
+---
+The actor.workstation_setting table contains duplicate rows.  The duplicates 
+should be removed before applying a new UNIQUE constraint.  To find the rows, 
+execute the following SQL:
+
+SELECT COUNT(*), workstation, name FROM actor.workstation_setting 
+    GROUP BY 2, 3 HAVING COUNT(*) > 1;  
+    
+Once the duplicates are cleared, execute the following SQL: 
+
+ALTER TABLE actor.workstation_setting 
     ADD CONSTRAINT ws_once_per_key UNIQUE (workstation, name);
+---
+
+$NOTICE$;
+
+    ELSE
+
+        ALTER TABLE actor.workstation_setting
+            ADD CONSTRAINT ws_once_per_key UNIQUE (workstation, name);
+    END IF;
+
+END;
+$SQL$;
 
 COMMIT;