LP#1281744 Aged hold purging column repair
authorBill Erickson <berick@esilibrary.com>
Tue, 18 Feb 2014 19:16:40 +0000 (14:16 -0500)
committerDan Wells <dbw2@calvin.edu>
Fri, 21 Feb 2014 21:33:10 +0000 (16:33 -0500)
Add missing non-NULLable "behind_desk" column to
action.all_hold_request, which is used during holds deletion and
archiving.

Signed-off-by: Bill Erickson <berick@esilibrary.com>
Signed-off-by: Dan Wells <dbw2@calvin.edu>
Open-ILS/examples/fm_IDL.xml
Open-ILS/src/sql/Pg/090.schema.action.sql
Open-ILS/src/sql/Pg/upgrade/XXXX.schema.all_hold_behind_desk.sql [new file with mode: 0644]

index e86ee9c..adfcd2e 100644 (file)
@@ -5628,6 +5628,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="Current Shelf Lib" name="current_shelf_lib" reporter:datatype="org_unit"/>
+                       <field reporter:label="Behind Desk" name="behind_desk" reporter:datatype="bool"/>
                </fields>
                <links>
                        <link field="fulfillment_lib" reltype="has_a" key="id" map="" class="aou"/>
index 6ab9ab4..35ab53b 100644 (file)
@@ -587,7 +587,8 @@ CREATE OR REPLACE VIEW action.all_hold_request AS
            ahr.cut_in_line,
            ahr.mint_condition,
            ahr.shelf_expire_time,
-           ahr.current_shelf_lib
+           ahr.current_shelf_lib,
+           ahr.behind_desk
     FROM action.hold_request ahr
          JOIN actor.usr p ON (ahr.usr = p.id)
          LEFT JOIN actor.usr_address a ON (p.mailing_address = a.id)
@@ -629,7 +630,8 @@ CREATE OR REPLACE VIEW action.all_hold_request AS
            cut_in_line,
            mint_condition,
            shelf_expire_time,
-           current_shelf_lib
+           current_shelf_lib,
+           behind_desk
     FROM action.aged_hold_request;
 
 CREATE OR REPLACE FUNCTION action.age_hold_on_delete () RETURNS TRIGGER AS $$
@@ -673,7 +675,8 @@ BEGIN
             cut_in_line,
             mint_condition,
             shelf_expire_time,
-            current_shelf_lib)
+            current_shelf_lib,
+            behind_desk)
       SELECT 
            usr_post_code,
            usr_home_ou,
@@ -710,7 +713,8 @@ BEGIN
            cut_in_line,
            mint_condition,
            shelf_expire_time,
-           current_shelf_lib
+           current_shelf_lib,
+           behind_desk
         FROM action.all_hold_request WHERE id = OLD.id;
 
     RETURN OLD;
