LP#1272074 Fix faulty physical characteristics seed data
authorLebbeous Fogle-Weekley <lebbeous@esilibrary.com>
Mon, 18 Nov 2013 17:31:47 +0000 (12:31 -0500)
committerDan Wells <dbw2@calvin.edu>
Tue, 18 Feb 2014 17:03:56 +0000 (12:03 -0500)
For 007 (00/a=f), "subfield" e (Level of contraction) starts at position
5, not 4.

Signed-off-by: Lebbeous Fogle-Weekley <lebbeous@esilibrary.com>
Signed-off-by: Dan Wells <dbw2@calvin.edu>
Open-ILS/src/sql/Pg/950.data.seed-values.sql
Open-ILS/src/sql/Pg/live_t/XXXX.fixed_field_enhancements.pg [new file with mode: 0644]
Open-ILS/src/sql/Pg/upgrade/XXXX.data.fixed_field_enhancements.sql [new file with mode: 0644]

index 2f8f839..3ea7b94 100644 (file)
@@ -5291,7 +5291,7 @@ INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfiel
 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('n',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Not applicable');
 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('u',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Unknown');
 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('z',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Other');
-INSERT INTO config.marc21_physical_characteristic_subfield_map (ptype_key,subfield,start_pos,length,label) VALUES ('f','e','4','1','Level of contraction');
+INSERT INTO config.marc21_physical_characteristic_subfield_map (ptype_key,subfield,start_pos,length,label) VALUES ('f','e','5','1','Level of contraction');
 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('a',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Uncontracted');
 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('b',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Contracted');
 INSERT INTO config.marc21_physical_characteristic_value_map (value,ptype_subfield,label) VALUES ('m',CURRVAL('config.marc21_physical_characteristic_subfield_map_id_seq'),'Combination');
diff --git a/Open-ILS/src/sql/Pg/live_t/XXXX.fixed_field_enhancements.pg b/Open-ILS/src/sql/Pg/live_t/XXXX.fixed_field_enhancements.pg
new file mode 100644 (file)
index 0000000..d48c4a0
--- /dev/null
@@ -0,0 +1,65 @@
+\set ECHO
+\set QUIET 1
+-- Turn off echo and keep things quiet.
+
+-- Format the output for nice TAP.
+\pset format unaligned
+\pset tuples_only true
+\pset pager
+
+-- Revert all changes on failure.
+\set ON_ERROR_ROLLBACK 1
+\set ON_ERROR_STOP true
+\set QUIET 1
+
+-- let's do this thing
+BEGIN;
+
+SELECT plan(1);
+
+CREATE OR REPLACE FUNCTION pg_temp.test_phys_char_no_overlaps() RETURNS BOOL AS $$
+DECLARE
+    ptype   TEXT;
+    str     TEXT;
+    subf    RECORD;
+    gap     INT;
+BEGIN
+    FOR ptype IN
+        SELECT ptype_key FROM config.marc21_physical_characteristic_type_map
+    LOOP
+        str := ptype;
+
+        FOR subf IN
+            SELECT subfield, start_pos, length
+            FROM config.marc21_physical_characteristic_subfield_map
+            WHERE ptype_key = ptype
+            ORDER BY subfield
+        LOOP
+            gap := subf.start_pos - LENGTH(str);
+            IF gap > 0 THEN
+                str := str || REPEAT(' ', gap);
+            ELSIF gap < 0 THEN
+                -- This is a WARNING instead of an ERROR just so we can
+                -- fail the test nicely. But it really is an error.
+                RAISE WARNING 'subfield % for ptype % backs up!',
+                    ptype, subf.subfield;
+                RETURN FALSE;
+            END IF;
+            str := str || REPEAT('|', subf.length);
+        END LOOP;
+        -- RAISE DEBUG '%', str;
+    END LOOP;
+
+    RETURN TRUE;
+END;
+$$ LANGUAGE PLPGSQL;
+
+SELECT is(
+    pg_temp.test_phys_char_no_overlaps(),
+    TRUE,
+    'Ensure that no set of subfields for a given Physical Characteristics ''type'' (00/a) contains any overlaps.'
+);
+
+SELECT * FROM finish();
+ROLLBACK;
+
diff --git a/Open-ILS/src/sql/Pg/upgrade/XXXX.data.fixed_field_enhancements.sql b/Open-ILS/src/sql/Pg/upgrade/XXXX.data.fixed_field_enhancements.sql
new file mode 100644 (file)
index 0000000..2128422
--- /dev/null
@@ -0,0 +1,11 @@
+BEGIN;
+
+-- SELECT evergreen.upgrade_deps_block_check('XXXX', :eg_version);
+
+-- Fix faulty seed data. Otherwise for ptype 'f' we have subfield 'e'
+-- overlapping subfield 'd'
+UPDATE config.marc21_physical_characteristic_subfield_map
+    SET start_pos = 5
+    WHERE ptype_key = 'f' AND subfield = 'e';
+
+COMMIT;