1 -- Evergreen DB patch 0701.schema.patron_stat_category_enhancements.sql
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.
10 -- check whether patch can be applied
11 SELECT evergreen.upgrade_deps_block_check('0701', :eg_version);
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)
23 COMMENT ON TABLE actor.stat_cat_entry_default IS $$
24 User Statistical Category Default Entry
26 A library may choose one of the stat_cat entries to be the
30 -- Add columns to existing tables
32 -- Patron stat cat required column
33 ALTER TABLE actor.stat_cat
34 ADD COLUMN required BOOL NOT NULL DEFAULT FALSE;
36 -- Patron stat cat allow_freetext column
37 ALTER TABLE actor.stat_cat
38 ADD COLUMN allow_freetext BOOL NOT NULL DEFAULT TRUE;
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' ));
50 INSERT INTO permission.grp_perm_map (grp, perm, depth, grantable)
52 pgt.id, perm.id, aout.depth, TRUE
54 permission.grp_tree pgt,
55 permission.perm_list perm,
56 actor.org_unit_type aout
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');