]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/src/sql/Pg/upgrade/0673.data.acq-cancel-reason-cleanup.sql
LP1893463: Follow-up to address de-duplication and adding release notes.
[Evergreen.git] / Open-ILS / src / sql / Pg / upgrade / 0673.data.acq-cancel-reason-cleanup.sql
1 -- Evergreen DB patch 0673.data.acq-cancel-reason-cleanup.sql
2 --
3 BEGIN;
4
5 -- check whether patch can be applied
6 SELECT evergreen.upgrade_deps_block_check('0673', :eg_version);
7
8 DELETE FROM
9     acq.cancel_reason
10 WHERE
11     -- any entries with id >= 2000 were added locally.  
12     id < 2000 
13
14     -- these cancel_reason's are actively used by the system
15     AND id NOT IN (1, 2, 3, 1002, 1003, 1004, 1005, 1010, 1024, 1211, 1221, 1246, 1283)
16
17     -- don't delete any cancel_reason's that may be in use locally
18     AND id NOT IN (SELECT DISTINCT(cancel_reason) FROM acq.user_request WHERE cancel_reason IS NOT NULL)
19     AND id NOT IN (SELECT DISTINCT(cancel_reason) FROM acq.purchase_order WHERE cancel_reason IS NOT NULL)
20     AND id NOT IN (SELECT DISTINCT(cancel_reason) FROM acq.lineitem WHERE cancel_reason IS NOT NULL)
21     AND id NOT IN (SELECT DISTINCT(cancel_reason) FROM acq.lineitem_detail WHERE cancel_reason IS NOT NULL)
22     AND id NOT IN (SELECT DISTINCT(cancel_reason) FROM acq.acq_lineitem_history WHERE cancel_reason IS NOT NULL)
23     AND id NOT IN (SELECT DISTINCT(cancel_reason) FROM acq.acq_purchase_order_history WHERE cancel_reason IS NOT NULL);
24
25 COMMIT;