[open-ils-commits] [GIT] Evergreen ILS branch master updated. 7f25c35f3242baef8306577ebe13785f2b1b472d

Evergreen Git git at git.evergreen-ils.org
Sat Jul 16 10:10:48 EDT 2011


This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "Evergreen ILS".

The branch, master has been updated
       via  7f25c35f3242baef8306577ebe13785f2b1b472d (commit)
       via  81c0adb739d2b85d72041e4e9ff04c7a879ea1ed (commit)
       via  e5d63d761e2156c78004f48e2620e5d1a63084ae (commit)
      from  79d40f168307d73497ef7d54a382c2cdd9816643 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit 7f25c35f3242baef8306577ebe13785f2b1b472d
Author: Mike Rylander <mrylander at gmail.com>
Date:   Sat Jul 16 10:08:03 2011 -0400

    Stamping upgrade script for "Prevent OU loops at DB level"
    
    Signed-off-by: Mike Rylander <mrylander at gmail.com>

diff --git a/Open-ILS/src/sql/Pg/002.schema.config.sql b/Open-ILS/src/sql/Pg/002.schema.config.sql
index df635b8..5adb855 100644
--- a/Open-ILS/src/sql/Pg/002.schema.config.sql
+++ b/Open-ILS/src/sql/Pg/002.schema.config.sql
@@ -86,7 +86,7 @@ CREATE TRIGGER no_overlapping_deps
     BEFORE INSERT OR UPDATE ON config.db_patch_dependencies
     FOR EACH ROW EXECUTE PROCEDURE evergreen.array_overlap_check ('deprecates');
 
