]> git.evergreen-ils.org Git - working/Evergreen.git/blob - Open-ILS/src/sql/Pg/upgrade/1033.data.fix_subject_browse_mappings.sql
LP#1680554: Stamping upgrade script for fix browse definition ids
[working/Evergreen.git] / Open-ILS / src / sql / Pg / upgrade / 1033.data.fix_subject_browse_mappings.sql
1 BEGIN;
2
3 SELECT evergreen.upgrade_deps_block_check('1033', :eg_version);
4
5 -- correctly turn off browsing for subjectd|geograhic and
6 -- subject|temporal now that the *_browse versions exist. This is
7 -- a no-op in a database that was started at version 2.12.0.
8 UPDATE config.metabib_field
9 SET browse_field = FALSE
10 WHERE field_class = 'subject' AND name = 'geographic'
11 AND browse_field
12 AND id = 11;
13 UPDATE config.metabib_field
14 SET browse_field = FALSE
15 WHERE field_class = 'subject' AND name = 'temporal'
16 AND browse_field
17 AND id = 13;
18
19 select b.tag, idx.name
20 from authority.control_set_bib_field b
21 join authority.control_set_bib_field_metabib_field_map map on (b.id = map.bib_field)
22 join config.metabib_field idx on (map.metabib_field = idx.id)
23 order by b.tag;
24
25 -- and fix bib field mapping if necessasry
26 UPDATE authority.control_set_bib_field_metabib_field_map map
27 SET metabib_field = cmf.id
28 FROM config.metabib_field cmf
29 WHERE cmf.field_class = 'subject' AND cmf.name= 'temporal_browse'
30 AND   map.bib_field IN (
31     SELECT b.id
32     FROM authority.control_set_bib_field b
33     JOIN authority.control_set_authority_field a
34     ON (b.authority_field = a.id)
35     AND a.tag = '148'
36 )
37 AND   map.metabib_field IN (
38     SELECT id
39     FROM config.metabib_field
40     WHERE field_class = 'subject' AND name = 'geographic_browse'
41 );
42 UPDATE authority.control_set_bib_field_metabib_field_map map
43 SET metabib_field = cmf.id
44 FROM config.metabib_field cmf
45 WHERE cmf.field_class = 'subject' AND cmf.name= 'geographic_browse'
46 AND   map.bib_field IN (
47     SELECT b.id
48     FROM authority.control_set_bib_field b
49     JOIN authority.control_set_authority_field a
50     ON (b.authority_field = a.id)
51     AND a.tag = '151'
52 )
53 AND   map.metabib_field IN (
54     SELECT id
55     FROM config.metabib_field
56     WHERE field_class = 'subject' AND name = 'temporal_browse'
57 );
58
59 \qecho Verify that bib subject fields appear to be mapped to
60 \qecho to correct browse indexes
61 SELECT b.id, b.tag, idx.field_class, idx.name
62 FROM authority.control_set_bib_field b
63 JOIN authority.control_set_bib_field_metabib_field_map map ON (b.id = map.bib_field)
64 JOIN config.metabib_field idx ON (map.metabib_field = idx.id)
65 WHERE tag ~ '^6'
66 ORDER BY b.tag;
67
68 COMMIT;
69
70 \qecho This is a browse-only reingest of your bib records. It may take a while.
71 \qecho You may cancel now without losing the effect of the rest of the
72 \qecho upgrade script, and arrange the reingest later.
73 \qecho .
74 SELECT metabib.reingest_metabib_field_entries(id, TRUE, FALSE, TRUE)
75     FROM biblio.record_entry;