[open-ils-commits] r16847 - trunk/Open-ILS/src/sql/Pg/upgrade (senator)

svn at svn.open-ils.org svn at svn.open-ils.org
Tue Jul 6 09:45:01 EDT 2010


Author: senator
Date: 2010-07-06 09:44:59 -0400 (Tue, 06 Jul 2010)
New Revision: 16847

Modified:
   trunk/Open-ILS/src/sql/Pg/upgrade/0323.data.booking.elbow_room.sql
Log:
Booking: fixed the last db upgrade script.  It was trying to insert a row
in config.org_unit_setting_type that had already been covered by 0109, but
which had not been in the seed data until recently, so I think one would have
only noticed this if hadn't installed a new schema from scratch in some time.

If you already ran 0323 and it worked for you, you don't have to do anything.

Also, this now avoids clobbering already-set default_elbow_room values.


Modified: trunk/Open-ILS/src/sql/Pg/upgrade/0323.data.booking.elbow_room.sql
===================================================================
--- trunk/Open-ILS/src/sql/Pg/upgrade/0323.data.booking.elbow_room.sql	2010-07-02 19:41:43 UTC (rev 16846)
+++ trunk/Open-ILS/src/sql/Pg/upgrade/0323.data.booking.elbow_room.sql	2010-07-06 13:44:59 UTC (rev 16847)
@@ -1,13 +1,8 @@
-BEGIN;
-
-INSERT INTO config.upgrade_log (version) VALUES ('0323'); -- senator
-
--- In booking, elbow room defines:
---  a) how far in the future you must make a reservation on a given item if
---      that item will have to transit somewhere to fulfill the reservation.
---  b) how soon a reservation must be starting for the reserved item to
---      be op-captured by the checkin interface.
-
+-- This statement ok to fail if the row is already there in coust. You will
+-- already have this if you have a
+-- very old trunk installation (because this has been added by an earlier
+-- upgrade script (0109), but has not been in the default seed data until
+-- recently
 INSERT INTO config.org_unit_setting_type
     (name, label, description, datatype) VALUES (
         'circ.booking_reservation.default_elbow_room',
@@ -26,10 +21,35 @@
         'interval'
     );
 
-INSERT INTO actor.org_unit_setting (org_unit, name, value) VALUES (
-    (SELECT id FROM actor.org_unit WHERE parent_ou IS NULL),
-    'circ.booking_reservation.default_elbow_room',
-    '"1 day"'
-);
+BEGIN;
 
+INSERT INTO config.upgrade_log (version) VALUES ('0323'); -- senator
+
+-- In booking, elbow room defines:
+--  a) how far in the future you must make a reservation on a given item if
+--      that item will have to transit somewhere to fulfill the reservation.
+--  b) how soon a reservation must be starting for the reserved item to
+--      be op-captured by the checkin interface.
+
+-- We don't want to clobber any default_elbow room at any level:
+
+CREATE OR REPLACE FUNCTION pg_temp.default_elbow() RETURNS INTEGER AS $$
+DECLARE
+    existing    actor.org_unit_setting%ROWTYPE;
+BEGIN
+    SELECT INTO existing id FROM actor.org_unit_setting WHERE name = 'circ.booking_reservation.default_elbow_room';
+    IF NOT FOUND THEN
+        INSERT INTO actor.org_unit_setting (org_unit, name, value) VALUES (
+            (SELECT id FROM actor.org_unit WHERE parent_ou IS NULL),
+            'circ.booking_reservation.default_elbow_room',
+            '"1 day"'
+        );
+        RETURN 1;
+    END IF;
+    RETURN 0;
+END;
+$$ LANGUAGE plpgsql;
+
+SELECT pg_temp.default_elbow();
+
 COMMIT;



More information about the open-ils-commits mailing list