Forward-port 2.8.0 to 2.8.1 SQL upgrade
[working/Evergreen.git] / Open-ILS / src / sql / Pg / version-upgrade / 2.8.0-2.8.1-upgrade-db.sql
1 --Upgrade Script for 2.8.0 to 2.8.1
2 \set eg_version '''2.8.1'''
3 BEGIN;
4 INSERT INTO config.upgrade_log (version, applied_to) VALUES ('2.8.1', :eg_version);
5
6 SELECT evergreen.upgrade_deps_block_check('0916', :eg_version);
7
8 CREATE OR REPLACE FUNCTION actor.convert_usr_note_to_message () RETURNS TRIGGER AS $$
9 DECLARE
10         sending_ou INTEGER;
11 BEGIN
12         IF NEW.pub THEN
13                 IF TG_OP = 'UPDATE' THEN
14                         IF OLD.pub = TRUE THEN
15                                 RETURN NEW;
16                         END IF;
17                 END IF;
18
19                 SELECT INTO sending_ou aw.owning_lib
20                 FROM auditor.get_audit_info() agai
21                 JOIN actor.workstation aw ON (aw.id = agai.eg_ws);
22                 IF sending_ou IS NULL THEN
23                         SELECT INTO sending_ou home_ou
24                         FROM actor.usr
25                         WHERE id = NEW.creator;
26                 END IF;
27                 INSERT INTO actor.usr_message (usr, title, message, sending_lib)
28                         VALUES (NEW.usr, NEW.title, NEW.value, sending_ou);
29         END IF;
30
31         RETURN NEW;
32 END;
33 $$ LANGUAGE PLPGSQL;
34
35 COMMIT;