[open-ils-commits] r16614 - in trunk/Open-ILS/src/sql/Pg: . upgrade (erickson)
svn at svn.open-ils.org
svn at svn.open-ils.org
Mon Jun 7 12:10:51 EDT 2010
Author: erickson
Date: 2010-06-07 12:10:48 -0400 (Mon, 07 Jun 2010)
New Revision: 16614
Added:
trunk/Open-ILS/src/sql/Pg/upgrade/0295.schema.marcxml_check_trigger.sql
Modified:
trunk/Open-ILS/src/sql/Pg/002.schema.config.sql
trunk/Open-ILS/src/sql/Pg/010.schema.biblio.sql
trunk/Open-ILS/src/sql/Pg/011.schema.authority.sql
Log:
Patch from Galen Charlton: The attached patch adds triggers on biblio.record_entry and authority.record_entry to prevent the insertion or update of MARCXML that is not well-formed. Since the various consumers of bre.marc and are.marc tend not to handle invalid XML all that well, these triggers serve as a (very basic) data integrity check. http://libmail.georgialibraries.org/pipermail/open-ils-dev/2010-June/006116.html
Modified: trunk/Open-ILS/src/sql/Pg/002.schema.config.sql
===================================================================
--- trunk/Open-ILS/src/sql/Pg/002.schema.config.sql 2010-06-07 15:17:41 UTC (rev 16613)
+++ trunk/Open-ILS/src/sql/Pg/002.schema.config.sql 2010-06-07 16:10:48 UTC (rev 16614)
@@ -65,7 +65,7 @@
install_date TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW()
);
-INSERT INTO config.upgrade_log (version) VALUES ('0294'); -- phasefx
+INSERT INTO config.upgrade_log (version) VALUES ('0295'); -- gmcharlt
CREATE TABLE config.bib_source (
id SERIAL PRIMARY KEY,
Modified: trunk/Open-ILS/src/sql/Pg/010.schema.biblio.sql
===================================================================
--- trunk/Open-ILS/src/sql/Pg/010.schema.biblio.sql 2010-06-07 15:17:41 UTC (rev 16613)
+++ trunk/Open-ILS/src/sql/Pg/010.schema.biblio.sql 2010-06-07 16:10:48 UTC (rev 16614)
@@ -25,6 +25,18 @@
BEGIN RETURN 'AUTOGENERATED-' || nextval('biblio.autogen_tcn_value_seq'::TEXT); END;
$$ LANGUAGE PLPGSQL;
+CREATE OR REPLACE FUNCTION biblio.check_marcxml_well_formed () RETURNS TRIGGER AS $func$
+BEGIN
+
+ IF xml_is_well_formed(NEW.marc) THEN
+ RETURN NEW;
+ ELSE
+ RAISE EXCEPTION 'Attempted to % MARCXML that is not well formed', TG_OP;
+ END IF;
+
+END;
+$func$ LANGUAGE PLPGSQL;
+
CREATE TABLE biblio.record_entry (
id BIGSERIAL PRIMARY KEY,
creator INT NOT NULL DEFAULT 1,
@@ -49,6 +61,7 @@
CREATE INDEX biblio_record_entry_edit_date_idx ON biblio.record_entry ( edit_date );
CREATE INDEX biblio_record_entry_fp_idx ON biblio.record_entry ( fingerprint );
CREATE UNIQUE INDEX biblio_record_unique_tcn ON biblio.record_entry (tcn_value) WHERE deleted = FALSE OR deleted IS FALSE;
+CREATE TRIGGER a_marcxml_is_well_formed BEFORE INSERT OR UPDATE ON biblio.record_entry FOR EACH ROW EXECUTE PROCEDURE biblio.check_marcxml_well_formed();
CREATE TABLE biblio.record_note (
id BIGSERIAL PRIMARY KEY,
Modified: trunk/Open-ILS/src/sql/Pg/011.schema.authority.sql
===================================================================
--- trunk/Open-ILS/src/sql/Pg/011.schema.authority.sql 2010-06-07 15:17:41 UTC (rev 16613)
+++ trunk/Open-ILS/src/sql/Pg/011.schema.authority.sql 2010-06-07 16:10:48 UTC (rev 16614)
@@ -37,6 +37,7 @@
CREATE INDEX authority_record_entry_creator_idx ON authority.record_entry ( creator );
CREATE INDEX authority_record_entry_editor_idx ON authority.record_entry ( editor );
CREATE UNIQUE INDEX authority_record_unique_tcn ON authority.record_entry (arn_source,arn_value) WHERE deleted = FALSE OR deleted IS FALSE;
+CREATE TRIGGER a_marcxml_is_well_formed BEFORE INSERT OR UPDATE ON authority.record_entry FOR EACH ROW EXECUTE PROCEDURE biblio.check_marcxml_well_formed();
CREATE TABLE authority.record_note (
id BIGSERIAL PRIMARY KEY,
Added: trunk/Open-ILS/src/sql/Pg/upgrade/0295.schema.marcxml_check_trigger.sql
===================================================================
--- trunk/Open-ILS/src/sql/Pg/upgrade/0295.schema.marcxml_check_trigger.sql (rev 0)
+++ trunk/Open-ILS/src/sql/Pg/upgrade/0295.schema.marcxml_check_trigger.sql 2010-06-07 16:10:48 UTC (rev 16614)
@@ -0,0 +1,21 @@
+BEGIN;
+
+INSERT INTO config.upgrade_log (version) VALUES ('0295'); -- gmcharlt
+
+CREATE OR REPLACE FUNCTION biblio.check_marcxml_well_formed () RETURNS TRIGGER AS $func$
+BEGIN
+
+ IF xml_is_well_formed(NEW.marc) THEN
+ RETURN NEW;
+ ELSE
+ RAISE EXCEPTION 'Attempted to % MARCXML that is not well formed', TG_OP;
+ END IF;
+
+END;
+$func$ LANGUAGE PLPGSQL;
+
+CREATE TRIGGER a_marcxml_is_well_formed BEFORE INSERT OR UPDATE ON biblio.record_entry FOR EACH ROW EXECUTE PROCEDURE biblio.check_marcxml_well_formed();
+
+CREATE TRIGGER a_marcxml_is_well_formed BEFORE INSERT OR UPDATE ON authority.record_entry FOR EACH ROW EXECUTE PROCEDURE biblio.check_marcxml_well_formed();
+
+COMMIT;
More information about the open-ils-commits
mailing list