]> git.evergreen-ils.org Git - working/Evergreen.git/blob - Open-ILS/src/sql/Pg/upgrade/0701.schema.patron_stat_category_enhancements.sql
Fix 0752 and 0756 upgrade scripts
[working/Evergreen.git] / Open-ILS / src / sql / Pg / upgrade / 0701.schema.patron_stat_category_enhancements.sql
1 -- Evergreen DB patch 0701.schema.patron_stat_category_enhancements.sql
2 --
3 -- Enables users to set patron statistical categories as required,
4 -- whether or not users can input free text for the category value.
5 -- Enables administrators to set an entry as the default for any
6 -- given patron statistical category and org unit.
7 --
8 BEGIN;
9
10 -- check whether patch can be applied
11 SELECT evergreen.upgrade_deps_block_check('0701', :eg_version);
12
13 -- New table
14
15 CREATE TABLE actor.stat_cat_entry_default (
16     id              SERIAL  PRIMARY KEY,
17     stat_cat_entry  INT     NOT NULL REFERENCES actor.stat_cat_entry (id) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED,
18     stat_cat        INT     NOT NULL REFERENCES actor.stat_cat (id) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED,
19     owner           INT     NOT NULL REFERENCES actor.org_unit (id) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED,
20     CONSTRAINT sced_once_per_owner UNIQUE (stat_cat,owner)
21 );
22
23 COMMENT ON TABLE actor.stat_cat_entry_default IS $$
24 User Statistical Category Default Entry
25
26 A library may choose one of the stat_cat entries to be the
27 default entry.
28 $$;
29
30 -- Add columns to existing tables
31
32 -- Patron stat cat required column
33 ALTER TABLE actor.stat_cat
34     ADD COLUMN required BOOL NOT NULL DEFAULT FALSE;
35
36 -- Patron stat cat allow_freetext column
37 ALTER TABLE actor.stat_cat
38     ADD COLUMN allow_freetext BOOL NOT NULL DEFAULT TRUE;
39
40 -- Add permissions
41
42 INSERT INTO permission.perm_list ( id, code, description ) VALUES
43     ( 525, 'CREATE_PATRON_STAT_CAT_ENTRY_DEFAULT', oils_i18n_gettext( 525, 
44         'User may set a default entry in a patron statistical category', 'ppl', 'description' )),
45     ( 526, 'UPDATE_PATRON_STAT_CAT_ENTRY_DEFAULT', oils_i18n_gettext( 526, 
46         'User may reset a default entry in a patron statistical category', 'ppl', 'description' )),
47     ( 527, 'DELETE_PATRON_STAT_CAT_ENTRY_DEFAULT', oils_i18n_gettext( 527, 
48         'User may unset a default entry in a patron statistical category', 'ppl', 'description' ));
49
50 INSERT INTO permission.grp_perm_map (grp, perm, depth, grantable)
51     SELECT
52         pgt.id, perm.id, aout.depth, TRUE
53     FROM
54         permission.grp_tree pgt,
55         permission.perm_list perm,
56         actor.org_unit_type aout
57     WHERE
58         pgt.name = 'Circulation Administrator' AND
59         aout.name = 'System' AND
60         perm.code IN ('CREATE_PATRON_STAT_CAT_ENTRY_DEFAULT', 'DELETE_PATRON_STAT_CAT_ENTRY_DEFAULT');
61
62 COMMIT;