From 8e92e52dd1a96a1beb4bd6a12d21a668cf488e78 Mon Sep 17 00:00:00 2001 From: Bill Ott Date: Fri, 18 May 2018 09:52:46 -0400 Subject: [PATCH] LP#1772028 Add some FK violation functions just in case they are missing Depending on your data, upgrade 1063 may not have created the functions being re-applied in this upgrade script. Let's make sure they are there. Signed-off-by: Bill Ott Signed-off-by: Dan Wells --- .../3.0.1-3.0.2-upgrade-db.sql | 48 +++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/Open-ILS/src/sql/Pg/version-upgrade/3.0.1-3.0.2-upgrade-db.sql b/Open-ILS/src/sql/Pg/version-upgrade/3.0.1-3.0.2-upgrade-db.sql index 7c30ed70fc..f8addc8032 100644 --- a/Open-ILS/src/sql/Pg/version-upgrade/3.0.1-3.0.2-upgrade-db.sql +++ b/Open-ILS/src/sql/Pg/version-upgrade/3.0.1-3.0.2-upgrade-db.sql @@ -412,6 +412,54 @@ $func$ LANGUAGE PLPGSQL; SELECT evergreen.upgrade_deps_block_check('1081', :eg_version); -- jboyer/gmcharlt +CREATE OR REPLACE FUNCTION evergreen.container_copy_bucket_item_target_copy_inh_fkey() RETURNS TRIGGER AS $f$ +BEGIN + PERFORM 1 FROM asset.copy WHERE id = NEW.target_copy; + IF NOT FOUND THEN + RAISE foreign_key_violation USING MESSAGE = FORMAT( + $$Referenced asset.copy id not found, target_copy:%s$$, NEW.target_copy + ); + END IF; + RETURN NEW; +END; +$f$ LANGUAGE PLPGSQL VOLATILE COST 50; + +CREATE OR REPLACE FUNCTION evergreen.asset_copy_note_owning_copy_inh_fkey() RETURNS TRIGGER AS $f$ +BEGIN + PERFORM 1 FROM asset.copy WHERE id = NEW.owning_copy; + IF NOT FOUND THEN + RAISE foreign_key_violation USING MESSAGE = FORMAT( + $$Referenced asset.copy id not found, owning_copy:%s$$, NEW.owning_copy + ); + END IF; + RETURN NEW; +END; +$f$ LANGUAGE PLPGSQL VOLATILE COST 50; + +CREATE OR REPLACE FUNCTION evergreen.asset_copy_tag_copy_map_copy_inh_fkey() RETURNS TRIGGER AS $f$ +BEGIN + PERFORM 1 FROM asset.copy WHERE id = NEW.copy; + IF NOT FOUND THEN + RAISE foreign_key_violation USING MESSAGE = FORMAT( + $$Referenced asset.copy id not found, copy:%s$$, NEW.copy + ); + END IF; + RETURN NEW; +END; +$f$ LANGUAGE PLPGSQL VOLATILE COST 50; + +CREATE OR REPLACE FUNCTION evergreen.asset_copy_alert_copy_inh_fkey() RETURNS TRIGGER AS $f$ +BEGIN + PERFORM 1 FROM asset.copy WHERE id = NEW.copy; + IF NOT FOUND THEN + RAISE foreign_key_violation USING MESSAGE = FORMAT( + $$Referenced asset.copy id not found, copy:%s$$, NEW.copy + ); + END IF; + RETURN NEW; +END; +$f$ LANGUAGE PLPGSQL VOLATILE COST 50; + DROP TRIGGER IF EXISTS inherit_copy_bucket_item_target_copy_fkey ON container.copy_bucket_item; DROP TRIGGER IF EXISTS inherit_import_item_imported_as_fkey ON vandelay.import_item; DROP TRIGGER IF EXISTS inherit_asset_copy_note_copy_fkey ON asset.copy_note; -- 2.43.2