diff --git a/Open-ILS/src/sql/Pg/upgrade/XXXX.schema.all_hold_behind_desk.sql b/Open-ILS/src/sql/Pg/upgrade/XXXX.schema.all_hold_behind_desk.sql
new file mode 100644 (file)
index 0000000..c2c6e95
--- /dev/null
@@ -0,0 +1,187 @@
+-- add missing behind_desk column
+
+BEGIN;
+
+CREATE OR REPLACE VIEW action.all_hold_request AS
+    SELECT DISTINCT
+           COALESCE(a.post_code, b.post_code) AS usr_post_code,
+           p.home_ou AS usr_home_ou,
+           p.profile AS usr_profile,
+           EXTRACT(YEAR FROM p.dob)::INT AS usr_birth_year,
+           CAST(ahr.requestor <> ahr.usr AS BOOLEAN) AS staff_placed,
+           ahr.id,
+           ahr.request_time,
+           ahr.capture_time,
+           ahr.fulfillment_time,
+           ahr.checkin_time,
+           ahr.return_time,
+           ahr.prev_check_time,
+           ahr.expire_time,
+           ahr.cancel_time,
+           ahr.cancel_cause,
+           ahr.cancel_note,
+           ahr.target,
+           ahr.current_copy,
+           ahr.fulfillment_staff,
+           ahr.fulfillment_lib,
+           ahr.request_lib,
+           ahr.selection_ou,
+           ahr.selection_depth,
+           ahr.pickup_lib,
+           ahr.hold_type,
+           ahr.holdable_formats,
+           CASE
+           WHEN ahr.phone_notify IS NULL THEN FALSE
+           WHEN ahr.phone_notify = '' THEN FALSE
+           ELSE TRUE
+           END AS phone_notify,
+           ahr.email_notify,
+           CASE
+           WHEN ahr.sms_notify IS NULL THEN FALSE
+           WHEN ahr.sms_notify = '' THEN FALSE
+           ELSE TRUE
+           END AS sms_notify,
+           ahr.frozen,
+           ahr.thaw_date,
+           ahr.shelf_time,
+           ahr.cut_in_line,
+           ahr.mint_condition,
+           ahr.shelf_expire_time,
+           ahr.current_shelf_lib,
+           ahr.behind_desk
+    FROM action.hold_request ahr
+         JOIN actor.usr p ON (ahr.usr = p.id)
+         LEFT JOIN actor.usr_address a ON (p.mailing_address = a.id)
+         LEFT JOIN actor.usr_address b ON (p.billing_address = b.id)
+    UNION ALL
+    SELECT 
+           usr_post_code,
+           usr_home_ou,
+           usr_profile,
+           usr_birth_year,
+           staff_placed,
+           id,
+           request_time,
+           capture_time,
+           fulfillment_time,
+           checkin_time,
+           return_time,
+           prev_check_time,
+           expire_time,
+           cancel_time,
+           cancel_cause,
+           cancel_note,
+           target,
+           current_copy,
+           fulfillment_staff,
+           fulfillment_lib,
+           request_lib,
+           selection_ou,
+           selection_depth,
+           pickup_lib,
+           hold_type,
+           holdable_formats,
+           phone_notify,
+           email_notify,
+           sms_notify,
+           frozen,
+           thaw_date,
+           shelf_time,
+           cut_in_line,
+           mint_condition,
+           shelf_expire_time,
+           current_shelf_lib,
+           behind_desk
+    FROM action.aged_hold_request;
+
+
+
+CREATE OR REPLACE FUNCTION action.age_hold_on_delete () RETURNS TRIGGER AS $$
+DECLARE
+BEGIN
+    -- Archive a copy of the old row to action.aged_hold_request
+
+    INSERT INTO action.aged_hold_request
+           (usr_post_code,
+            usr_home_ou,
+            usr_profile,
+            usr_birth_year,
+            staff_placed,
+            id,
+            request_time,
+            capture_time,
+            fulfillment_time,
+            checkin_time,
+            return_time,
+            prev_check_time,
+            expire_time,
+            cancel_time,
+            cancel_cause,
+            cancel_note,
+            target,
+            current_copy,
+            fulfillment_staff,
+            fulfillment_lib,
+            request_lib,
+            selection_ou,
+            selection_depth,
+            pickup_lib,
+            hold_type,
+            holdable_formats,
+            phone_notify,
+            email_notify,
+            sms_notify,
+            frozen,
+            thaw_date,
+            shelf_time,
+            cut_in_line,
+            mint_condition,
+            shelf_expire_time,
+            current_shelf_lib,
+            behind_desk)
+      SELECT 
+           usr_post_code,
+           usr_home_ou,
+           usr_profile,
+           usr_birth_year,
+           staff_placed,
+           id,
+           request_time,
+           capture_time,
+           fulfillment_time,
+           checkin_time,
+           return_time,
+           prev_check_time,
+           expire_time,
+           cancel_time,
+           cancel_cause,
+           cancel_note,
+           target,
+           current_copy,
+           fulfillment_staff,
+           fulfillment_lib,
+           request_lib,
+           selection_ou,
+           selection_depth,
+           pickup_lib,
+           hold_type,
+           holdable_formats,
+           phone_notify,
+           email_notify,
+           sms_notify,
+           frozen,
+           thaw_date,
+           shelf_time,
+           cut_in_line,
+           mint_condition,
+           shelf_expire_time,
+           current_shelf_lib,
+           behind_desk
+        FROM action.all_hold_request WHERE id = OLD.id;
+
+    RETURN OLD;
+END;
+$$ LANGUAGE 'plpgsql';
+
+COMMIT;
+