[open-ils-commits] [GIT] Evergreen ILS branch rel_2_0 updated. 0b0d730e1d71575dddc7fb41df4057ecee285749
Evergreen Git
git at git.evergreen-ils.org
Sat Jul 16 10:18:23 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_0 has been updated
via 0b0d730e1d71575dddc7fb41df4057ecee285749 (commit)
via d65460827ce6107c19eb114838b1fb5722eff7fc (commit)
via 4cb016adb610dc22e0671c20345abca7744ecfe5 (commit)
from 8589cf090b400c2e4e35233825e45027a4fde15d (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 0b0d730e1d71575dddc7fb41df4057ecee285749
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 9a5e4de..a65d217 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 ('0576'); -- phasefx/gmcharlt
+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 d65460827ce6107c19eb114838b1fb5722eff7fc
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 4cb016adb610dc22e0671c20345abca7744ecfe5
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 f87ffa0..72b7f5b 100644
--- a/Open-ILS/src/sql/Pg/005.schema.actors.sql
+++ b/Open-ILS/src/sql/Pg/005.schema.actors.sql
@@ -244,6 +244,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