LP#1414112: Seed data and avoid reingest
authorMike Rylander <mrylander@gmail.com>
Mon, 26 Jan 2015 16:44:45 +0000 (11:44 -0500)
committerBen Shum <bshum@biblio.org>
Tue, 3 Feb 2015 20:52:48 +0000 (15:52 -0500)
Update search metadata without a reingest by identifying records that
use a space in the audience field, and be sure that the coded value map
has a space for "uncoded" audience.

Signed-off-by: Mike Rylander <mrylander@gmail.com>
Signed-off-by: Ben Shum <bshum@biblio.org>
Open-ILS/src/sql/Pg/upgrade/XXXX.schema.allow_spaces_as_ff_attr_values.sql

index efe55cb..94aef86 100644 (file)
@@ -8,6 +8,31 @@ BEGIN;
 -- check whether patch can be applied
 SELECT evergreen.upgrade_deps_block_check('XXXX', :eg_version);
 
+-- The code for "uncoded" audience is a space, but upgraded DBs may have a blank.
+UPDATE  config.coded_value_map
+  SET   code = ' '
+  WHERE ctype = 'audience'
+        AND code = ''
+        AND (
+          SELECT  COUNT(*)
+            FROM  config.coded_value_map
+            WHERE ctype = 'audience'
+            AND code = ' ') = 0;
+
+WITH ccvm AS (
+    SELECT  id
+      FROM  config.coded_value_map
+      WHERE ctype = 'audience'
+            AND code = ' '
+) UPDATE  metabib.record_attr_vector_list
+    SET   vlist = vlist + intset(ccvm.id)
+    WHERE source IN (
+            SELECT  record
+              FROM  metabib.real_full_rec
+              WHERE tag = '008'
+                    AND substring(value,23,1) = ' '
+          );
+
 CREATE OR REPLACE FUNCTION metabib.reingest_record_attributes (rid BIGINT, pattr_list TEXT[] DEFAULT NULL, prmarc TEXT DEFAULT NULL, rdeleted BOOL DEFAULT TRUE) RETURNS VOID AS $func$
 DECLARE
     transformed_xml TEXT;