From 6ef8711978cb37e3d3b09ce5737daec551d8947d Mon Sep 17 00:00:00 2001 From: Thomas Berezansky Date: Wed, 28 Mar 2012 15:52:21 -0400 Subject: [PATCH] Stamping upgrade script for custom toolbars Signed-off-by: Thomas Berezansky --- Open-ILS/src/sql/Pg/002.schema.config.sql | 2 +- .../sql/Pg/upgrade/0695.schema.custom_toolbars.sql | 68 ++++++++++++++++++++++ 2 files changed, 69 insertions(+), 1 deletion(-) create mode 100644 Open-ILS/src/sql/Pg/upgrade/0695.schema.custom_toolbars.sql diff --git a/Open-ILS/src/sql/Pg/002.schema.config.sql b/Open-ILS/src/sql/Pg/002.schema.config.sql index acac661e84..52dbf17c01 100644 --- a/Open-ILS/src/sql/Pg/002.schema.config.sql +++ b/Open-ILS/src/sql/Pg/002.schema.config.sql @@ -86,7 +86,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 ('0694', :eg_version); -- mrpeters/miker +INSERT INTO config.upgrade_log (version, applied_to) VALUES ('0695', :eg_version); -- phasefx/tsbere CREATE TABLE config.bib_source ( id SERIAL PRIMARY KEY, diff --git a/Open-ILS/src/sql/Pg/upgrade/0695.schema.custom_toolbars.sql b/Open-ILS/src/sql/Pg/upgrade/0695.schema.custom_toolbars.sql new file mode 100644 index 0000000000..4ebb8bb700 --- /dev/null +++ b/Open-ILS/src/sql/Pg/upgrade/0695.schema.custom_toolbars.sql @@ -0,0 +1,68 @@ +-- Evergreen DB patch 0695.schema.custom_toolbars.sql +-- +-- FIXME: insert description of change, if needed +-- +BEGIN; + + +-- check whether patch can be applied +SELECT evergreen.upgrade_deps_block_check('0695', :eg_version); + +CREATE TABLE actor.toolbar ( + id BIGSERIAL PRIMARY KEY, + ws INT REFERENCES actor.workstation (id) ON DELETE CASCADE, + org INT REFERENCES actor.org_unit (id) ON DELETE CASCADE, + usr INT REFERENCES actor.usr (id) ON DELETE CASCADE, + label TEXT NOT NULL, + layout TEXT NOT NULL, + CONSTRAINT only_one_type CHECK ( + (ws IS NOT NULL AND COALESCE(org,usr) IS NULL) OR + (org IS NOT NULL AND COALESCE(ws,usr) IS NULL) OR + (usr IS NOT NULL AND COALESCE(org,ws) IS NULL) + ), + CONSTRAINT layout_must_be_json CHECK ( is_json(layout) ) +); +CREATE UNIQUE INDEX label_once_per_ws ON actor.toolbar (ws, label) WHERE ws IS NOT NULL; +CREATE UNIQUE INDEX label_once_per_org ON actor.toolbar (org, label) WHERE org IS NOT NULL; +CREATE UNIQUE INDEX label_once_per_usr ON actor.toolbar (usr, label) WHERE usr IS NOT NULL; + +-- this one unrelated to toolbars but is a gap in the upgrade scripts +INSERT INTO permission.perm_list ( id, code, description ) + SELECT + 522, + 'IMPORT_AUTHORITY_MARC', + oils_i18n_gettext( + 522, + 'Allows a user to create new authority records', + 'ppl', + 'description' + ) + WHERE NOT EXISTS ( + SELECT 1 + FROM permission.perm_list + WHERE + id = 522 + ); + +INSERT INTO permission.perm_list ( id, code, description ) VALUES ( + 523, + 'ADMIN_TOOLBAR', + oils_i18n_gettext( + 523, + 'Allows a user to create, edit, and delete custom toolbars', + 'ppl', + 'description' + ) +); + +-- Don't want to assume stock perm groups in an upgrade script, but here for ease of testing +-- INSERT INTO permission.grp_perm_map (grp, perm, depth, grantable) SELECT pgt.id, perm.id, aout.depth, FALSE FROM permission.grp_tree pgt, permission.perm_list perm, actor.org_unit_type aout WHERE pgt.name = 'Staff' AND aout.name = 'Branch' AND perm.code = 'ADMIN_TOOLBAR'; + +INSERT INTO actor.toolbar(org,label,layout) VALUES + ( 1, 'circ', '["circ_checkout","circ_checkin","toolbarseparator.1","search_opac","copy_status","toolbarseparator.2","patron_search","patron_register","toolbarspacer.3","hotkeys_toggle"]' ), + ( 1, 'cat', '["circ_checkin","toolbarseparator.1","search_opac","copy_status","toolbarseparator.2","create_marc","authority_manage","retrieve_last_record","toolbarspacer.3","hotkeys_toggle"]' ); + +-- delete from permission.grp_perm_map where perm in (select id from permission.perm_list where code ~ 'TOOLBAR'); delete from permission.perm_list where code ~ 'TOOLBAR'; drop table actor.toolbar ; + + +COMMIT; -- 2.11.0