From: Jane Sandberg Date: Thu, 27 Oct 2022 22:27:46 +0000 (-0700) Subject: LP1952931 stamp upgrade script X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=25f23ca394d5759f685f6b54933e9d0db18423cd;p=evergreen%2Fpines.git LP1952931 stamp upgrade script Signed-off-by: Jane Sandberg --- diff --git a/Open-ILS/src/sql/Pg/002.schema.config.sql b/Open-ILS/src/sql/Pg/002.schema.config.sql index b3ebef822d..ffa81f5739 100644 --- a/Open-ILS/src/sql/Pg/002.schema.config.sql +++ b/Open-ILS/src/sql/Pg/002.schema.config.sql @@ -92,7 +92,7 @@ CREATE TRIGGER no_overlapping_deps BEFORE INSERT OR UPDATE ON config.db_patch_dependencies FOR EACH ROW EXECUTE PROCEDURE evergreen.array_overlap_check ('deprecates'); -INSERT INTO config.upgrade_log (version, applied_to) VALUES ('1343', :eg_version); -- mrylander/jweston/sandbergja +INSERT INTO config.upgrade_log (version, applied_to) VALUES ('1345', :eg_version); -- berick/tlittle/sandbergja CREATE TABLE config.bib_source ( id SERIAL PRIMARY KEY, diff --git a/Open-ILS/src/sql/Pg/upgrade/1345.schema.acq-asn.sql b/Open-ILS/src/sql/Pg/upgrade/1345.schema.acq-asn.sql new file mode 100644 index 0000000000..1a87429b77 --- /dev/null +++ b/Open-ILS/src/sql/Pg/upgrade/1345.schema.acq-asn.sql @@ -0,0 +1,70 @@ +BEGIN; + +SELECT evergreen.upgrade_deps_block_check('1345', :eg_version); + +CREATE TABLE acq.shipment_notification ( + id SERIAL PRIMARY KEY, + receiver INT NOT NULL REFERENCES actor.org_unit (id), + provider INT NOT NULL REFERENCES acq.provider (id), + shipper INT NOT NULL REFERENCES acq.provider (id), + recv_date TIMESTAMPTZ NOT NULL DEFAULT NOW(), + recv_method TEXT NOT NULL REFERENCES acq.invoice_method (code) DEFAULT 'EDI', + process_date TIMESTAMPTZ, + processed_by INT REFERENCES actor.usr(id) ON DELETE SET NULL, + container_code TEXT NOT NULL, -- vendor-supplied super-barcode + lading_number TEXT, -- informational + note TEXT, + CONSTRAINT container_code_once_per_provider UNIQUE(provider, container_code) +); + +CREATE INDEX acq_asn_container_code_idx ON acq.shipment_notification (container_code); + +CREATE TABLE acq.shipment_notification_entry ( + id SERIAL PRIMARY KEY, + shipment_notification INT NOT NULL REFERENCES acq.shipment_notification (id) + ON DELETE CASCADE, + lineitem INT REFERENCES acq.lineitem (id) + ON UPDATE CASCADE ON DELETE SET NULL, + item_count INT NOT NULL -- How many items the provider shipped +); + +/* TODO alter valid_message_type constraint */ + +ALTER TABLE acq.edi_message DROP CONSTRAINT valid_message_type; +ALTER TABLE acq.edi_message ADD CONSTRAINT valid_message_type +CHECK ( + message_type IN ( + 'ORDERS', + 'ORDRSP', + 'INVOIC', + 'OSTENQ', + 'OSTRPT', + 'DESADV' + ) +); + +COMMIT; + +/* UNDO + +DELETE FROM acq.edi_message WHERE message_type = 'DESADV'; + +DELETE FROM acq.shipment_notification_entry; +DELETE FROM acq.shipment_notification; + +ALTER TABLE acq.edi_message DROP CONSTRAINT valid_message_type; +ALTER TABLE acq.edi_message ADD CONSTRAINT valid_message_type +CHECK ( + message_type IN ( + 'ORDERS', + 'ORDRSP', + 'INVOIC', + 'OSTENQ', + 'OSTRPT' + ) +); + +DROP TABLE acq.shipment_notification_entry; +DROP TABLE acq.shipment_notification; + +*/ diff --git a/Open-ILS/src/sql/Pg/upgrade/XXXX.schema.acq-asn.sql b/Open-ILS/src/sql/Pg/upgrade/XXXX.schema.acq-asn.sql deleted file mode 100644 index ad295b721f..0000000000 --- a/Open-ILS/src/sql/Pg/upgrade/XXXX.schema.acq-asn.sql +++ /dev/null @@ -1,70 +0,0 @@ -BEGIN; - --- SELECT evergreen.upgrade_deps_block_check('TODO', :eg_version); - -CREATE TABLE acq.shipment_notification ( - id SERIAL PRIMARY KEY, - receiver INT NOT NULL REFERENCES actor.org_unit (id), - provider INT NOT NULL REFERENCES acq.provider (id), - shipper INT NOT NULL REFERENCES acq.provider (id), - recv_date TIMESTAMPTZ NOT NULL DEFAULT NOW(), - recv_method TEXT NOT NULL REFERENCES acq.invoice_method (code) DEFAULT 'EDI', - process_date TIMESTAMPTZ, - processed_by INT REFERENCES actor.usr(id) ON DELETE SET NULL, - container_code TEXT NOT NULL, -- vendor-supplied super-barcode - lading_number TEXT, -- informational - note TEXT, - CONSTRAINT container_code_once_per_provider UNIQUE(provider, container_code) -); - -CREATE INDEX acq_asn_container_code_idx ON acq.shipment_notification (container_code); - -CREATE TABLE acq.shipment_notification_entry ( - id SERIAL PRIMARY KEY, - shipment_notification INT NOT NULL REFERENCES acq.shipment_notification (id) - ON DELETE CASCADE, - lineitem INT REFERENCES acq.lineitem (id) - ON UPDATE CASCADE ON DELETE SET NULL, - item_count INT NOT NULL -- How many items the provider shipped -); - -/* TODO alter valid_message_type constraint */ - -ALTER TABLE acq.edi_message DROP CONSTRAINT valid_message_type; -ALTER TABLE acq.edi_message ADD CONSTRAINT valid_message_type -CHECK ( - message_type IN ( - 'ORDERS', - 'ORDRSP', - 'INVOIC', - 'OSTENQ', - 'OSTRPT', - 'DESADV' - ) -); - -COMMIT; - -/* UNDO - -DELETE FROM acq.edi_message WHERE message_type = 'DESADV'; - -DELETE FROM acq.shipment_notification_entry; -DELETE FROM acq.shipment_notification; - -ALTER TABLE acq.edi_message DROP CONSTRAINT valid_message_type; -ALTER TABLE acq.edi_message ADD CONSTRAINT valid_message_type -CHECK ( - message_type IN ( - 'ORDERS', - 'ORDRSP', - 'INVOIC', - 'OSTENQ', - 'OSTRPT' - ) -); - -DROP TABLE acq.shipment_notification_entry; -DROP TABLE acq.shipment_notification; - -*/