]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/src/sql/Pg/upgrade/0139.schema.vandelay-item-import-fix.sql
LP#1564079 Checkout history skips nonexistent items
[Evergreen.git] / Open-ILS / src / sql / Pg / upgrade / 0139.schema.vandelay-item-import-fix.sql
1
2 BEGIN;
3
4 INSERT INTO config.upgrade_log (version) VALUES ('0139'); -- Dan Wells via miker
5
6 CREATE OR REPLACE FUNCTION vandelay.ingest_bib_items ( ) RETURNS TRIGGER AS $func$
7 DECLARE
8     attr_def    BIGINT;
9     item_data   vandelay.import_item%ROWTYPE;
10 BEGIN
11
12     SELECT item_attr_def INTO attr_def FROM vandelay.bib_queue WHERE id = NEW.queue;
13
14     FOR item_data IN SELECT * FROM vandelay.ingest_items( NEW.id::BIGINT, attr_def ) LOOP
15         INSERT INTO vandelay.import_item (
16             record,
17             definition,
18             owning_lib,
19             circ_lib,
20             call_number,
21             copy_number,
22             status,
23             location,
24             circulate,
25             deposit,
26             deposit_amount,
27             ref,
28             holdable,
29             price,
30             barcode,
31             circ_modifier,
32             circ_as_type,
33             alert_message,
34             pub_note,
35             priv_note,
36             opac_visible
37         ) VALUES (
38             NEW.id,
39             item_data.definition,
40             item_data.owning_lib,
41             item_data.circ_lib,
42             item_data.call_number,
43             item_data.copy_number,
44             item_data.status,
45             item_data.location,
46             item_data.circulate,
47             item_data.deposit,
48             item_data.deposit_amount,
49             item_data.ref,
50             item_data.holdable,
51             item_data.price,
52             item_data.barcode,
53             item_data.circ_modifier,
54             item_data.circ_as_type,
55             item_data.alert_message,
56             item_data.pub_note,
57             item_data.priv_note,
58             item_data.opac_visible
59         );
60     END LOOP;
61
62     RETURN NULL;
63 END;
64 $func$ LANGUAGE PLPGSQL;
65
66 COMMIT;