]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/src/sql/Pg/upgrade/0823.schema.patron-self-reg.sql
LP#1643709: Stamping upgrade scripts
[Evergreen.git] / Open-ILS / src / sql / Pg / upgrade / 0823.schema.patron-self-reg.sql
1
2 BEGIN;
3
4 SELECT evergreen.upgrade_deps_block_check('0823', :eg_version);
5
6 -- Track the requesting user
7 ALTER TABLE staging.user_stage
8     ADD COLUMN requesting_usr INTEGER 
9         REFERENCES actor.usr(id) ON DELETE SET NULL;
10
11 -- add county column to staged address tables and 
12 -- drop state requirement to match actor.usr_address
13 ALTER TABLE staging.mailing_address_stage 
14     ADD COLUMN county TEXT,
15     ALTER COLUMN state DROP DEFAULT,
16     ALTER COLUMN state DROP NOT NULL;
17
18 ALTER TABLE staging.billing_address_stage 
19     ADD COLUMN county TEXT,
20     ALTER COLUMN state DROP DEFAULT,
21     ALTER COLUMN state DROP NOT NULL;
22
23 -- stored procedure for deleting expired pending patrons
24 CREATE OR REPLACE FUNCTION staging.purge_pending_users() RETURNS VOID AS $$
25 DECLARE
26     org_id INT;
27     intvl TEXT;
28 BEGIN
29     FOR org_id IN SELECT DISTINCT(home_ou) FROM staging.user_stage LOOP
30
31         SELECT INTO intvl value FROM 
32             actor.org_unit_ancestor_setting(
33                 'opac.pending_user_expire_interval', org_id);
34
35         CONTINUE WHEN intvl IS NULL OR intvl ILIKE 'null';
36
37         -- de-JSON-ify the string
38         SELECT INTO intvl TRIM(BOTH '"' FROM intvl);
39
40         DELETE FROM staging.user_stage 
41             WHERE home_ou = org_id AND row_date + intvl::INTERVAL < NOW();
42
43     END LOOP;
44 END;
45 $$ LANGUAGE PLPGSQL;
46
47
48 INSERT INTO config.org_unit_setting_type
49     (name, grp, datatype, label, description)
50 VALUES (
51     'opac.allow_pending_user',
52     'opac',
53     'bool',
54     oils_i18n_gettext(
55         'opac.allow_pending_user',
56         'Allow Patron Self-Registration',
57         'coust',
58         'label'
59     ),
60     oils_i18n_gettext(
61         'opac.allow_pending_user',
62         'Allow patrons to self-register, creating pending user accounts',
63         'coust',
64         'description'
65     )
66 ), (
67     'opac.pending_user_expire_interval',
68     'opac',
69     'interval',
70     oils_i18n_gettext(
71         'opac.pending_user_expire_interval',
72         'Patron Self-Reg. Expire Interval',
73         'coust',
74         'label'
75     ),
76     oils_i18n_gettext(
77         'opac.pending_user_expire_interval',
78         'If set, this is the amount of time a pending user account will ' ||
79         'be allowed to sit in the database.  After this time, the pending ' ||
80         'user information will be purged',
81         'coust',
82         'description'
83     )
84 ), (
85     'ui.patron.edit.aua.county.show',
86     'gui',
87     'bool',
88     oils_i18n_gettext(
89         'ui.patron.edit.aua.county.require',
90         'Show county field on patron registration',
91         'coust',
92         'label'
93     ),
94     oils_i18n_gettext(
95         'ui.patron.edit.aua.county.require',
96         'The county field will be shown on the patron registration screen',
97         'coust',
98         'description'
99     )
100 );
101
102 COMMIT;