]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/src/sql/Pg/upgrade/0594.schema.acp_status_date_changed.sql
Stamped upgrade script for "lp 823496: do not fail to index personal names that have...
[Evergreen.git] / Open-ILS / src / sql / Pg / upgrade / 0594.schema.acp_status_date_changed.sql
1 -- Evergreen DB patch YYYY.schema.acp_status_date_changed.sql
2 --
3 -- Change trigger which updates copy status_changed_time to ignore the
4 -- Reshelving->Available status rollover
5 BEGIN;
6
7 -- FIXME: 0039.schema.acp_status_date_changed.sql defines this the first time
8 -- around, but along with the column itself, etc.  And it gets modified with
9 -- 0562.schema.copy_active_date.sql.  Not sure how to use the supercedes /
10 -- deprecate stuff for upgrade scripts, if it's even applicable when a given
11 -- upgrade script is doing so much.
12
13 -- check whether patch can be applied
14 SELECT evergreen.upgrade_deps_block_check('0594', :eg_version);
15
16 CREATE OR REPLACE FUNCTION asset.acp_status_changed()
17 RETURNS TRIGGER AS $$
18 BEGIN
19         IF NEW.status <> OLD.status AND NOT (NEW.status = 0 AND OLD.status = 7) THEN
20         NEW.status_changed_time := now();
21         IF NEW.active_date IS NULL AND NEW.status IN (SELECT id FROM config.copy_status WHERE copy_active = true) THEN
22             NEW.active_date := now();
23         END IF;
24     END IF;
25     RETURN NEW;
26 END;
27 $$ LANGUAGE plpgsql;
28
29 COMMIT;