From bc0cbd58919fd683936bcf0f4b36c4505836e41b Mon Sep 17 00:00:00 2001
From: scottmk <scottmk@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Date: Tue, 25 May 2010 17:53:43 +0000
Subject: [PATCH] Correcting an upgrade script.

The value column in actor.org_unit_setting should be valid JSON.  In this
revised version the new value is jiggered to make it a string instead of a
number.  This conversion is a bit simplistic and can be defeated by various
kinds of improbable input.

M    Open-ILS/src/sql/Pg/upgrade/0274.data.org-setting-type-est-wait.sql


git-svn-id: svn://svn.open-ils.org/ILS/trunk@16496 dcc99617-32d9-48b4-a31d-7c20da2025e4
---
 .../sql/Pg/upgrade/0274.data.org-setting-type-est-wait.sql   | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)

diff --git a/Open-ILS/src/sql/Pg/upgrade/0274.data.org-setting-type-est-wait.sql b/Open-ILS/src/sql/Pg/upgrade/0274.data.org-setting-type-est-wait.sql
index f1c02adae7..85aef37e21 100644
--- a/Open-ILS/src/sql/Pg/upgrade/0274.data.org-setting-type-est-wait.sql
+++ b/Open-ILS/src/sql/Pg/upgrade/0274.data.org-setting-type-est-wait.sql
@@ -11,7 +11,17 @@ WHERE name = 'circ.hold_estimate_wait_interval';
 
 UPDATE actor.org_unit_setting SET
 	name = 'circ.holds.default_estimated_wait_interval',
-	value = value || ' days'
+	--
+	-- The value column should be JSON.  The old value should be a number,
+	-- but it may or may not be quoted.  The following CASE behaves
+	-- differently depending on whether value is quoted.  It is simplistic,
+	-- and will be defeated by leading or trailing white space, or various
+	-- malformations.
+	--
+	value = CASE WHEN SUBSTR( value, 1, 1 ) = '"'
+				THEN '"' || SUBSTR( value, 2, LENGTH(value) - 2 ) || ' days"'
+				ELSE '"' || value || ' days"'
+			END
 WHERE name = 'circ.hold_estimate_wait_interval';
 
 INSERT INTO config.org_unit_setting_type (
-- 
2.11.0