]> git.evergreen-ils.org Git - working/Evergreen.git/blob - Open-ILS/src/sql/Pg/upgrade/0684.schema.acq-vandelay-integration.sql
LP2042879 Shelving Location Groups Admin accessibility
[working/Evergreen.git] / Open-ILS / src / sql / Pg / upgrade / 0684.schema.acq-vandelay-integration.sql
1 -- Evergreen DB patch 0684.schema.acq-vandelay-integration.sql
2 BEGIN;
3
4 -- check whether patch can be applied
5 SELECT evergreen.upgrade_deps_block_check('0684', :eg_version);
6
7 -- schema --
8
9 -- Replace the constraints with more flexible ENUM's
10 ALTER TABLE vandelay.queue DROP CONSTRAINT queue_queue_type_check;
11 ALTER TABLE vandelay.bib_queue DROP CONSTRAINT bib_queue_queue_type_check;
12 ALTER TABLE vandelay.authority_queue DROP CONSTRAINT authority_queue_queue_type_check;
13
14 CREATE TYPE vandelay.bib_queue_queue_type AS ENUM ('bib', 'acq');
15 CREATE TYPE vandelay.authority_queue_queue_type AS ENUM ('authority');
16
17 -- dropped column is also implemented by the child tables
18 ALTER TABLE vandelay.queue DROP COLUMN queue_type; 
19
20 -- to recover after using the undo sql from below
21 -- alter table vandelay.bib_queue  add column queue_type text default 'bib' not null;
22 -- alter table vandelay.authority_queue  add column queue_type text default 'authority' not null;
23
24 -- modify the child tables to use the ENUMs
25 ALTER TABLE vandelay.bib_queue 
26     ALTER COLUMN queue_type DROP DEFAULT,
27     ALTER COLUMN queue_type TYPE vandelay.bib_queue_queue_type 
28         USING (queue_type::vandelay.bib_queue_queue_type),
29     ALTER COLUMN queue_type SET DEFAULT 'bib';
30
31 ALTER TABLE vandelay.authority_queue 
32     ALTER COLUMN queue_type DROP DEFAULT,
33     ALTER COLUMN queue_type TYPE vandelay.authority_queue_queue_type 
34         USING (queue_type::vandelay.authority_queue_queue_type),
35     ALTER COLUMN queue_type SET DEFAULT 'authority';
36
37 -- give lineitems a pointer to their vandelay queued_record
38
39 ALTER TABLE acq.lineitem ADD COLUMN queued_record BIGINT
40     REFERENCES vandelay.queued_bib_record (id) 
41     ON DELETE SET NULL DEFERRABLE INITIALLY DEFERRED;
42
43 ALTER TABLE acq.acq_lineitem_history ADD COLUMN queued_record BIGINT
44     REFERENCES vandelay.queued_bib_record (id) 
45     ON DELETE SET NULL DEFERRABLE INITIALLY DEFERRED;
46
47 -- seed data --
48
49 INSERT INTO permission.perm_list ( id, code, description ) 
50     VALUES ( 
51         521, 
52         'IMPORT_ACQ_LINEITEM_BIB_RECORD_UPLOAD', 
53         oils_i18n_gettext( 
54             521,
55             'Allows a user to create new bibs directly from an ACQ MARC file upload', 
56             'ppl', 
57             'description' 
58         )
59     );
60
61
62 INSERT INTO vandelay.import_error ( code, description ) 
63     VALUES ( 
64         'import.record.perm_failure', 
65         oils_i18n_gettext(
66             'import.record.perm_failure', 
67             'Perm failure creating a record', 'vie', 'description') 
68     );
69
70
71 COMMIT;
72
73 /* UNDO SQL
74 -- XXX this does not exactly recover the state.  The bib/auth queue_type colum is
75 -- directly inherited instead of overridden, which will fail with some of the sql above.
76 ALTER TABLE acq.lineitem DROP COLUMN queued_record;
77 ALTER TABLE acq.acq_lineitem_history DROP COLUMN queued_record;
78 ALTER TABLE vandelay.authority_queue DROP COLUMN queue_type;
79 ALTER TABLE vandelay.bib_queue DROP COLUMN queue_type;
80
81 DROP TYPE vandelay.bib_queue_queue_type;
82 DROP TYPE vandelay.authority_queue_queue_type;
83
84 ALTER TABLE vandelay.bib_queue DROP CONSTRAINT vand_bib_queue_name_once_per_owner_const;
85 ALTER TABLE vandelay.authority_queue DROP CONSTRAINT vand_authority_queue_name_once_per_owner_const;
86
87 ALTER TABLE vandelay.queue ADD COLUMN queue_type TEXT NOT NULL DEFAULT 'bib' CHECK (queue_type IN ('bib','authority'));
88 UPDATE vandelay.authority_queue SET queue_type = 'authority';
89 ALTER TABLE vandelay.bib_queue ADD CONSTRAINT bib_queue_queue_type_check CHECK (queue_type IN ('bib'));
90 ALTER TABLE vandelay.authority_queue ADD CONSTRAINT authority_queue_queue_type_check CHECK (queue_type IN ('authority'));
91
92 DELETE FROM permission.perm_list WHERE code = 'IMPORT_ACQ_LINEITEM_BIB_RECORD_UPLOAD';
93 DELETE FROM vandelay.import_error WHERE code = 'import.record.perm_failure';
94 */
95
96