Hold current_shelf_lib DB and IDL
authorBill Erickson <berick@esilibrary.com>
Tue, 27 Dec 2011 17:19:05 +0000 (12:19 -0500)
committerBill Erickson <berick@esilibrary.com>
Wed, 4 Jan 2012 19:40:00 +0000 (14:40 -0500)
Schema, upgrade, and IDL pieces for a new
action.hold_request.current_shelf_lib column.  The goal of the column is
to track the location where a hold is currently sitting on a hold shelf.
Typically, this will be the pickup library, however, if the pickup
library has changed while the hold was on the shelf, the current shelf
lib will be different.

The upgrade script sets current_shelf_lib to match the pickup_lib for
all holds that are currently active and on the shelf.

Signed-off-by: Bill Erickson <berick@esilibrary.com>
Open-ILS/examples/fm_IDL.xml
Open-ILS/src/sql/Pg/090.schema.action.sql
Open-ILS/src/sql/Pg/upgrade/XXXX.schema.hold-current-shelf-lib.sql [new file with mode: 0644]

index 7e0b301..42807fd 100644 (file)
@@ -4520,6 +4520,7 @@ SELECT  usr,
                        <field reporter:label="Is Mint Condition" name="mint_condition" reporter:datatype="bool" />
                        <field reporter:label="Shelf Expire Time" name="shelf_expire_time" reporter:datatype="timestamp"/>
                        <field reporter:label="Notes" name="notes" reporter:datatype="link" oils_persist:virtual="true"/>
+                       <field reporter:label="Current Shelf Lib" name="current_shelf_lib" reporter:datatype="org_unit"/>
                </fields>
                <links>
                        <link field="fulfillment_lib" reltype="has_a" key="id" map="" class="aou"/>
@@ -4536,6 +4537,7 @@ SELECT  usr,
                        <link field="bib_rec" reltype="might_have" key="id" map="" class="rhrr"/>
                        <link field="cancel_cause" reltype="might_have" key="id" map="" class="ahrcc"/>
                        <link field="notes" reltype="has_many" key="hold" map="" class="ahrn"/>
+                       <link field="current_shelf_lib" reltype="has_a" key="id" map="" class="aou"/>
                </links>
        </class>
        <class id="alhr" controller="open-ils.cstore" oils_obj:fieldmapper="action::last_hold_request" reporter:label="Last Captured Hold Request" oils_persist:readonly="true">
@@ -4580,6 +4582,7 @@ SELECT  usr,
                        <field reporter:label="Is Mint Condition" name="mint_condition" reporter:datatype="bool" />
                        <field reporter:label="Shelf Expire Time" name="shelf_expire_time" reporter:datatype="timestamp"/>
                        <field reporter:label="Notes" name="notes" reporter:datatype="link" oils_persist:virtual="true"/>
+                       <field reporter:label="Current Shelf Lib" name="current_shelf_lib" reporter:datatype="org_unit"/>
                </fields>
                <links>
                        <link field="fulfillment_lib" reltype="has_a" key="id" map="" class="aou"/>
@@ -4596,6 +4599,7 @@ SELECT  usr,
                        <link field="bib_rec" reltype="might_have" key="id" map="" class="rhrr"/>
                        <link field="cancel_cause" reltype="might_have" key="id" map="" class="ahrcc"/>
                        <link field="notes" reltype="has_many" key="hold" map="" class="ahrn"/>
+                       <link field="current_shelf_lib" reltype="has_a" key="id" map="" class="aou"/>
                </links>
        </class>
 
index 05c45ad..111b53d 100644 (file)
@@ -357,7 +357,8 @@ CREATE TABLE action.hold_request (
        shelf_time              TIMESTAMP WITH TIME ZONE,
     cut_in_line     BOOL,
        mint_condition  BOOL NOT NULL DEFAULT TRUE,
-       shelf_expire_time TIMESTAMPTZ
+       shelf_expire_time TIMESTAMPTZ,
+       current_shelf_lib INT REFERENCES actor.org_unit DEFERRABLE INITIALLY DEFERRED
 );
 
 CREATE INDEX hold_request_target_idx ON action.hold_request (target);
diff --git a/Open-ILS/src/sql/Pg/upgrade/XXXX.schema.hold-current-shelf-lib.sql b/Open-ILS/src/sql/Pg/upgrade/XXXX.schema.hold-current-shelf-lib.sql
new file mode 100644 (file)
index 0000000..cec449c
--- /dev/null
@@ -0,0 +1,28 @@
+-- Evergreen DB patch XXXX.schema.hold-current-shelf-lib.sql
+--
+-- FIXME: insert description of change, if needed
+--
+BEGIN;
+
+
+-- check whether patch can be applied
+SELECT evergreen.upgrade_deps_block_check('XXXX', :eg_version);
+
+-- add the new column
+ALTER TABLE action.hold_request ADD COLUMN current_shelf_lib 
+    INT REFERENCES actor.org_unit DEFERRABLE INITIALLY DEFERRED;
+
+-- set the value for current_shelf_lib on existing shelved holds
+UPDATE action.hold_request ahr
+    SET current_shelf_lib = pickup_lib
+    FROM asset.copy acp
+    WHERE 
+            ahr.shelf_time IS NOT NULL 
+        AND ahr.capture_time IS NOT NULL
+        AND ahr.current_copy IS NOT NULL
+        AND ahr.fulfillment_time IS NULL
+        AND ahr.cancel_time IS NULL
+        AND acp.id = ahr.current_copy
+        AND acp.status = 8; -- on holds shelf
+
+COMMIT;