insert holds
authormiker <miker@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Wed, 2 Aug 2006 20:15:12 +0000 (20:15 +0000)
committermiker <miker@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Wed, 2 Aug 2006 20:15:12 +0000 (20:15 +0000)
git-svn-id: svn://svn.open-ils.org/ILS/trunk@5228 dcc99617-32d9-48b4-a31d-7c20da2025e4

Evergreen/src/extras/import/legacy_hold.sql

index d784c5e..dc7fce9 100644 (file)
@@ -1,13 +1,14 @@
 BEGIN;
 
 -- These are copy level holds
-CREATE TABLE legacy_copy_hold_insert AS
-       SELECT  DISTINCT ON (jl.cat_key, jl.call_key, jl.item_key)
-               cp.id AS current_copy,
+-- 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,
                cp.id AS target,
                'C'::TEXT AS hold_type,
                pou.id AS pickup_lib,
-               pou.id AS selection_lib,
+               pou.id AS selection_ou,
                CASE    WHEN lh.hold_range = 'SYSTEM' THEN 0
                        WHEN lh.hold_range = 'GROUP' THEN 1
                        ELSE 2
@@ -20,7 +21,7 @@ CREATE TABLE legacy_copy_hold_insert AS
                au.id AS requestor,
                au.id AS usr
          FROM  legacy_hold lh
-               JOIN joined_legacy jl
+               JOIN legacy_item jl
                        ON (    jl.cat_key = lh.cat_key
                                AND jl.call_key = lh.call_key
                                AND jl.item_key = lh.call_key )
@@ -31,13 +32,14 @@ CREATE TABLE legacy_copy_hold_insert AS
          WHERE lh.hold_level = 'C';
 
 -- And these are CN level holds
-CREATE TABLE legacy_cn_hold_insert AS
-       SELECT  DISTINCT ON (jl.cat_key, jl.call_key, jl.item_key)
+-- 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,
                cp.id AS current_copy,
-               cp.call_number AS target,
                'V'::TEXT AS hold_type,
                pou.id AS pickup_lib,
-               pou.id AS selection_lib,
+               pou.id AS selection_ou,
                CASE    WHEN lh.hold_range = 'SYSTEM' THEN 0
                        WHEN lh.hold_range = 'GROUP' THEN 1
                        ELSE 2
@@ -50,7 +52,7 @@ CREATE TABLE legacy_cn_hold_insert AS
                au.id AS requestor,
                au.id AS usr
          FROM  legacy_hold lh
-               JOIN joined_legacy jl
+               JOIN legacy_item jl
                        ON (    jl.cat_key = lh.cat_key
                                AND jl.call_key = lh.call_key
                                AND jl.item_key = lh.call_key )
@@ -61,13 +63,14 @@ CREATE TABLE legacy_cn_hold_insert AS
          WHERE lh.hold_level = 'A';
 
 -- And these are CN level holds
-CREATE TABLE legacy_title_hold_insert AS
-       SELECT  DISTINCT ON (jl.cat_key, jl.call_key, jl.item_key)
+-- 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,
                cp.id AS current_copy,
-               cn.record AS target,
                'T'::TEXT AS hold_type,
                pou.id AS pickup_lib,
-               pou.id AS selection_lib,
+               pou.id AS selection_ou,
                CASE    WHEN lh.hold_range = 'SYSTEM' THEN 0
                        WHEN lh.hold_range = 'GROUP' THEN 1
                        ELSE 2
@@ -80,12 +83,11 @@ CREATE TABLE legacy_title_hold_insert AS
                au.id AS requestor,
                au.id AS usr
          FROM  legacy_hold lh
-               JOIN joined_legacy jl
+               JOIN legacy_item jl
                        ON (    jl.cat_key = lh.cat_key
                                AND jl.call_key = lh.call_key
                                AND jl.item_key = lh.call_key )
                JOIN asset.copy cp ON (cp.barcode = jl.item_id)
-               JOIN asset.call_number cn ON (cp.call_number = cn.id)
                JOIN actor.usr au ON (au.id = lh.user_key)
                JOIN actor.org_unit rou ON (rou.shortname = lh.placing_lib)
                JOIN actor.org_unit pou ON (pou.shortname = lh.pickup_lib)