From: Michele Morgan Date: Mon, 1 Aug 2022 18:30:25 +0000 (-0400) Subject: LP1910546: Stamping upgrade script X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=35179d65ba7a5056c18f27b2a8aacad57a66e621;p=evergreen%2Fpines.git LP1910546: Stamping upgrade script Signed-off-by: Michele Morgan --- diff --git a/Open-ILS/src/sql/Pg/002.schema.config.sql b/Open-ILS/src/sql/Pg/002.schema.config.sql index 89de0a6a2b..626e611abf 100644 --- a/Open-ILS/src/sql/Pg/002.schema.config.sql +++ b/Open-ILS/src/sql/Pg/002.schema.config.sql @@ -92,7 +92,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 ('1327', :eg_version); -- berick/jamundson/mmorgan +INSERT INTO config.upgrade_log (version, applied_to) VALUES ('1328', :eg_version); -- berick/tlittle/mmorgan CREATE TABLE config.bib_source ( id SERIAL PRIMARY KEY, diff --git a/Open-ILS/src/sql/Pg/upgrade/1328.schema.reject-active-acpl-deleted.sql b/Open-ILS/src/sql/Pg/upgrade/1328.schema.reject-active-acpl-deleted.sql new file mode 100644 index 0000000000..1df97e04ad --- /dev/null +++ b/Open-ILS/src/sql/Pg/upgrade/1328.schema.reject-active-acpl-deleted.sql @@ -0,0 +1,30 @@ +BEGIN; + +SELECT evergreen.upgrade_deps_block_check('1328', :eg_version); + +CREATE OR REPLACE FUNCTION asset.check_delete_copy_location(acpl_id INTEGER) + RETURNS VOID AS $FUNK$ +BEGIN + PERFORM TRUE FROM asset.copy WHERE location = acpl_id AND NOT deleted LIMIT 1; + + IF FOUND THEN + RAISE EXCEPTION + 'Copy location % contains active copies and cannot be deleted', acpl_id; + END IF; +END; +$FUNK$ LANGUAGE plpgsql; + +DROP RULE protect_copy_location_delete ON asset.copy_location; + +CREATE RULE protect_copy_location_delete AS + ON DELETE TO asset.copy_location DO INSTEAD ( + SELECT asset.check_delete_copy_location(OLD.id); + UPDATE asset.copy_location SET deleted = TRUE WHERE OLD.id = asset.copy_location.id; + UPDATE acq.lineitem_detail SET location = NULL WHERE location = OLD.id; + DELETE FROM asset.copy_location_order WHERE location = OLD.id; + DELETE FROM asset.copy_location_group_map WHERE location = OLD.id; + DELETE FROM config.circ_limit_set_copy_loc_map WHERE copy_loc = OLD.id; + ); + +COMMIT; + diff --git a/Open-ILS/src/sql/Pg/upgrade/XXXX.schema.reject-active-acpl-delete.sql b/Open-ILS/src/sql/Pg/upgrade/XXXX.schema.reject-active-acpl-delete.sql deleted file mode 100644 index b767ba83fe..0000000000 --- a/Open-ILS/src/sql/Pg/upgrade/XXXX.schema.reject-active-acpl-delete.sql +++ /dev/null @@ -1,30 +0,0 @@ -BEGIN; - --- SELECT evergreen.upgrade_deps_block_check('TODO', :eg_version); - -CREATE OR REPLACE FUNCTION asset.check_delete_copy_location(acpl_id INTEGER) - RETURNS VOID AS $FUNK$ -BEGIN - PERFORM TRUE FROM asset.copy WHERE location = acpl_id AND NOT deleted LIMIT 1; - - IF FOUND THEN - RAISE EXCEPTION - 'Copy location % contains active copies and cannot be deleted', acpl_id; - END IF; -END; -$FUNK$ LANGUAGE plpgsql; - -DROP RULE protect_copy_location_delete ON asset.copy_location; - -CREATE RULE protect_copy_location_delete AS - ON DELETE TO asset.copy_location DO INSTEAD ( - SELECT asset.check_delete_copy_location(OLD.id); - UPDATE asset.copy_location SET deleted = TRUE WHERE OLD.id = asset.copy_location.id; - UPDATE acq.lineitem_detail SET location = NULL WHERE location = OLD.id; - DELETE FROM asset.copy_location_order WHERE location = OLD.id; - DELETE FROM asset.copy_location_group_map WHERE location = OLD.id; - DELETE FROM config.circ_limit_set_copy_loc_map WHERE copy_loc = OLD.id; - ); - -COMMIT; -