]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/src/sql/Pg/upgrade/XXXX.schema.triggered_event_log.sql
LP1207533 patron triggered events log
[Evergreen.git] / Open-ILS / src / sql / Pg / upgrade / XXXX.schema.triggered_event_log.sql
1 BEGIN;
2
3 SELECT evergreen.upgrade_deps_block_check('XXXX', :eg_version);
4
5 --    context_usr_path        TEXT, -- for optimizing action_trigger.event
6 --    context_library_path    TEXT, -- '''
7 --    context_bib_path        TEXT, -- '''
8 ALTER TABLE action_trigger.event_definition ADD COLUMN context_usr_path TEXT;
9 ALTER TABLE action_trigger.event_definition ADD COLUMN context_library_path TEXT;
10 ALTER TABLE action_trigger.event_definition ADD COLUMN context_bib_path TEXT;
11
12 --    context_user    INT         REFERENCES actor.usr (id),
13 --    context_library INT         REFERENCES actor.org_unit (id),
14 --    context_bib     BIGINT      REFERENCES biblio.record_entry (id)
15 ALTER TABLE action_trigger.event ADD COLUMN context_user INT REFERENCES actor.usr (id);
16 ALTER TABLE action_trigger.event ADD COLUMN context_library INT REFERENCES actor.org_unit (id);
17 ALTER TABLE action_trigger.event ADD COLUMN context_bib BIGINT REFERENCES biblio.record_entry (id);
18 CREATE INDEX atev_context_user ON action_trigger.event (context_user);
19 CREATE INDEX atev_context_library ON action_trigger.event (context_library);
20
21 UPDATE
22     action_trigger.event_definition
23 SET
24     context_usr_path = 'usr',
25     context_library_path = 'circ_lib',
26     context_bib_path = 'target_copy.call_number.record'
27 WHERE
28     hook IN (
29         SELECT key FROM action_trigger.hook WHERE core_type = 'circ'
30     )
31 ;
32
33 UPDATE
34     action_trigger.event_definition
35 SET
36     context_usr_path = 'usr',
37     context_library_path = 'pickup_lib',
38     context_bib_path = 'bib_rec'
39 WHERE
40     hook IN (
41         SELECT key FROM action_trigger.hook WHERE core_type = 'ahr'
42     )
43 ;
44
45 -- Retroactively setting context_user and context_library on existing rows in action_trigger.event:
46 -- This is not done by default because it'll likely take a long time depending on the Evergreen
47 -- installation.  You may want to do this out-of-band with the upgrade if you want to do this at all.
48 --
49 -- \pset format unaligned
50 -- \t
51 -- \o update_action_trigger_events_for_circs.sql
52 -- SELECT 'UPDATE action_trigger.event e SET context_user = c.usr, context_library = c.circ_lib, context_bib = cn.record FROM action.circulation c, asset.copy i, asset.call_number cn WHERE c.id = e.target AND c.target_copy = i.id AND i.call_number = cn.id AND e.id = ' || e.id || ' RETURNING ' || e.id || ';' FROM action_trigger.event e, action.circulation c WHERE e.target = c.id AND e.event_def IN (SELECT id FROM action_trigger.event_definition WHERE hook in (SELECT key FROM action_trigger.hook WHERE core_type = 'circ')) ORDER BY e.id DESC;
53 -- \o
54 -- \o update_action_trigger_events_for_holds.sql
55 -- SELECT 'UPDATE action_trigger.event e SET context_user = h.usr, context_library = h.pickup_lib, context_bib = r.bib_record FROM action.hold_request h, reporter.hold_request_record r WHERE h.id = e.target AND h.id = r.id AND e.id = ' || e.id || ' RETURNING ' || e.id || ';' FROM action_trigger.event e, action.hold_request h WHERE e.target = h.id AND e.event_def IN (SELECT id FROM action_trigger.event_definition WHERE hook in (SELECT key FROM action_trigger.hook WHERE core_type = 'ahr')) ORDER BY e.id DESC;
56 -- \o
57
58 COMMIT;
59