-- These are copy level holds
-- CREATE TABLE legacy_copy_hold_insert AS
INSERT INTO action.hold_request
- (target, current_copy, hold_type, pickup_lib, selection_ou, selection_depth, request_time, capture_time, request_lib, requestor, usr)
- SELECT cp.id AS target,
+ (id, target, current_copy, hold_type, pickup_lib, selection_ou, selection_depth, request_time, capture_time, request_lib, requestor, usr)
+ SELECT lh.hold_key AS id,
cp.id AS target,
+ cp.id AS current_copy,
'C'::TEXT AS hold_type,
pou.id AS pickup_lib,
pou.id AS selection_ou,
-- And these are CN level holds
-- CREATE TABLE legacy_cn_hold_insert AS
INSERT INTO action.hold_request
- (target, current_copy, hold_type, pickup_lib, selection_ou, selection_depth, request_time, capture_time, request_lib, requestor, usr)
- SELECT cp.call_number AS target,
+ (id, target, current_copy, hold_type, pickup_lib, selection_ou, selection_depth, request_time, capture_time, request_lib, requestor, usr)
+ SELECT lh.hold_key AS id,
+ cp.call_number AS target,
cp.id AS current_copy,
'V'::TEXT AS hold_type,
pou.id AS pickup_lib,
-- And these are CN level holds
-- CREATE TABLE legacy_title_hold_insert AS
INSERT INTO action.hold_request
- (target, current_copy, hold_type, pickup_lib, selection_ou, selection_depth, request_time, capture_time, request_lib, requestor, usr)
- SELECT lh.cat_key AS target,
+ (id, target, current_copy, hold_type, pickup_lib, selection_ou, selection_depth, request_time, capture_time, request_lib, requestor, usr)
+ SELECT lh.hold_key AS id,
+ lh.cat_key AS target,
cp.id AS current_copy,
'T'::TEXT AS hold_type,
pou.id AS pickup_lib,
JOIN actor.org_unit pou ON (pou.shortname = lh.pickup_lib)
WHERE lh.hold_level = 'T';
---COMMIT;
+SELECT SETVAL('action.hold_request_id_seq',(SELECT MAX(id) FROM action.hold_request),TRUE);
+
+COMMIT;
--- /dev/null
+BEGIN;
+
+-- hold transit import
+INSERT INTO action.hold_transit_copy (dest, source, source_send_time, target_copy, copy_status, hold)
+ SELECT dou.id AS dest,
+ sou.id AS source,
+ l.transit_date AS source_send_time,
+ cp.id AS target_copy,
+ 8 AS copy_status,
+ h.id AS hold
+ FROM legacy_transit l
+ JOIN action.hold_request h ON (l.hold_key = h.id)
+ JOIN legacy_item li USING (cat_key, call_key, item_key)
+ JOIN asset.copy cp ON (li.item_id = cp.barcode)
+ JOIN actor.org_unit dou ON (l.destination_lib = dou.shortname)
+ JOIN actor.org_unit sou ON (l.starting_lib = sou.shortname)
+ WHERE l.hold_key > 0;
+
+-- normal transits
+INSERT INTO action.transit_copy (dest, source, source_send_time, target_copy, copy_status)
+ SELECT dou.id AS dest,
+ sou.id AS source,
+ l.transit_date AS source_send_time,
+ cp.id AS target_copy,
+ 7 AS copy_status
+ FROM legacy_transit l
+ JOIN legacy_item li USING (cat_key, call_key, item_key)
+ JOIN asset.copy cp ON (li.item_id = cp.barcode)
+ JOIN actor.org_unit dou ON (l.destination_lib = dou.shortname)
+ JOIN actor.org_unit sou ON (l.starting_lib = sou.shortname)
+ WHERE l.hold_key = 0;
+
+COMMIT;