[open-ils-commits] r19043 - in trunk/Open-ILS/src/sql/Pg: . upgrade (miker)
svn at svn.open-ils.org
svn at svn.open-ils.org
Wed Dec 22 20:27:31 EST 2010
Author: miker
Date: 2010-12-22 20:27:30 -0500 (Wed, 22 Dec 2010)
New Revision: 19043
Added:
trunk/Open-ILS/src/sql/Pg/upgrade/0473.schema.vandelay-replace_field.sql
Modified:
trunk/Open-ILS/src/sql/Pg/002.schema.config.sql
trunk/Open-ILS/src/sql/Pg/012.schema.vandelay.sql
trunk/Open-ILS/src/sql/Pg/1.6.1-2.0-upgrade-db.sql
Log:
allow vandelay.replace_field() to handle a complex field spec by splitting and looping; bringing 1.6.1-2.0 upgrade script up to date
Modified: trunk/Open-ILS/src/sql/Pg/002.schema.config.sql
===================================================================
--- trunk/Open-ILS/src/sql/Pg/002.schema.config.sql 2010-12-22 17:05:11 UTC (rev 19042)
+++ trunk/Open-ILS/src/sql/Pg/002.schema.config.sql 2010-12-23 01:27:30 UTC (rev 19043)
@@ -70,7 +70,7 @@
install_date TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW()
);
-INSERT INTO config.upgrade_log (version) VALUES ('0472'); -- dbs
+INSERT INTO config.upgrade_log (version) VALUES ('0473'); -- miker
CREATE TABLE config.bib_source (
id SERIAL PRIMARY KEY,
Modified: trunk/Open-ILS/src/sql/Pg/012.schema.vandelay.sql
===================================================================
--- trunk/Open-ILS/src/sql/Pg/012.schema.vandelay.sql 2010-12-22 17:05:11 UTC (rev 19042)
+++ trunk/Open-ILS/src/sql/Pg/012.schema.vandelay.sql 2010-12-23 01:27:30 UTC (rev 19043)
@@ -445,18 +445,27 @@
DECLARE
xml_output TEXT;
parsed_target TEXT;
+ curr_field TEXT;
BEGIN
- parsed_target := vandelay.strip_field( target_xml, ''); -- this dance normalized the format of the xml for the IF below
- xml_output := vandelay.strip_field( parsed_target, field);
- IF xml_output <> parsed_target AND field ~ E'~' THEN
- -- we removed something, and there was a regexp restriction in the field definition, so proceed
- xml_output := vandelay.add_field( xml_output, source_xml, field, 1 );
- ELSIF field !~ E'~' THEN
- -- No regexp restriction, add the field
- xml_output := vandelay.add_field( xml_output, source_xml, field, 0 );
- END IF;
+ parsed_target := vandelay.strip_field( target_xml, ''); -- this dance normalizes the format of the xml for the IF below
+ FOR curr_field IN SELECT UNNEST( STRING_TO_ARRAY(field, ',') ) LOOP -- naive split, but it's the same we use in the perl
+
+ xml_output := vandelay.strip_field( parsed_target, curr_field);
+
+ IF xml_output <> parsed_target AND curr_field ~ E'~' THEN
+ -- we removed something, and there was a regexp restriction in the curr_field definition, so proceed
+ xml_output := vandelay.add_field( xml_output, source_xml, curr_field, 1 );
+ ELSIF curr_field !~ E'~' THEN
+ -- No regexp restriction, add the curr_field
+ xml_output := vandelay.add_field( xml_output, source_xml, curr_field, 0 );
+ END IF;
+
+ parsed_target := xml_output; -- in prep for any following loop iterations
+
+ END LOOP;
+
RETURN xml_output;
END;
$_$ LANGUAGE PLPGSQL;
Modified: trunk/Open-ILS/src/sql/Pg/1.6.1-2.0-upgrade-db.sql
===================================================================
--- trunk/Open-ILS/src/sql/Pg/1.6.1-2.0-upgrade-db.sql 2010-12-22 17:05:11 UTC (rev 19042)
+++ trunk/Open-ILS/src/sql/Pg/1.6.1-2.0-upgrade-db.sql 2010-12-23 01:27:30 UTC (rev 19043)
@@ -31,7 +31,7 @@
-- Highest-numbered individual upgrade script incorporated herein:
-INSERT INTO config.upgrade_log (version) VALUES ('0469');
+INSERT INTO config.upgrade_log (version) VALUES ('0473');
-- Push the auri sequence in case it's out of date
-- Add 2 as the sequence value must be 1 or higher, and seed is -1
@@ -6383,7 +6383,7 @@
SELECT DISTINCT ON (hard_due_date) *
FROM config.hard_due_date_values
WHERE active_date <= NOW() -- We've passed (or are at) the rollover time
- ORDER BY active_date DESC -- Latest (nearest to us) active time
+ ORDER BY hard_due_date, active_date DESC -- Latest (nearest to us) active time
LOOP
UPDATE config.hard_due_date
SET ceiling_date = temp_value.ceiling_date
@@ -14218,18 +14218,27 @@
DECLARE
xml_output TEXT;
parsed_target TEXT;
+ curr_field TEXT;
BEGIN
- parsed_target := vandelay.strip_field( target_xml, ''); -- this dance normalized the format of the xml for the IF below
- xml_output := vandelay.strip_field( parsed_target, field);
- IF xml_output <> parsed_target AND field ~ E'~' THEN
- -- we removed something, and there was a regexp restriction in the field definition, so proceed
- xml_output := vandelay.add_field( xml_output, source_xml, field, 1 );
- ELSIF field !~ E'~' THEN
- -- No regexp restriction, add the field
- xml_output := vandelay.add_field( xml_output, source_xml, field, 0 );
- END IF;
+ parsed_target := vandelay.strip_field( target_xml, ''); -- this dance normalizes the format of the xml for the IF below
+ FOR curr_field IN SELECT UNNEST( STRING_TO_ARRAY(field, ',') ) LOOP -- naive split, but it's the same we use in the perl
+
+ xml_output := vandelay.strip_field( parsed_target, curr_field);
+
+ IF xml_output <> parsed_target AND curr_field ~ E'~' THEN
+ -- we removed something, and there was a regexp restriction in the curr_field definition, so proceed
+ xml_output := vandelay.add_field( xml_output, source_xml, curr_field, 1 );
+ ELSIF curr_field !~ E'~' THEN
+ -- No regexp restriction, add the curr_field
+ xml_output := vandelay.add_field( xml_output, source_xml, curr_field, 0 );
+ END IF;
+
+ parsed_target := xml_output; -- in prep for any following loop iterations
+
+ END LOOP;
+
RETURN xml_output;
END;
$_$ LANGUAGE PLPGSQL;
Added: trunk/Open-ILS/src/sql/Pg/upgrade/0473.schema.vandelay-replace_field.sql
===================================================================
--- trunk/Open-ILS/src/sql/Pg/upgrade/0473.schema.vandelay-replace_field.sql (rev 0)
+++ trunk/Open-ILS/src/sql/Pg/upgrade/0473.schema.vandelay-replace_field.sql 2010-12-23 01:27:30 UTC (rev 19043)
@@ -0,0 +1,35 @@
+
+BEGIN;
+
+INSERT INTO config.upgrade_log (version) VALUES ('0473'); -- miker
+
+CREATE OR REPLACE FUNCTION vandelay.replace_field ( target_xml TEXT, source_xml TEXT, field TEXT ) RETURNS TEXT AS $_$
+DECLARE
+ xml_output TEXT;
+ parsed_target TEXT;
+ curr_field TEXT;
+BEGIN
+
+ parsed_target := vandelay.strip_field( target_xml, ''); -- this dance normalizes the format of the xml for the IF below
+
+ FOR curr_field IN SELECT UNNEST( STRING_TO_ARRAY(field, ',') ) LOOP -- naive split, but it's the same we use in the perl
+
+ xml_output := vandelay.strip_field( parsed_target, curr_field);
+
+ IF xml_output <> parsed_target AND curr_field ~ E'~' THEN
+ -- we removed something, and there was a regexp restriction in the curr_field definition, so proceed
+ xml_output := vandelay.add_field( xml_output, source_xml, curr_field, 1 );
+ ELSIF curr_field !~ E'~' THEN
+ -- No regexp restriction, add the curr_field
+ xml_output := vandelay.add_field( xml_output, source_xml, curr_field, 0 );
+ END IF;
+
+ parsed_target := xml_output; -- in prep for any following loop iterations
+
+ END LOOP;
+
+ RETURN xml_output;
+END;
+$_$ LANGUAGE PLPGSQL;
+
+COMMIT;
More information about the open-ils-commits
mailing list