1 --Upgrade Script for 2.3.2 to 2.3.3
2 \set eg_version '''2.3.3'''
4 INSERT INTO config.upgrade_log (version, applied_to) VALUES ('2.3.3', :eg_version);
5 -- Use MARC relator codes (710 subfield 4) to index corporate authors, along
6 -- with the existing relator text (710 subfield e)
9 -- check whether patch can be applied
10 SELECT evergreen.upgrade_deps_block_check('0749', :eg_version);
12 UPDATE config.metabib_field
13 SET xpath = $$//mods32:mods/mods32:name[@type='corporate'
14 and (mods32:role/mods32:roleTerm[text()='creator']
15 or mods32:role/mods32:roleTerm[text()='aut']
16 or mods32:role/mods32:roleTerm[text()='cre']
21 SELECT metabib.reingest_metabib_field_entries(record, TRUE, TRUE, FALSE)
25 AND value IN ('cre', 'aut')
28 -- Only consider main entry headings for bib overlay
31 -- check whether patch can be applied
32 SELECT evergreen.upgrade_deps_block_check('0750', :eg_version);
35 -- Function to generate an ephemeral overlay template from an authority record
36 CREATE OR REPLACE FUNCTION authority.generate_overlay_template (source_xml TEXT) RETURNS TEXT AS $f$
39 main_entry authority.control_set_authority_field%ROWTYPE;
40 bib_field authority.control_set_bib_field%ROWTYPE;
41 auth_id INT DEFAULT oils_xpath_string('//*[@tag="901"]/*[local-name()="subfield" and @code="c"]', source_xml)::INT;
42 replace_data XML[] DEFAULT '{}'::XML[];
43 replace_rules TEXT[] DEFAULT '{}'::TEXT[];
46 IF auth_id IS NULL THEN
50 -- Default to the LoC controll set
51 SELECT control_set INTO cset FROM authority.record_entry WHERE id = auth_id;
53 -- if none, make a best guess
55 SELECT control_set INTO cset
56 FROM authority.control_set_authority_field
58 SELECT UNNEST(XPATH('//*[starts-with(@tag,"1")]/@tag',marc::XML)::TEXT[])
59 FROM authority.record_entry
65 -- if STILL none, no-op change
69 XMLATTRIBUTES('http://www.loc.gov/MARC21/slim' AS xmlns),
70 XMLELEMENT( name leader, '00881nam a2200193 4500'),
73 XMLATTRIBUTES( '905' AS tag, ' ' AS ind1, ' ' AS ind2),
76 XMLATTRIBUTES('d' AS code),
83 FOR main_entry IN SELECT * FROM authority.control_set_authority_field acsaf WHERE acsaf.control_set = cset AND acsaf.main_entry IS NULL LOOP
84 auth_field := XPATH('//*[@tag="'||main_entry.tag||'"][1]',source_xml::XML);
85 IF ARRAY_LENGTH(auth_field,1) > 0 THEN
86 FOR bib_field IN SELECT * FROM authority.control_set_bib_field WHERE authority_field = main_entry.id LOOP
87 replace_data := replace_data || XMLELEMENT( name datafield, XMLATTRIBUTES(bib_field.tag AS tag), XPATH('//*[local-name()="subfield"]',auth_field[1])::XML[]);
88 replace_rules := replace_rules || ( bib_field.tag || main_entry.sf_list || E'[0~\\)' || auth_id || '$]' );
96 XMLATTRIBUTES('http://www.loc.gov/MARC21/slim' AS xmlns),
97 XMLELEMENT( name leader, '00881nam a2200193 4500'),
101 XMLATTRIBUTES( '905' AS tag, ' ' AS ind1, ' ' AS ind2),
104 XMLATTRIBUTES('r' AS code),
105 ARRAY_TO_STRING(replace_rules,',')
110 $f$ STABLE LANGUAGE PLPGSQL;
112 -- Change the two argument form of vandelay.merge_record_xml to
113 -- prevent bibliographic record destruction when there is nothing to
117 CREATE OR REPLACE FUNCTION vandelay.merge_record_xml ( target_marc TEXT, template_marc TEXT ) RETURNS TEXT AS $$
119 dyn_profile vandelay.compile_profile%ROWTYPE;
127 IF target_marc IS NULL OR template_marc IS NULL THEN
128 -- RAISE NOTICE 'no marc for target or template record';
132 dyn_profile := vandelay.compile_profile( template_marc );
134 IF dyn_profile.replace_rule <> '' AND dyn_profile.preserve_rule <> '' THEN
135 -- RAISE NOTICE 'both replace [%] and preserve [%] specified', dyn_profile.replace_rule, dyn_profile.preserve_rule;
139 IF dyn_profile.replace_rule = '' AND dyn_profile.preserve_rule = '' AND dyn_profile.add_rule = '' THEN
140 --Since we have nothing to do, just return what we were given.
142 ELSIF dyn_profile.replace_rule <> '' THEN
143 trgt_marc = target_marc;
144 tmpl_marc = template_marc;
145 replace_rule = dyn_profile.replace_rule;
147 tmp_marc = target_marc;
148 trgt_marc = template_marc;
149 tmpl_marc = tmp_marc;
150 replace_rule = dyn_profile.preserve_rule;
153 RETURN vandelay.merge_record_xml( trgt_marc, tmpl_marc, dyn_profile.add_rule, replace_rule, dyn_profile.strip_rule );
158 CREATE OR REPLACE FUNCTION vandelay.template_overlay_bib_record ( v_marc TEXT, eg_id BIGINT, merge_profile_id INT ) RETURNS BOOL AS $$
160 merge_profile vandelay.merge_profile%ROWTYPE;
161 dyn_profile vandelay.compile_profile%ROWTYPE;
171 SELECT b.marc INTO eg_marc
172 FROM biblio.record_entry b
176 IF eg_marc IS NULL OR v_marc IS NULL THEN
177 -- RAISE NOTICE 'no marc for template or bib record';
181 dyn_profile := vandelay.compile_profile( v_marc );
183 IF merge_profile_id IS NOT NULL THEN
184 SELECT * INTO merge_profile FROM vandelay.merge_profile WHERE id = merge_profile_id;
186 dyn_profile.add_rule := BTRIM( dyn_profile.add_rule || ',' || COALESCE(merge_profile.add_spec,''), ',');
187 dyn_profile.strip_rule := BTRIM( dyn_profile.strip_rule || ',' || COALESCE(merge_profile.strip_spec,''), ',');
188 dyn_profile.replace_rule := BTRIM( dyn_profile.replace_rule || ',' || COALESCE(merge_profile.replace_spec,''), ',');
189 dyn_profile.preserve_rule := BTRIM( dyn_profile.preserve_rule || ',' || COALESCE(merge_profile.preserve_spec,''), ',');
193 IF dyn_profile.replace_rule <> '' AND dyn_profile.preserve_rule <> '' THEN
194 -- RAISE NOTICE 'both replace [%] and preserve [%] specified', dyn_profile.replace_rule, dyn_profile.preserve_rule;
198 IF dyn_profile.replace_rule = '' AND dyn_profile.preserve_rule = '' AND dyn_profile.add_rule = '' AND dyn_profile.strip_rule = '' THEN
199 --Since we have nothing to do, just return a NOOP "we did it"
201 ELSIF dyn_profile.replace_rule <> '' THEN
202 source_marc = v_marc;
203 target_marc = eg_marc;
204 replace_rule = dyn_profile.replace_rule;
206 source_marc = eg_marc;
207 target_marc = v_marc;
208 replace_rule = dyn_profile.preserve_rule;
211 UPDATE biblio.record_entry
212 SET marc = vandelay.merge_record_xml( target_marc, source_marc, dyn_profile.add_rule, replace_rule, dyn_profile.strip_rule )
216 -- RAISE NOTICE 'update of biblio.record_entry failed';
225 CREATE OR REPLACE FUNCTION vandelay.overlay_authority_record ( import_id BIGINT, eg_id BIGINT, merge_profile_id INT ) RETURNS BOOL AS $$
227 merge_profile vandelay.merge_profile%ROWTYPE;
228 dyn_profile vandelay.compile_profile%ROWTYPE;
237 SELECT b.marc INTO eg_marc
238 FROM authority.record_entry b
239 JOIN vandelay.authority_match m ON (m.eg_record = b.id AND m.queued_record = import_id)
242 SELECT q.marc INTO v_marc
243 FROM vandelay.queued_record q
244 JOIN vandelay.authority_match m ON (m.queued_record = q.id AND q.id = import_id)
247 IF eg_marc IS NULL OR v_marc IS NULL THEN
248 -- RAISE NOTICE 'no marc for vandelay or authority record';
252 dyn_profile := vandelay.compile_profile( v_marc );
254 IF merge_profile_id IS NOT NULL THEN
255 SELECT * INTO merge_profile FROM vandelay.merge_profile WHERE id = merge_profile_id;
257 dyn_profile.add_rule := BTRIM( dyn_profile.add_rule || ',' || COALESCE(merge_profile.add_spec,''), ',');
258 dyn_profile.strip_rule := BTRIM( dyn_profile.strip_rule || ',' || COALESCE(merge_profile.strip_spec,''), ',');
259 dyn_profile.replace_rule := BTRIM( dyn_profile.replace_rule || ',' || COALESCE(merge_profile.replace_spec,''), ',');
260 dyn_profile.preserve_rule := BTRIM( dyn_profile.preserve_rule || ',' || COALESCE(merge_profile.preserve_spec,''), ',');
264 IF dyn_profile.replace_rule <> '' AND dyn_profile.preserve_rule <> '' THEN
265 -- RAISE NOTICE 'both replace [%] and preserve [%] specified', dyn_profile.replace_rule, dyn_profile.preserve_rule;
269 IF dyn_profile.replace_rule = '' AND dyn_profile.preserve_rule = '' AND dyn_profile.add_rule = '' AND dyn_profile.strip_rule = '' THEN
270 --Since we have nothing to do, just return a NOOP "we did it"
272 ELSIF dyn_profile.replace_rule <> '' THEN
273 source_marc = v_marc;
274 target_marc = eg_marc;
275 replace_rule = dyn_profile.replace_rule;
277 source_marc = eg_marc;
278 target_marc = v_marc;
279 replace_rule = dyn_profile.preserve_rule;
282 UPDATE authority.record_entry
283 SET marc = vandelay.merge_record_xml( target_marc, source_marc, dyn_profile.add_rule, replace_rule, dyn_profile.strip_rule )
287 UPDATE vandelay.queued_authority_record
288 SET imported_as = eg_id,
290 WHERE id = import_id;
294 -- RAISE NOTICE 'update of authority.record_entry failed';
302 SELECT evergreen.upgrade_deps_block_check('0751', :eg_version);
304 INSERT INTO acq.cancel_reason (keep_debits, id, org_unit, label, description)
310 'This line item is not accepted by the seller.'