Add ISSN fix to the version upgrade script
authorMike Rylander <mrylander@gmail.com>
Mon, 26 Mar 2012 15:09:14 +0000 (11:09 -0400)
committerDan Scott <dscott@laurentian.ca>
Thu, 3 May 2012 20:47:08 +0000 (16:47 -0400)
Signed-off-by: Mike Rylander <mrylander@gmail.com>
Signed-off-by: Dan Scott <dscott@laurentian.ca>

Open-ILS/src/sql/Pg/version-upgrade/2.1.1-2.1.2-upgrade-db.sql

index 70777a1..6c891d6 100644 (file)
@@ -116,3 +116,27 @@ BEGIN
 END;
 $func$ LANGUAGE PLPGSQL;
 
+INSERT INTO config.upgrade_log (version) VALUES ('0693');
+
+-- Delete the index normalizer that was meant to remove spaces from ISSNs
+-- but ended up breaking records with multiple ISSNs
+DELETE FROM config.metabib_field_index_norm_map WHERE id IN (
+    SELECT map.id FROM config.metabib_field_index_norm_map map
+        INNER JOIN config.metabib_field cmf ON cmf.id = map.field
+        INNER JOIN config.index_normalizer cin ON cin.id = map.norm
+    WHERE cin.func = 'replace'
+        AND cmf.field_class = 'identifier'
+        AND cmf.name = 'issn'
+        AND map.params = $$[" ",""]$$
+);
+
+-- Reindex records that have more than just a single ISSN
+-- to ensure that spaces are maintained
+SELECT metabib.reingest_metabib_field_entries(source)
+  FROM metabib.identifier_field_entry mife
+    INNER JOIN config.metabib_field cmf ON cmf.id = mife.field
+  WHERE cmf.field_class = 'identifier'
+    AND cmf.name = 'issn'
+    AND char_length(value) > 9
+;
+