From 7924287c08a936e335db1676f8f28eb4740349ae Mon Sep 17 00:00:00 2001 From: atz Date: Mon, 13 Sep 2010 16:34:32 +0000 Subject: [PATCH] Prevent failure of update scripts. git-svn-id: svn://svn.open-ils.org/ILS/trunk@17632 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- .../sql/Pg/upgrade/0385.schema.perm_list_fkeys.sql | 20 ++++++++++++++------ .../0387.schema.perm_list_fkeys_restrict_delete.sql | 12 ++++++++---- 2 files changed, 22 insertions(+), 10 deletions(-) diff --git a/Open-ILS/src/sql/Pg/upgrade/0385.schema.perm_list_fkeys.sql b/Open-ILS/src/sql/Pg/upgrade/0385.schema.perm_list_fkeys.sql index 8dd242ad6..e24dbf888 100644 --- a/Open-ILS/src/sql/Pg/upgrade/0385.schema.perm_list_fkeys.sql +++ b/Open-ILS/src/sql/Pg/upgrade/0385.schema.perm_list_fkeys.sql @@ -1,20 +1,28 @@ + +-- First drop the stuff we are going to (re)create. If it fails for not existing, fine. +-- Some constraints might have different names, so we try all of them. +ALTER TABLE permission.grp_perm_map DROP CONSTRAINT grp_perm_map_perm_fkey; +ALTER TABLE permission.usr_perm_map DROP CONSTRAINT usr_perm_map_perm_fkey; +ALTER TABLE permission.usr_object_perm_map DROP CONSTRAINT usr_object_perm_map_perm_fkey; + +ALTER TABLE config.org_unit_setting_type DROP CONSTRAINT view_perm_fkey; +ALTER TABLE config.org_unit_setting_type DROP CONSTRAINT update_perm_fkey; +ALTER TABLE config.org_unit_setting_type DROP CONSTRAINT org_unit_setting_type_view_perm_fkey; -- alternate name +ALTER TABLE config.org_unit_setting_type DROP CONSTRAINT org_unit_setting_type_update_perm_fkey; -- alternate name + + BEGIN; INSERT INTO config.upgrade_log (version) VALUES ('0385'); --gmc -ALTER TABLE permission.grp_perm_map DROP CONSTRAINT grp_perm_map_perm_fkey; ALTER TABLE permission.grp_perm_map ADD CONSTRAINT grp_perm_map_perm_fkey FOREIGN KEY (perm) REFERENCES permission.perm_list (id) ON UPDATE CASCADE ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED; -ALTER TABLE permission.usr_perm_map DROP CONSTRAINT usr_perm_map_perm_fkey; ALTER TABLE permission.usr_perm_map ADD CONSTRAINT usr_perm_map_perm_fkey FOREIGN KEY (perm) REFERENCES permission.perm_list (id) ON UPDATE CASCADE ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED; -ALTER TABLE permission.usr_object_perm_map DROP CONSTRAINT usr_object_perm_map_perm_fkey; ALTER TABLE permission.usr_object_perm_map ADD CONSTRAINT usr_object_perm_map_perm_fkey FOREIGN KEY (perm) REFERENCES permission.perm_list (id) ON UPDATE CASCADE ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED; -ALTER TABLE config.org_unit_setting_type DROP CONSTRAINT view_perm_fkey; -ALTER TABLE config.org_unit_setting_type ADD CONSTRAINT view_perm_fkey FOREIGN KEY (view_perm) REFERENCES permission.perm_list (id) ON UPDATE CASCADE ON DELETE SET NULL DEFERRABLE INITIALLY DEFERRED; -ALTER TABLE config.org_unit_setting_type DROP CONSTRAINT update_perm_fkey; +ALTER TABLE config.org_unit_setting_type ADD CONSTRAINT view_perm_fkey FOREIGN KEY (view_perm ) REFERENCES permission.perm_list (id) ON UPDATE CASCADE ON DELETE SET NULL DEFERRABLE INITIALLY DEFERRED; ALTER TABLE config.org_unit_setting_type ADD CONSTRAINT update_perm_fkey FOREIGN KEY (update_perm) REFERENCES permission.perm_list (id) ON UPDATE CASCADE DEFERRABLE INITIALLY DEFERRED; COMMIT; diff --git a/Open-ILS/src/sql/Pg/upgrade/0387.schema.perm_list_fkeys_restrict_delete.sql b/Open-ILS/src/sql/Pg/upgrade/0387.schema.perm_list_fkeys_restrict_delete.sql index c79e37515..9b3c72189 100644 --- a/Open-ILS/src/sql/Pg/upgrade/0387.schema.perm_list_fkeys_restrict_delete.sql +++ b/Open-ILS/src/sql/Pg/upgrade/0387.schema.perm_list_fkeys_restrict_delete.sql @@ -1,18 +1,22 @@ + +-- First drop the stuff we are going to (re)create. If it fails for not existing, fine. + +ALTER TABLE permission.grp_perm_map DROP CONSTRAINT grp_perm_map_perm_fkey; +ALTER TABLE permission.usr_perm_map DROP CONSTRAINT usr_perm_map_perm_fkey; +ALTER TABLE permission.usr_object_perm_map DROP CONSTRAINT usr_object_perm_map_perm_fkey; +ALTER TABLE config.org_unit_setting_type DROP CONSTRAINT view_perm_fkey; + BEGIN; INSERT INTO config.upgrade_log (version) VALUES ('0387'); --gmc -ALTER TABLE permission.grp_perm_map DROP CONSTRAINT grp_perm_map_perm_fkey; ALTER TABLE permission.grp_perm_map ADD CONSTRAINT grp_perm_map_perm_fkey FOREIGN KEY (perm) REFERENCES permission.perm_list (id) ON UPDATE CASCADE ON DELETE RESTRICT DEFERRABLE INITIALLY DEFERRED; -ALTER TABLE permission.usr_perm_map DROP CONSTRAINT usr_perm_map_perm_fkey; ALTER TABLE permission.usr_perm_map ADD CONSTRAINT usr_perm_map_perm_fkey FOREIGN KEY (perm) REFERENCES permission.perm_list (id) ON UPDATE CASCADE ON DELETE RESTRICT DEFERRABLE INITIALLY DEFERRED; -ALTER TABLE permission.usr_object_perm_map DROP CONSTRAINT usr_object_perm_map_perm_fkey; ALTER TABLE permission.usr_object_perm_map ADD CONSTRAINT usr_object_perm_map_perm_fkey FOREIGN KEY (perm) REFERENCES permission.perm_list (id) ON UPDATE CASCADE ON DELETE RESTRICT DEFERRABLE INITIALLY DEFERRED; -ALTER TABLE config.org_unit_setting_type DROP CONSTRAINT view_perm_fkey; ALTER TABLE config.org_unit_setting_type ADD CONSTRAINT view_perm_fkey FOREIGN KEY (view_perm) REFERENCES permission.perm_list (id) ON UPDATE CASCADE ON DELETE RESTRICT DEFERRABLE INITIALLY DEFERRED; COMMIT; -- 2.11.0