]> git.evergreen-ils.org Git - working/Evergreen.git/blob - Open-ILS/src/sql/Pg/upgrade/XXXX.schema.acq-vandelay-integration.sql
ACQ+Vandelay schema and IDL changes w/ upgrade script
[working/Evergreen.git] / Open-ILS / src / sql / Pg / upgrade / XXXX.schema.acq-vandelay-integration.sql
1 -- Evergreen DB patch XXXX.schema.acq-vandelay-integration.sql
2 BEGIN;
3
4 -- check whether patch can be applied
5 SELECT evergreen.upgrade_deps_block_check('XXXX', :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 COMMIT;
48
49 /* UNDO SQL
50 -- XXX this does not exactly recover the state.  The bib/auth queue_type colum is
51 -- directly inherited instead of overridden, which will fail with some of the sql above.
52 ALTER TABLE acq.lineitem DROP COLUMN queued_record;
53 ALTER TABLE acq.acq_lineitem_history DROP COLUMN queued_record;
54 ALTER TABLE vandelay.authority_queue DROP COLUMN queue_type;
55 ALTER TABLE vandelay.bib_queue DROP COLUMN queue_type;
56
57 DROP TYPE vandelay.bib_queue_queue_type;
58 DROP TYPE vandelay.authority_queue_queue_type;
59
60 ALTER TABLE vandelay.bib_queue DROP CONSTRAINT vand_bib_queue_name_once_per_owner_const;
61 ALTER TABLE vandelay.authority_queue DROP CONSTRAINT vand_authority_queue_name_once_per_owner_const;
62
63 ALTER TABLE vandelay.queue ADD COLUMN queue_type TEXT NOT NULL DEFAULT 'bib' CHECK (queue_type IN ('bib','authority'));
64 UPDATE vandelay.authority_queue SET queue_type = 'authority';
65 ALTER TABLE vandelay.bib_queue ADD CONSTRAINT bib_queue_queue_type_check CHECK (queue_type IN ('bib'));
66 ALTER TABLE vandelay.authority_queue ADD CONSTRAINT authority_queue_queue_type_check CHECK (queue_type IN ('authority'));
67
68 DELETE FROM permission.perm_list WHERE code = 'IMPORT_ACQ_LINEITEM_BIB_RECORD_UPLOAD';
69 DELETE FROM vandelay.import_error WHERE code = 'import.record.perm_failure';
70 */
71
72