]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/src/sql/Pg/upgrade/0030.data.flat-subject-entries.sql
LP#1947173: Clean up bad cataloging pot hole
[Evergreen.git] / Open-ILS / src / sql / Pg / upgrade / 0030.data.flat-subject-entries.sql
1 BEGIN;
2
3 -- Generate the equivalent of compound subject entries from the existing rows
4 -- so that we don't have to laboriously reindex them
5
6 INSERT INTO config.upgrade_log (version) VALUES ('0030'); -- dbs
7
8 INSERT INTO config.metabib_field (field_class, name, format, xpath ) VALUES
9     ( 'subject', 'complete', 'mods32', $$//mods32:mods/mods32:subject//text()$$ );
10
11 CREATE INDEX metabib_subject_field_entry_source_idx ON metabib.subject_field_entry (source);
12
13 INSERT INTO metabib.subject_field_entry (source, field, value)
14     SELECT source, (
15             SELECT id 
16             FROM config.metabib_field
17             WHERE field_class = 'subject' AND name = 'complete'
18         ), 
19         ARRAY_TO_STRING ( 
20             ARRAY (
21                 SELECT value 
22                 FROM metabib.subject_field_entry msfe
23                 WHERE msfe.source = groupee.source
24                 ORDER BY source 
25             ), ' ' 
26         ) AS grouped
27     FROM ( 
28         SELECT source
29         FROM metabib.subject_field_entry
30         GROUP BY source
31     ) AS groupee;
32
33 COMMIT;