[open-ils-commits] [GIT] Evergreen ILS branch rel_2_1 updated. 10b2c746745779dd34fcdd6956d6aa929dd586be
Evergreen Git
git at git.evergreen-ils.org
Sat Jul 16 10:14:14 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, rel_2_1 has been updated
via 10b2c746745779dd34fcdd6956d6aa929dd586be (commit)
via 2ab2abd1673839c2f73eeecbf484fb19a041b84a (commit)
via b210ac5d407148ee7b81fc00d26feffafebeffd0 (commit)
from bfd440d9150ae2812ff50e2e27cfbd4bf0fc96d2 (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 10b2c746745779dd34fcdd6956d6aa929dd586be
Author: Mike Rylander <mrylander at gmail.com>
Date: Sat Jul 16 10:10:26 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 34feeaa..bca10d8 100644
--- a/Open-ILS/src/sql/Pg/002.schema.config.sql
+++ b/Open-ILS/src/sql/Pg/002.schema.config.sql
@@ -57,7 +57,7 @@ CREATE TABLE config.upgrade_log (
install_date TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW()
);
-INSERT INTO config.upgrade_log (version) VALUES ('0579'); -- tsbere via miker
+INSERT INTO config.upgrade_log (version) VALUES ('0580'); -- 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_protect.sql
similarity index 93%
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_protect.sql
index 589aa97..f2cb925 100644
--- a/Open-ILS/src/sql/Pg/upgrade/XXXX.aou_parent_protect.sql
+++ b/Open-ILS/src/sql/Pg/upgrade/0580.schema.aou_parent_protect.sql
@@ -1,3 +1,7 @@
+BEGIN;
+
+INSERT INTO config.upgrade_log (version) VALUES ('0580'); -- tsbere via miker
+
CREATE OR REPLACE FUNCTION actor.org_unit_parent_protect () RETURNS TRIGGER AS $$
DECLARE
current_aou actor.org_unit%ROWTYPE;
@@ -31,3 +35,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 2ab2abd1673839c2f73eeecbf484fb19a041b84a
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 b210ac5d407148ee7b81fc00d26feffafebeffd0
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 d56e644..919ddf0 100644
--- a/Open-ILS/src/sql/Pg/005.schema.actors.sql
+++ b/Open-ILS/src/sql/Pg/005.schema.actors.sql
@@ -253,6 +253,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_protect.sql | 40 ++++++++++++++++++++
3 files changed, 75 insertions(+), 1 deletions(-)
create mode 100644 Open-ILS/src/sql/Pg/upgrade/0580.schema.aou_parent_protect.sql
hooks/post-receive
--
Evergreen ILS
More information about the open-ils-commits
mailing list