lp#1007248: tweak order in which pgt rows are renumbered
authorGalen Charlton <gmc@esilibrary.com>
Fri, 1 Jun 2012 03:31:11 +0000 (23:31 -0400)
committerBill Erickson <berick@esilibrary.com>
Fri, 1 Jun 2012 19:42:34 +0000 (15:42 -0400)
Need to renumber from highest to lowest.  Because the primary
key constraint is not deferred, doing the renumbering in a single
statement will fail if there is overlap between the set of
existing pgt.id values and the set of {pgt.id + 100}.

Signed-off-by: Galen Charlton <gmc@esilibrary.com>
Signed-off-by: Bill Erickson <berick@esilibrary.com>

Open-ILS/src/sql/Pg/version-upgrade/2.0-2.1-upgrade-db.sql

index 88cb563..3638766 100644 (file)
@@ -5732,7 +5732,16 @@ INSERT INTO permission.perm_list
 
 -- Prevent conflicts with existing custom permission groups; as of 2.0.10, 
 -- highest permission.grp_tree ID was 10 for Local System Administrator
-UPDATE permission.grp_tree SET id = id + 100 WHERE id > 10;
+DO $$
+DECLARE i INTEGER;
+BEGIN
+    FOR i IN
+        SELECT id FROM permission.grp_tree WHERE id > 10 ORDER BY id DESC
+    LOOP
+        UPDATE permission.grp_tree SET id = id + 100 WHERE id = i;
+    END LOOP;
+END;
+$$;
 UPDATE permission.grp_tree SET parent = parent + 100 WHERE parent > 10;
 UPDATE actor.usr SET profile = profile + 100 WHERE profile > 10;
 UPDATE permission.grp_perm_map SET grp = grp + 100 WHERE grp > 10;