-INSERT INTO config.upgrade_log (version, applied_to) VALUES ('0579', :eg_version); -- tsbere via miker
+INSERT INTO config.upgrade_log (version, applied_to) VALUES ('0580', :eg_version); -- tsbere via miker
 
 CREATE TABLE config.bib_source (
 	id		SERIAL	PRIMARY KEY,
diff --git a/Open-ILS/src/sql/Pg/upgrade/XXXX.aou_parent_protect.sql b/Open-ILS/src/sql/Pg/upgrade/0580.schema.aou_parent_protec.sql
similarity index 87%
rename from Open-ILS/src/sql/Pg/upgrade/XXXX.aou_parent_protect.sql
rename to Open-ILS/src/sql/Pg/upgrade/0580.schema.aou_parent_protec.sql
index 589aa97..1c86c0a 100644
--- a/Open-ILS/src/sql/Pg/upgrade/XXXX.aou_parent_protect.sql
+++ b/Open-ILS/src/sql/Pg/upgrade/0580.schema.aou_parent_protec.sql
@@ -1,3 +1,12 @@
+-- Evergreen DB patch 0580.schema.aou_parent_protec.sql
+--
+--
+BEGIN;
+
+
+-- check whether patch can be applied
+SELECT evergreen.upgrade_deps_block_check('0580', :eg_version);
+
 CREATE OR REPLACE FUNCTION actor.org_unit_parent_protect () RETURNS TRIGGER AS $$
     DECLARE
         current_aou actor.org_unit%ROWTYPE;
@@ -31,3 +40,6 @@ $$ LANGUAGE PLPGSQL;
 CREATE TRIGGER actor_org_unit_parent_protect_trigger
     BEFORE INSERT OR UPDATE ON actor.org_unit FOR EACH ROW
     EXECUTE PROCEDURE actor.org_unit_parent_protect ();
+
+
+COMMIT;

commit 81c0adb739d2b85d72041e4e9ff04c7a879ea1ed
Author: Thomas Berezansky <tsbere at mvlc.org>
Date:   Wed Jun 15 22:03:47 2011 -0400

    Unwrapped upgrade script for ou loop protect
    
    May need to be split into "create function" and "add trigger" pieces.
    
    Signed-off-by: Thomas Berezansky <tsbere at mvlc.org>
    Signed-off-by: Mike Rylander <mrylander at gmail.com>

diff --git a/Open-ILS/src/sql/Pg/upgrade/XXXX.aou_parent_protect.sql b/Open-ILS/src/sql/Pg/upgrade/XXXX.aou_parent_protect.sql
new file mode 100644
index 0000000..589aa97
--- /dev/null
+++ b/Open-ILS/src/sql/Pg/upgrade/XXXX.aou_parent_protect.sql
@@ -0,0 +1,33 @@
+CREATE OR REPLACE FUNCTION actor.org_unit_parent_protect () RETURNS TRIGGER AS $$
+    DECLARE
+        current_aou actor.org_unit%ROWTYPE;
+        seen_ous    INT[];
+        depth_count INT;
+	BEGIN
+        current_aou := NEW;
+        depth_count := 0;
+        seen_ous := ARRAY[NEW.id];
+        IF TG_OP = 'INSERT' OR NEW.parent_ou IS DISTINCT FROM OLD.parent_ou THEN
+            LOOP
+                IF current_aou.parent_ou IS NULL THEN -- Top of the org tree?
+                    RETURN NEW; -- No loop. Carry on.
+                END IF;
+                IF current_aou.parent_ou = ANY(seen_ous) THEN -- Parent is one we have seen?
+                    RAISE 'OU LOOP: Saw % twice', current_aou.parent_ou; -- LOOP! ABORT!
+                END IF;
+                -- Get the next one!
+                SELECT INTO current_aou * FROM actor.org_unit WHERE id = current_aou.parent_ou;
+                seen_ous := seen_ous || current_aou.id;
+                depth_count := depth_count + 1;
+                IF depth_count = 100 THEN
+                    RAISE 'OU CHECK TOO DEEP';
+                END IF;
+            END LOOP;
+        END IF;
+		RETURN NEW;
+	END;
+$$ LANGUAGE PLPGSQL;
+
+CREATE TRIGGER actor_org_unit_parent_protect_trigger
+    BEFORE INSERT OR UPDATE ON actor.org_unit FOR EACH ROW
+    EXECUTE PROCEDURE actor.org_unit_parent_protect ();

commit e5d63d761e2156c78004f48e2620e5d1a63084ae
Author: Thomas Berezansky <tsbere at mvlc.org>
Date:   Wed Jun 15 22:03:38 2011 -0400

    Prevent OU loops at DB level
    
    Database trigger to prevent actor.org_unit from being parent of self
    
    Actually detects any loops, even those above the current point
    
    Signed-off-by: Thomas Berezansky <tsbere at mvlc.org>
    Signed-off-by: Mike Rylander <mrylander at gmail.com>

diff --git a/Open-ILS/src/sql/Pg/005.schema.actors.sql b/Open-ILS/src/sql/Pg/005.schema.actors.sql
index 058387c..75b379e 100644
--- a/Open-ILS/src/sql/Pg/005.schema.actors.sql
+++ b/Open-ILS/src/sql/Pg/005.schema.actors.sql
@@ -288,6 +288,40 @@ CREATE INDEX actor_org_unit_billing_address_idx ON actor.org_unit (billing_addre
 CREATE INDEX actor_org_unit_mailing_address_idx ON actor.org_unit (mailing_address);
 CREATE INDEX actor_org_unit_holds_address_idx ON actor.org_unit (holds_address);
 
+CREATE OR REPLACE FUNCTION actor.org_unit_parent_protect () RETURNS TRIGGER AS $$
+    DECLARE
+        current_aou actor.org_unit%ROWTYPE;
+        seen_ous    INT[];
+        depth_count INT;
+	BEGIN
+        current_aou := NEW;
+        depth_count := 0;
+        seen_ous := ARRAY[NEW.id];
+        IF TG_OP = 'INSERT' OR NEW.parent_ou IS DISTINCT FROM OLD.parent_ou THEN
+            LOOP
+                IF current_aou.parent_ou IS NULL THEN -- Top of the org tree?
+                    RETURN NEW; -- No loop. Carry on.
+                END IF;
+                IF current_aou.parent_ou = ANY(seen_ous) THEN -- Parent is one we have seen?
+                    RAISE 'OU LOOP: Saw % twice', current_aou.parent_ou; -- LOOP! ABORT!
+                END IF;
+                -- Get the next one!
+                SELECT INTO current_aou * FROM actor.org_unit WHERE id = current_aou.parent_ou;
+                seen_ous := seen_ous || current_aou.id;
+                depth_count := depth_count + 1;
+                IF depth_count = 100 THEN
+                    RAISE 'OU CHECK TOO DEEP';
+                END IF;
+            END LOOP;
+        END IF;
+		RETURN NEW;
+	END;
+$$ LANGUAGE PLPGSQL;
+
+CREATE TRIGGER actor_org_unit_parent_protect_trigger
+    BEFORE INSERT OR UPDATE ON actor.org_unit FOR EACH ROW
+    EXECUTE PROCEDURE actor.org_unit_parent_protect ();
+
 CREATE TABLE actor.org_lasso (
     id      SERIAL  PRIMARY KEY,
     name   	TEXT    UNIQUE

-----------------------------------------------------------------------

Summary of changes:
 Open-ILS/src/sql/Pg/002.schema.config.sql          |    2 +-
 Open-ILS/src/sql/Pg/005.schema.actors.sql          |   34 +++++++++++++++
 .../Pg/upgrade/0580.schema.aou_parent_protec.sql   |   45 ++++++++++++++++++++
 3 files changed, 80 insertions(+), 1 deletions(-)
 create mode 100644 Open-ILS/src/sql/Pg/upgrade/0580.schema.aou_parent_protec.sql


hooks/post-receive
-- 
Evergreen ILS


More information about the open-ils-commits mailing list