]> git.evergreen-ils.org Git - working/Evergreen.git/blob - Open-ILS/src/sql/Pg/upgrade/0264.schema.acq-edi-message-type.sql
Two changes to acq.edi_message:
[working/Evergreen.git] / Open-ILS / src / sql / Pg / upgrade / 0264.schema.acq-edi-message-type.sql
1 BEGIN;
2
3 INSERT INTO config.upgrade_log (version) VALUES ('0264'); -- Scott McKellar
4
5 -- Add a message_type column
6
7 -- WARNING: because the new column is NOT NULL, this upgrade script must
8 -- initialize it with something if the table is not empty.  The initial
9 -- value, 'ORDERS', may not always be appropriate.  Massage as needed.
10
11 ALTER TABLE acq.edi_message
12         ADD COLUMN message_type TEXT;
13
14 UPDATE acq.edi_message
15 SET message_type = 'ORDERS';
16
17 ALTER TABLE acq.edi_message
18         ALTER COLUMN message_type SET NOT NULL;
19
20 ALTER TABLE acq.edi_message
21         ADD CONSTRAINT valid_message_type CHECK
22                 ( message_type IN (
23                         'ORDERS',
24                         'ORDRSP',
25                         'INVOIC',
26                         'OSTENQ',
27                         'OSTRPT'
28                 ));
29
30 -- Add a new valid value for status: 'retry'
31
32 ALTER TABLE acq.edi_message
33         DROP CONSTRAINT status_value;
34
35 ALTER TABLE acq.edi_message
36         ADD CONSTRAINT status_value CHECK
37         ( status IN (
38                 'new',          -- needs to be translated
39                 'translated',   -- needs to be processed
40                 'trans_error',  -- error in translation step
41                 'processed',    -- needs to have remote_file deleted
42                 'proc_error',   -- error in processing step
43                 'delete_error', -- error in deletion
44                 'retry',        -- need to retry
45                 'complete'      -- done
46         ));
47
48 COMMIT;