]> git.evergreen-ils.org Git - working/Evergreen.git/blob - Open-ILS/src/sql/Pg/upgrade/0695.schema.custom_toolbars.sql
Upgrade script numbering for acq order indentifier selector
[working/Evergreen.git] / Open-ILS / src / sql / Pg / upgrade / 0695.schema.custom_toolbars.sql
1 -- Evergreen DB patch 0695.schema.custom_toolbars.sql
2 --
3 -- FIXME: insert description of change, if needed
4 --
5 BEGIN;
6
7
8 -- check whether patch can be applied
9 SELECT evergreen.upgrade_deps_block_check('0695', :eg_version);
10
11 CREATE TABLE actor.toolbar (
12     id          BIGSERIAL   PRIMARY KEY,
13     ws          INT         REFERENCES actor.workstation (id) ON DELETE CASCADE,
14     org         INT         REFERENCES actor.org_unit (id) ON DELETE CASCADE,
15     usr         INT         REFERENCES actor.usr (id) ON DELETE CASCADE,
16     label       TEXT        NOT NULL,
17     layout      TEXT        NOT NULL,
18     CONSTRAINT only_one_type CHECK (
19         (ws IS NOT NULL AND COALESCE(org,usr) IS NULL) OR
20         (org IS NOT NULL AND COALESCE(ws,usr) IS NULL) OR
21         (usr IS NOT NULL AND COALESCE(org,ws) IS NULL)
22     ),
23     CONSTRAINT layout_must_be_json CHECK ( is_json(layout) )
24 );
25 CREATE UNIQUE INDEX label_once_per_ws ON actor.toolbar (ws, label) WHERE ws IS NOT NULL;
26 CREATE UNIQUE INDEX label_once_per_org ON actor.toolbar (org, label) WHERE org IS NOT NULL;
27 CREATE UNIQUE INDEX label_once_per_usr ON actor.toolbar (usr, label) WHERE usr IS NOT NULL;
28
29 -- this one unrelated to toolbars but is a gap in the upgrade scripts
30 INSERT INTO permission.perm_list ( id, code, description )
31     SELECT
32         522,
33         'IMPORT_AUTHORITY_MARC',
34         oils_i18n_gettext(
35             522,
36             'Allows a user to create new authority records',
37             'ppl',
38             'description'
39         )
40     WHERE NOT EXISTS (
41         SELECT 1
42         FROM permission.perm_list
43         WHERE
44             id = 522
45     );
46
47 INSERT INTO permission.perm_list ( id, code, description ) VALUES (
48     523,
49     'ADMIN_TOOLBAR',
50     oils_i18n_gettext(
51         523,
52         'Allows a user to create, edit, and delete custom toolbars',
53         'ppl',
54         'description'
55     )
56 );
57
58 -- Don't want to assume stock perm groups in an upgrade script, but here for ease of testing
59 -- 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';
60
61 INSERT INTO actor.toolbar(org,label,layout) VALUES
62     ( 1, 'circ', '["circ_checkout","circ_checkin","toolbarseparator.1","search_opac","copy_status","toolbarseparator.2","patron_search","patron_register","toolbarspacer.3","hotkeys_toggle"]' ),
63     ( 1, 'cat', '["circ_checkin","toolbarseparator.1","search_opac","copy_status","toolbarseparator.2","create_marc","authority_manage","retrieve_last_record","toolbarspacer.3","hotkeys_toggle"]' );
64
65 -- 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 ;
66
67
68 COMMIT;