]> git.evergreen-ils.org Git - working/Evergreen.git/blob - Open-ILS/src/sql/Pg/upgrade/XXYY.schema.custom-best-hold-selection.sql
55e390682fa68f8145ddd2443b3c27f435d73b60
[working/Evergreen.git] / Open-ILS / src / sql / Pg / upgrade / XXYY.schema.custom-best-hold-selection.sql
1 BEGIN;
2
3 CREATE TABLE config.best_hold_order(
4     id          SERIAL      PRIMARY KEY,    -- (metadata)
5     name        TEXT        UNIQUE,   -- i18n (metadata)
6     pprox       INT, -- copy capture <-> pickup lib prox
7     hprox       INT, -- copy circ lib <-> request lib prox
8     aprox       INT, -- copy circ lib <-> pickup lib ADJUSTED prox on ahcm
9     approx      INT, -- copy capture <-> pickup lib ADJUSTED prox from function
10     priority    INT, -- group hold priority
11     cut         INT, -- cut-in-line
12     depth       INT, -- selection depth
13     htime       INT, -- time since last home-lib circ exceeds org-unit setting
14     rtime       INT, -- request time
15     shtime      INT  -- time since copy last trip home exceeds org-unit setting
16 );
17
18 -- At least one of these columns must contain a non-null value
19 ALTER TABLE config.best_hold_order ADD CHECK ((
20     pprox IS NOT NULL OR
21     hprox IS NOT NULL OR
22     aprox IS NOT NULL OR
23     priority IS NOT NULL OR
24     cut IS NOT NULL OR
25     depth IS NOT NULL OR
26     htime IS NOT NULL OR
27     rtime IS NOT NULL
28 ));
29
30 INSERT INTO config.best_hold_order (
31     name,
32     pprox, aprox, priority, cut, depth, rtime, htime, hprox
33 ) VALUES (
34     'Traditional',
35     1, 2, 3, 4, 5, 6, 7, 8
36 );
37
38 INSERT INTO config.best_hold_order (
39     name,
40     hprox, pprox, aprox, priority, cut, depth, rtime, htime
41 ) VALUES (
42     'Traditional with Holds-always-go-home',
43     1, 2, 3, 4, 5, 6, 7, 8
44 );
45
46 INSERT INTO config.best_hold_order (
47     name,
48     htime, hprox, pprox, aprox, priority, cut, depth, rtime
49 ) VALUES (
50     'Traditional with Holds-go-home',
51     1, 2, 3, 4, 5, 6, 7, 8
52 );
53
54 INSERT INTO config.best_hold_order (
55     name,
56     priority, cut, rtime, depth, pprox, hprox, aprox, htime
57 ) VALUES (
58     'FIFO',
59     1, 2, 3, 4, 5, 6, 7, 8
60 );
61
62 INSERT INTO config.best_hold_order (
63     name,
64     hprox, priority, cut, rtime, depth, pprox, aprox, htime
65 ) VALUES (
66     'FIFO with Holds-always-go-home',
67     1, 2, 3, 4, 5, 6, 7, 8
68 );
69
70 INSERT INTO config.best_hold_order (
71     name,
72     htime, priority, cut, rtime, depth, pprox, aprox, hprox
73 ) VALUES (
74     'FIFO with Holds-go-home',
75     1, 2, 3, 4, 5, 6, 7, 8
76 );
77
78 INSERT INTO permission.perm_list (
79     id, code, description
80 ) VALUES (
81     543,
82     'ADMIN_HOLD_CAPTURE_SORT',
83     oils_i18n_gettext(
84         543,
85         'Allows a user to make changes to best-hold selection sort order',
86         'ppl',
87         'description'
88     )
89 );
90
91 INSERT INTO config.org_unit_setting_type (
92     name, label, description, datatype, fm_class, update_perm, grp
93 ) VALUES (
94     'circ.hold_capture_order',
95     oils_i18n_gettext(
96         'circ.hold_capture_order',
97         'Best-hold selection sort order',
98         'coust',
99         'label'
100     ),
101     oils_i18n_gettext(
102         'circ.hold_capture_order',
103         'Defines the sort order of holds when selecting a hold to fill using a given copy at capture time',
104         'coust',
105         'description'
106     ),
107     'link',
108     'cbho',
109     543,
110     'holds'
111 );
112
113 INSERT INTO config.org_unit_setting_type (
114     name, label, description, datatype, update_perm, grp
115 ) VALUES (
116     'circ.hold_go_home_interval',
117     oils_i18n_gettext(
118         'circ.hold_go_home_interval',
119         'Max foreign-circulation time',
120         'coust',
121         'label'
122     ),
123     oils_i18n_gettext(
124         'circ.hold_go_home_interval',
125         'Time a copy can spend circulating away from its circ lib before returning there to fill a hold (if one exists there)',
126         'coust',
127         'description'
128     ),
129     'interval',
130     543,
131     'holds'
132 );
133
134 INSERT INTO actor.org_unit_setting (
135     org_unit, name, value
136 ) VALUES (
137     (SELECT id FROM actor.org_unit WHERE parent_ou IS NULL),
138     'circ.hold_go_home_interval',
139     '"6 months"'
140 );
141
142 UPDATE actor.org_unit_setting SET
143     name = 'circ.hold_capture_order',
144     value = (SELECT id FROM config.best_hold_order WHERE name = 'FIFO')
145 WHERE
146     name = 'circ.holds_fifo' AND value ILIKE '%true%';
147
148 COMMIT;