[open-ils-commits] r20054 - in branches/rel_2_1/Open-ILS/src/sql/Pg: . upgrade (miker)
svn at svn.open-ils.org
svn at svn.open-ils.org
Tue Apr 12 14:16:36 EDT 2011
Author: miker
Date: 2011-04-12 14:16:31 -0400 (Tue, 12 Apr 2011)
New Revision: 20054
Added:
branches/rel_2_1/Open-ILS/src/sql/Pg/upgrade/0511.schema.fake_fkey_tgr-for-inherited-tables.sql
Modified:
branches/rel_2_1/Open-ILS/src/sql/Pg/000.functions.general.sql
branches/rel_2_1/Open-ILS/src/sql/Pg/002.schema.config.sql
branches/rel_2_1/Open-ILS/src/sql/Pg/090.schema.action.sql
Log:
Add a trigger function to simulate FKEY constraints on inherited tables
Modified: branches/rel_2_1/Open-ILS/src/sql/Pg/000.functions.general.sql
===================================================================
--- branches/rel_2_1/Open-ILS/src/sql/Pg/000.functions.general.sql 2011-04-12 18:16:07 UTC (rev 20053)
+++ branches/rel_2_1/Open-ILS/src/sql/Pg/000.functions.general.sql 2011-04-12 18:16:31 UTC (rev 20054)
@@ -24,6 +24,19 @@
END;
$$ LANGUAGE plpgsql;
+CREATE OR REPLACE FUNCTION evergreen.fake_fkey_tgr () RETURNS TRIGGER AS $F$
+DECLARE
+ copy_id BIGINT;
+BEGIN
+ EXECUTE 'SELECT ($1).' || quote_ident(TG_ARGV[0]) INTO copy_id USING NEW;
+ PERFORM * FROM asset.copy WHERE id = copy_id;
+ IF NOT FOUND THEN
+ RAISE EXCEPTION 'Key (%.%=%) does not exist in asset.copy', TG_TABLE_SCHEMA, TG_TABLE_NAME, copy_id;
+ END IF;
+ RETURN NULL;
+END;
+$F$ LANGUAGE PLPGSQL;
+
SELECT evergreen.change_db_setting('search_path', ARRAY['evergreen','public','pg_catalog']);
COMMIT;
Modified: branches/rel_2_1/Open-ILS/src/sql/Pg/002.schema.config.sql
===================================================================
--- branches/rel_2_1/Open-ILS/src/sql/Pg/002.schema.config.sql 2011-04-12 18:16:07 UTC (rev 20053)
+++ branches/rel_2_1/Open-ILS/src/sql/Pg/002.schema.config.sql 2011-04-12 18:16:31 UTC (rev 20054)
@@ -70,7 +70,7 @@
install_date TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW()
);
-INSERT INTO config.upgrade_log (version) VALUES ('0510'); -- miker
+INSERT INTO config.upgrade_log (version) VALUES ('0511'); -- miker
CREATE TABLE config.bib_source (
id SERIAL PRIMARY KEY,
Modified: branches/rel_2_1/Open-ILS/src/sql/Pg/090.schema.action.sql
===================================================================
--- branches/rel_2_1/Open-ILS/src/sql/Pg/090.schema.action.sql 2011-04-12 18:16:07 UTC (rev 20053)
+++ branches/rel_2_1/Open-ILS/src/sql/Pg/090.schema.action.sql 2011-04-12 18:16:31 UTC (rev 20054)
@@ -151,6 +151,8 @@
CREATE UNIQUE INDEX circ_parent_idx ON action.circulation ( parent_circ ) WHERE parent_circ IS NOT NULL;
CREATE UNIQUE INDEX only_one_concurrent_checkout_per_copy ON action.circulation(target_copy) WHERE checkin_time IS NULL;
+CREATE TRIGGER action_circulation_target_copy_trig AFTER INSERT OR UPDATE ON action.circulation FOR EACH ROW EXECUTE PROCEDURE evergreen.fake_fkey_tgr('target_copy');
+
CREATE TRIGGER mat_summary_create_tgr AFTER INSERT ON action.circulation FOR EACH ROW EXECUTE PROCEDURE money.mat_summary_create ('circulation');
CREATE TRIGGER mat_summary_change_tgr AFTER UPDATE ON action.circulation FOR EACH ROW EXECUTE PROCEDURE money.mat_summary_update ();
CREATE TRIGGER mat_summary_remove_tgr AFTER DELETE ON action.circulation FOR EACH ROW EXECUTE PROCEDURE money.mat_summary_delete ();
Copied: branches/rel_2_1/Open-ILS/src/sql/Pg/upgrade/0511.schema.fake_fkey_tgr-for-inherited-tables.sql (from rev 20053, trunk/Open-ILS/src/sql/Pg/upgrade/0511.schema.fake_fkey_tgr-for-inherited-tables.sql)
===================================================================
--- branches/rel_2_1/Open-ILS/src/sql/Pg/upgrade/0511.schema.fake_fkey_tgr-for-inherited-tables.sql (rev 0)
+++ branches/rel_2_1/Open-ILS/src/sql/Pg/upgrade/0511.schema.fake_fkey_tgr-for-inherited-tables.sql 2011-04-12 18:16:31 UTC (rev 20054)
@@ -0,0 +1,21 @@
+BEGIN;
+
+INSERT INTO config.upgrade_log (version) VALUES ('0511'); -- miker
+
+CREATE OR REPLACE FUNCTION evergreen.fake_fkey_tgr () RETURNS TRIGGER AS $F$
+DECLARE
+ copy_id BIGINT;
+BEGIN
+ EXECUTE 'SELECT ($1).' || quote_ident(TG_ARGV[0]) INTO copy_id USING NEW;
+ PERFORM * FROM asset.copy WHERE id = copy_id;
+ IF NOT FOUND THEN
+ RAISE EXCEPTION 'Key (%.%=%) does not exist in asset.copy', TG_TABLE_SCHEMA, TG_TABLE_NAME, copy_id;
+ END IF;
+ RETURN NULL;
+END;
+$F$ LANGUAGE PLPGSQL;
+
+CREATE TRIGGER action_circulation_target_copy_trig AFTER INSERT OR UPDATE ON action.circulation FOR EACH ROW EXECUTE PROCEDURE evergreen.fake_fkey_tgr('target_copy');
+
+COMMIT;
+
More information about the open-ils-commits
mailing list