[open-ils-commits] [GIT] Evergreen ILS branch master updated. fd435363e7af964c699032b5eba4eb56c14c899e
Evergreen Git
git at git.evergreen-ils.org
Sat Feb 27 19:30:59 EST 2016
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 fd435363e7af964c699032b5eba4eb56c14c899e (commit)
via 075878f4e7ba308043b8bbe85e808af8e67940b1 (commit)
via aeb734c75db65650be80c884f55e33ca049b58fa (commit)
from 466756061fce2d877361bd89b7845826059fc330 (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 fd435363e7af964c699032b5eba4eb56c14c899e
Author: Ben Shum <ben at evergreener.net>
Date: Sat Feb 27 19:27:45 2016 -0500
LP#1506534: Stamping upgrade script for new z3950_attr_type check
Signed-off-by: Ben Shum <ben at evergreener.net>
diff --git a/Open-ILS/src/sql/Pg/002.schema.config.sql b/Open-ILS/src/sql/Pg/002.schema.config.sql
index 009db22..edb2de6 100644
--- a/Open-ILS/src/sql/Pg/002.schema.config.sql
+++ b/Open-ILS/src/sql/Pg/002.schema.config.sql
@@ -91,7 +91,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 ('0962', :eg_version); -- dbwells/kmlussier
+INSERT INTO config.upgrade_log (version, applied_to) VALUES ('0963', :eg_version); -- jboyer/bshum
CREATE TABLE config.bib_source (
id SERIAL PRIMARY KEY,
diff --git a/Open-ILS/src/sql/Pg/upgrade/XXXX.schema.config_z3950_attr_check.sql b/Open-ILS/src/sql/Pg/upgrade/0963.schema.config_z3950_attr_check.sql
similarity index 93%
rename from Open-ILS/src/sql/Pg/upgrade/XXXX.schema.config_z3950_attr_check.sql
rename to Open-ILS/src/sql/Pg/upgrade/0963.schema.config_z3950_attr_check.sql
index 8267292..0890974 100644
--- a/Open-ILS/src/sql/Pg/upgrade/XXXX.schema.config_z3950_attr_check.sql
+++ b/Open-ILS/src/sql/Pg/upgrade/0963.schema.config_z3950_attr_check.sql
@@ -1,6 +1,6 @@
BEGIN;
-SELECT evergreen.upgrade_deps_block_check('XXXX', :eg_version);
+SELECT evergreen.upgrade_deps_block_check('0963', :eg_version);
ALTER TABLE config.z3950_index_field_map DROP CONSTRAINT "valid_z3950_attr_type";
commit 075878f4e7ba308043b8bbe85e808af8e67940b1
Author: Ben Shum <ben at evergreener.net>
Date: Sat Feb 27 19:28:37 2016 -0500
LP#1506534: Fix typo in for z3950_attr_type
In 002.schema.config.sql there was a small typo for "z3950attr_name_is_valid"
where that should be "z3950_attr_name_is_valid" with the underscore between.
Fix to stop breakage on new database installs.
Signed-off-by: Ben Shum <ben at evergreener.net>
diff --git a/Open-ILS/src/sql/Pg/002.schema.config.sql b/Open-ILS/src/sql/Pg/002.schema.config.sql
index 3d3d0c2..009db22 100644
--- a/Open-ILS/src/sql/Pg/002.schema.config.sql
+++ b/Open-ILS/src/sql/Pg/002.schema.config.sql
@@ -1055,7 +1055,7 @@ ALTER TABLE config.best_hold_order ADD CHECK ((
));
CREATE OR REPLACE FUNCTION
- evergreen.z3950attr_name_is_valid() RETURNS TRIGGER AS $func$
+ evergreen.z3950_attr_name_is_valid() RETURNS TRIGGER AS $func$
BEGIN
PERFORM * FROM config.z3950_attr WHERE name = NEW.z3950_attr_type;
commit aeb734c75db65650be80c884f55e33ca049b58fa
Author: Jason Boyer <jboyer at library.in.gov>
Date: Tue Dec 29 13:53:04 2015 -0500
LP#1506534: Improve czifm z3950_attr_type Check
Rather than use a CHECK constraint, this patch
uses a CONSTRAINT TRIGGER, er, constraint to verify
the z3950_attr_type field. This allows the trigger
to be deferred as any other deferrable constraint
and also allows parallel pg_restore jobs to complete
properly.
Signed-off-by: Jason Boyer <jboyer at library.in.gov>
Signed-off-by: Ben Shum <ben at evergreener.net>
diff --git a/Open-ILS/src/sql/Pg/002.schema.config.sql b/Open-ILS/src/sql/Pg/002.schema.config.sql
index c2ebbe6..3d3d0c2 100644
--- a/Open-ILS/src/sql/Pg/002.schema.config.sql
+++ b/Open-ILS/src/sql/Pg/002.schema.config.sql
@@ -1055,13 +1055,22 @@ ALTER TABLE config.best_hold_order ADD CHECK ((
));
CREATE OR REPLACE FUNCTION
- evergreen.z3950_attr_name_is_valid(TEXT) RETURNS BOOLEAN AS $func$
- SELECT EXISTS (SELECT 1 FROM config.z3950_attr WHERE name = $1);
-$func$ LANGUAGE SQL STRICT STABLE;
+ evergreen.z3950attr_name_is_valid() RETURNS TRIGGER AS $func$
+ BEGIN
+
+ PERFORM * FROM config.z3950_attr WHERE name = NEW.z3950_attr_type;
+
+ IF FOUND THEN
+ RETURN NULL;
+ END IF;
+
+ RAISE EXCEPTION '% is not a valid Z39.50 attribute type', NEW.z3950_attr_type;
-COMMENT ON FUNCTION evergreen.z3950_attr_name_is_valid(TEXT) IS $$
-Results in TRUE if there exists at least one config.z3950_attr
-with the provided name. Used by config.z3950_index_field_map
+ END;
+$func$ LANGUAGE PLPGSQL STABLE;
+
+COMMENT ON FUNCTION evergreen.z3950_attr_name_is_valid() IS $$
+Used by a config.z3950_index_field_map constraint trigger
to verify z3950_attr_type maps.
$$;
@@ -1081,14 +1090,13 @@ CREATE TABLE config.z3950_index_field_map (
CONSTRAINT attr_or_attr_type CHECK (
z3950_attr IS NOT NULL OR
z3950_attr_type IS NOT NULL
- ),
- -- ensure the selected z3950_attr_type refers to a valid attr name
- CONSTRAINT valid_z3950_attr_type CHECK (
- z3950_attr_type IS NULL OR
- evergreen.z3950_attr_name_is_valid(z3950_attr_type)
)
);
+CREATE CONSTRAINT TRIGGER valid_z3950_attr_type AFTER INSERT OR UPDATE ON config.z3950_index_field_map
+ DEFERRABLE INITIALLY DEFERRED FOR EACH ROW WHEN (NEW.z3950_attr_type IS NOT NULL)
+ EXECUTE PROCEDURE evergreen.z3950_attr_name_is_valid();
+
CREATE TABLE config.marc_format (
id SERIAL PRIMARY KEY,
code TEXT NOT NULL,
diff --git a/Open-ILS/src/sql/Pg/t/lp1506534_z3950_attr_check.pg b/Open-ILS/src/sql/Pg/t/lp1506534_z3950_attr_check.pg
new file mode 100644
index 0000000..dce44d6
--- /dev/null
+++ b/Open-ILS/src/sql/Pg/t/lp1506534_z3950_attr_check.pg
@@ -0,0 +1,21 @@
+BEGIN;
+SELECT plan(5);
+
+-- Is the proper constraint present?
+SELECT is((SELECT COUNT(*) FROM pg_constraint WHERE conname='valid_z3950_attr_type' AND contype='c')::INTEGER, 0::INTEGER, 'CHECK constraint not present');
+SELECT has_trigger('config', 'z3950_index_field_map', 'valid_z3950_attr_type', 'CONSTRAINT TRIGGER present on config.z3950_index_field_map');
+
+-- Does it work properly?
+SET CONSTRAINTS config.valid_z3950_attr_type IMMEDIATE;
+PREPARE busted_insert AS INSERT INTO config.z3950_index_field_map (label, metabib_field, z3950_attr_type) VALUES ('Title', 5, 'sadface');
+PREPARE ok_type_insert AS INSERT INTO config.z3950_index_field_map (label, metabib_field, z3950_attr_type) VALUES ('Title2', 5, 'title');
+PREPARE ok_attr_insert AS INSERT INTO config.z3950_index_field_map (label, metabib_field, z3950_attr) VALUES ('Title3', 5, 5);
+
+SELECT throws_ok('busted_insert', 'P0001', 'sadface is not a valid Z39.50 attribute type', 'Invalid Insert Test');
+SELECT lives_ok('ok_type_insert', 'Valid z3950_attr_type Insert');
+SELECT lives_ok('ok_attr_insert', 'Valid z3950_attr Insert, z3950_attr_type is NULL');
+
+-- Finish the tests and clean up.
+SELECT * FROM finish();
+ROLLBACK;
+
diff --git a/Open-ILS/src/sql/Pg/upgrade/XXXX.schema.config_z3950_attr_check.sql b/Open-ILS/src/sql/Pg/upgrade/XXXX.schema.config_z3950_attr_check.sql
new file mode 100644
index 0000000..8267292
--- /dev/null
+++ b/Open-ILS/src/sql/Pg/upgrade/XXXX.schema.config_z3950_attr_check.sql
@@ -0,0 +1,33 @@
+BEGIN;
+
+SELECT evergreen.upgrade_deps_block_check('XXXX', :eg_version);
+
+ALTER TABLE config.z3950_index_field_map DROP CONSTRAINT "valid_z3950_attr_type";
+
+DROP FUNCTION evergreen.z3950_attr_name_is_valid(text);
+
+CREATE OR REPLACE FUNCTION evergreen.z3950_attr_name_is_valid() RETURNS TRIGGER AS $func$
+BEGIN
+
+ PERFORM * FROM config.z3950_attr WHERE name = NEW.z3950_attr_type;
+
+ IF FOUND THEN
+ RETURN NULL;
+ END IF;
+
+ RAISE EXCEPTION '% is not a valid Z39.50 attribute type', NEW.z3950_attr_type;
+
+END;
+$func$ LANGUAGE PLPGSQL STABLE;
+
+COMMENT ON FUNCTION evergreen.z3950_attr_name_is_valid() IS $$
+Used by a config.z3950_index_field_map constraint trigger
+to verify z3950_attr_type maps.
+$$;
+
+CREATE CONSTRAINT TRIGGER valid_z3950_attr_type AFTER INSERT OR UPDATE ON config.z3950_index_field_map
+ DEFERRABLE INITIALLY DEFERRED FOR EACH ROW WHEN (NEW.z3950_attr_type IS NOT NULL)
+ EXECUTE PROCEDURE evergreen.z3950_attr_name_is_valid();
+
+COMMIT;
+
-----------------------------------------------------------------------
Summary of changes:
Open-ILS/src/sql/Pg/002.schema.config.sql | 32 ++++++++++++-------
.../src/sql/Pg/t/lp1506534_z3950_attr_check.pg | 21 ++++++++++++
.../0963.schema.config_z3950_attr_check.sql | 33 ++++++++++++++++++++
3 files changed, 74 insertions(+), 12 deletions(-)
create mode 100644 Open-ILS/src/sql/Pg/t/lp1506534_z3950_attr_check.pg
create mode 100644 Open-ILS/src/sql/Pg/upgrade/0963.schema.config_z3950_attr_check.sql
hooks/post-receive
--
Evergreen ILS
More information about the open-ils-commits
mailing list