1 --Upgrade Script for 3.6.4 to 3.6.5
2 \set eg_version '''3.6.5'''
4 INSERT INTO config.upgrade_log (version, applied_to) VALUES ('3.6.5', :eg_version);
6 SELECT evergreen.upgrade_deps_block_check('1266', :eg_version);
8 INSERT INTO config.workstation_setting_type (name, grp, datatype, label)
10 'eg.grid.catalog.record.copies', 'gui', 'object',
12 'eg.grid.catalog.record.copies',
13 'Grid Config: eg.grid.catalog.record.copies',
18 SELECT evergreen.upgrade_deps_block_check('1268', :eg_version);
20 INSERT INTO config.workstation_setting_type (name, grp, datatype, label)
22 'eg.staff.catalog.results.show_more', 'gui', 'bool',
24 'eg.staff.catalog.results.show_more',
25 'Show more details in Angular staff catalog',
31 SELECT evergreen.upgrade_deps_block_check('1269', :eg_version);
36 WHERE code IN ('VIEW_BOOKING_RESERVATION', 'VIEW_BOOKING_RESERVATION_ATTR_MAP'))
38 INSERT INTO permission.grp_perm_map (grp, perm, depth, grantable)
39 SELECT grp, perms_to_add.id as perm, depth, grantable
41 permission.grp_perm_map
43 --- Don't add the permissions if they have already been assigned
45 (SELECT DISTINCT grp FROM permission.grp_perm_map
46 INNER JOIN perms_to_add ON perm=perms_to_add.id)
48 --- Anybody who can view resources should also see reservations
52 FROM permission.perm_list
53 WHERE code = 'VIEW_BOOKING_RESOURCE'
58 SELECT evergreen.upgrade_deps_block_check('1270', :eg_version);
60 INSERT INTO config.marc21_ff_pos_map (fixed_field, tag, rec_type,start_pos, length, default_val) VALUES ('Srce', '008', 'BKS', 39, 1, ' ');
61 INSERT INTO config.marc21_ff_pos_map (fixed_field, tag, rec_type,start_pos, length, default_val) VALUES ('Srce', '008', 'COM', 39, 1, ' ');
62 INSERT INTO config.marc21_ff_pos_map (fixed_field, tag, rec_type,start_pos, length, default_val) VALUES ('Srce', '008', 'MAP', 39, 1, ' ');
63 INSERT INTO config.marc21_ff_pos_map (fixed_field, tag, rec_type,start_pos, length, default_val) VALUES ('Srce', '008', 'MIX', 39, 1, ' ');
64 INSERT INTO config.marc21_ff_pos_map (fixed_field, tag, rec_type,start_pos, length, default_val) VALUES ('Srce', '008', 'REC', 39, 1, ' ');
65 INSERT INTO config.marc21_ff_pos_map (fixed_field, tag, rec_type,start_pos, length, default_val) VALUES ('Srce', '008', 'SCO', 39, 1, ' ');
66 INSERT INTO config.marc21_ff_pos_map (fixed_field, tag, rec_type,start_pos, length, default_val) VALUES ('Srce', '008', 'SER', 39, 1, ' ');
67 INSERT INTO config.marc21_ff_pos_map (fixed_field, tag, rec_type,start_pos, length, default_val) VALUES ('Srce', '008', 'VIS', 39, 1, ' ');
70 INSERT INTO config.record_attr_definition (name,label,fixed_field) values ('srce','Srce','Srce');
72 INSERT INTO config.coded_value_map (id, ctype, code, value) VALUES
73 (1750, 'srce', ' ', oils_i18n_gettext('1750', 'National bibliographic agency', 'ccvm', 'value')),
74 (1751, 'srce', 'c', oils_i18n_gettext('1751', 'Cooperative cataloging program', 'ccvm', 'value')),
75 (1752, 'srce', 'd', oils_i18n_gettext('1752', 'Other', 'ccvm', 'value'));
78 SELECT evergreen.upgrade_deps_block_check('1272', :eg_version);
83 PERFORM FROM config.usr_setting_type WHERE name = 'circ.collections.exempt';
87 INSERT INTO config.usr_setting_type (
95 'circ.collections.exempt',
98 'circ.collections.exempt',
99 'Collections: Exempt',
104 'circ.collections.exempt',
105 'User is exempt from collections tracking/processing',
119 SELECT evergreen.upgrade_deps_block_check('1279', :eg_version);
121 UPDATE config.org_unit_setting_type SET fm_class='cnal', datatype='link' WHERE name='ui.patron.default_inet_access_level';
125 SELECT evergreen.upgrade_deps_block_check('1283', :eg_version); -- rhamby/ehardy/jboyer
127 UPDATE asset.call_number SET record = -1 WHERE id = -1 AND record != -1;
129 CREATE RULE protect_bre_id_neg1 AS ON UPDATE TO biblio.record_entry WHERE OLD.id = -1 DO INSTEAD NOTHING;
130 CREATE RULE protect_acl_id_1 AS ON UPDATE TO asset.copy_location WHERE OLD.id = 1 DO INSTEAD NOTHING;
131 CREATE RULE protect_acn_id_neg1 AS ON UPDATE TO asset.call_number WHERE OLD.id = -1 DO INSTEAD NOTHING;
133 CREATE OR REPLACE FUNCTION asset.merge_record_assets( target_record BIGINT, source_record BIGINT ) RETURNS INT AS $func$
135 moved_objects INT := 0;
136 source_cn asset.call_number%ROWTYPE;
137 target_cn asset.call_number%ROWTYPE;
138 metarec metabib.metarecord%ROWTYPE;
139 hold action.hold_request%ROWTYPE;
140 ser_rec serial.record_entry%ROWTYPE;
141 ser_sub serial.subscription%ROWTYPE;
142 acq_lineitem acq.lineitem%ROWTYPE;
143 acq_request acq.user_request%ROWTYPE;
144 booking booking.resource_type%ROWTYPE;
145 source_part biblio.monograph_part%ROWTYPE;
146 target_part biblio.monograph_part%ROWTYPE;
147 multi_home biblio.peer_bib_copy_map%ROWTYPE;
154 -- we don't merge bib -1
155 IF target_record = -1 OR source_record = -1 THEN
159 -- move any 856 entries on records that have at least one MARC-mapped URI entry
160 SELECT INTO uri_count COUNT(*)
161 FROM asset.uri_call_number_map m
162 JOIN asset.call_number cn ON (m.call_number = cn.id)
163 WHERE cn.record = source_record;
165 IF uri_count > 0 THEN
167 -- This returns more nodes than you might expect:
168 -- 7 instead of 1 for an 856 with $u $y $9
169 SELECT COUNT(*) INTO counter
170 FROM oils_xpath_table(
173 'biblio.record_entry',
175 'id=' || source_record
176 ) as t(i int,c text);
178 FOR i IN 1 .. counter LOOP
179 SELECT '<datafield xmlns="http://www.loc.gov/MARC21/slim"' ||
181 ' ind1="' || FIRST(ind1) || '"' ||
182 ' ind2="' || FIRST(ind2) || '">' ||
184 '<subfield code="' || subfield || '">' ||
187 regexp_replace(data,'&','&','g'),
191 ) || '</subfield>', ''
192 ) || '</datafield>' INTO uri_datafield
193 FROM oils_xpath_table(
196 'biblio.record_entry',
197 '//*[@tag="856"][position()=' || i || ']/@ind1|' ||
198 '//*[@tag="856"][position()=' || i || ']/@ind2|' ||
199 '//*[@tag="856"][position()=' || i || ']/*/@code|' ||
200 '//*[@tag="856"][position()=' || i || ']/*[@code]',
201 'id=' || source_record
202 ) as t(id int,ind1 text, ind2 text,subfield text,data text);
204 -- As most of the results will be NULL, protect against NULLifying
205 -- the valid content that we do generate
206 uri_text := uri_text || COALESCE(uri_datafield, '');
209 IF uri_text <> '' THEN
210 UPDATE biblio.record_entry
211 SET marc = regexp_replace(marc,'(</[^>]*record>)', uri_text || E'\\1')
212 WHERE id = target_record;
217 -- Find and move metarecords to the target record
218 SELECT INTO metarec *
219 FROM metabib.metarecord
220 WHERE master_record = source_record;
223 UPDATE metabib.metarecord
224 SET master_record = target_record,
226 WHERE id = metarec.id;
228 moved_objects := moved_objects + 1;
231 -- Find call numbers attached to the source ...
232 FOR source_cn IN SELECT * FROM asset.call_number WHERE record = source_record LOOP
234 SELECT INTO target_cn *
235 FROM asset.call_number
236 WHERE label = source_cn.label
237 AND prefix = source_cn.prefix
238 AND suffix = source_cn.suffix
239 AND owning_lib = source_cn.owning_lib
240 AND record = target_record
243 -- ... and if there's a conflicting one on the target ...
246 -- ... move the copies to that, and ...
248 SET call_number = target_cn.id
249 WHERE call_number = source_cn.id;
251 -- ... move V holds to the move-target call number
252 FOR hold IN SELECT * FROM action.hold_request WHERE target = source_cn.id AND hold_type = 'V' LOOP
254 UPDATE action.hold_request
255 SET target = target_cn.id
258 moved_objects := moved_objects + 1;
261 UPDATE asset.call_number SET deleted = TRUE WHERE id = source_cn.id;
265 -- ... just move the call number to the target record
266 UPDATE asset.call_number
267 SET record = target_record
268 WHERE id = source_cn.id;
271 moved_objects := moved_objects + 1;
274 -- Find T holds targeting the source record ...
275 FOR hold IN SELECT * FROM action.hold_request WHERE target = source_record AND hold_type = 'T' LOOP
277 -- ... and move them to the target record
278 UPDATE action.hold_request
279 SET target = target_record
282 moved_objects := moved_objects + 1;
285 -- Find serial records targeting the source record ...
286 FOR ser_rec IN SELECT * FROM serial.record_entry WHERE record = source_record LOOP
287 -- ... and move them to the target record
288 UPDATE serial.record_entry
289 SET record = target_record
290 WHERE id = ser_rec.id;
292 moved_objects := moved_objects + 1;
295 -- Find serial subscriptions targeting the source record ...
296 FOR ser_sub IN SELECT * FROM serial.subscription WHERE record_entry = source_record LOOP
297 -- ... and move them to the target record
298 UPDATE serial.subscription
299 SET record_entry = target_record
300 WHERE id = ser_sub.id;
302 moved_objects := moved_objects + 1;
305 -- Find booking resource types targeting the source record ...
306 FOR booking IN SELECT * FROM booking.resource_type WHERE record = source_record LOOP
307 -- ... and move them to the target record
308 UPDATE booking.resource_type
309 SET record = target_record
310 WHERE id = booking.id;
312 moved_objects := moved_objects + 1;
315 -- Find acq lineitems targeting the source record ...
316 FOR acq_lineitem IN SELECT * FROM acq.lineitem WHERE eg_bib_id = source_record LOOP
317 -- ... and move them to the target record
319 SET eg_bib_id = target_record
320 WHERE id = acq_lineitem.id;
322 moved_objects := moved_objects + 1;
325 -- Find acq user purchase requests targeting the source record ...
326 FOR acq_request IN SELECT * FROM acq.user_request WHERE eg_bib = source_record LOOP
327 -- ... and move them to the target record
328 UPDATE acq.user_request
329 SET eg_bib = target_record
330 WHERE id = acq_request.id;
332 moved_objects := moved_objects + 1;
335 -- Find parts attached to the source ...
336 FOR source_part IN SELECT * FROM biblio.monograph_part WHERE record = source_record LOOP
338 SELECT INTO target_part *
339 FROM biblio.monograph_part
340 WHERE label = source_part.label
341 AND record = target_record;
343 -- ... and if there's a conflicting one on the target ...
346 -- ... move the copy-part maps to that, and ...
347 UPDATE asset.copy_part_map
348 SET part = target_part.id
349 WHERE part = source_part.id;
351 -- ... move P holds to the move-target part
352 FOR hold IN SELECT * FROM action.hold_request WHERE target = source_part.id AND hold_type = 'P' LOOP
354 UPDATE action.hold_request
355 SET target = target_part.id
358 moved_objects := moved_objects + 1;
363 -- ... just move the part to the target record
364 UPDATE biblio.monograph_part
365 SET record = target_record
366 WHERE id = source_part.id;
369 moved_objects := moved_objects + 1;
372 -- Find multi_home items attached to the source ...
373 FOR multi_home IN SELECT * FROM biblio.peer_bib_copy_map WHERE peer_record = source_record LOOP
374 -- ... and move them to the target record
375 UPDATE biblio.peer_bib_copy_map
376 SET peer_record = target_record
377 WHERE id = multi_home.id;
379 moved_objects := moved_objects + 1;
382 -- And delete mappings where the item's home bib was merged with the peer bib
383 DELETE FROM biblio.peer_bib_copy_map WHERE peer_record = (
384 SELECT (SELECT record FROM asset.call_number WHERE id = call_number)
385 FROM asset.copy WHERE id = target_copy
388 -- Apply merge tracking
389 UPDATE biblio.record_entry
390 SET merge_date = NOW() WHERE id = target_record;
392 UPDATE biblio.record_entry
393 SET merge_date = NOW(), merged_to = target_record
394 WHERE id = source_record;
396 -- replace book bag entries of source_record with target_record
397 UPDATE container.biblio_record_entry_bucket_item
398 SET target_biblio_record_entry = target_record
399 WHERE bucket IN (SELECT id FROM container.biblio_record_entry_bucket WHERE btype = 'bookbag')
400 AND target_biblio_record_entry = source_record;
402 -- Finally, "delete" the source record
403 UPDATE biblio.record_entry SET active = FALSE WHERE id = source_record;
404 DELETE FROM biblio.record_entry WHERE id = source_record;
406 -- That's all, folks!
407 RETURN moved_objects;
409 $func$ LANGUAGE plpgsql;
414 SELECT evergreen.upgrade_deps_block_check('1294', :eg_version); -- mmorgan / tlittle / JBoyer
416 INSERT INTO config.workstation_setting_type (name, grp, datatype, label)
418 'eg.grid.admin.local.container.carousel_org_unit', 'gui', 'object',
420 'eg.grid.admin.local.container.carousel_org_unit',
421 'Grid Config: eg.grid.admin.local.container.carousel_org_unit',
425 'eg.grid.admin.container.carousel', 'gui', 'object',
427 'eg.grid.admin.container.carousel',
428 'Grid Config: eg.grid.admin.container.carousel',
432 'eg.grid.admin.server.config.carousel_type', 'gui', 'object',
434 'eg.grid.admin.server.config.carousel_type',
435 'Grid Config: eg.grid.admin.server.config.carousel_type',
441 SELECT evergreen.upgrade_deps_block_check('1302', :eg_version);
443 UPDATE config.org_unit_setting_type
444 SET description = oils_i18n_gettext(
445 'ui.circ.items_out.longoverdue',
446 'Value is a numeric code, describing: A. In which tab ("Items Checked Out", '||
447 'or "Other/Special Circulations") the circulation '||
448 'should appear while checked out, and B. Whether the circulation should '||
449 'continue to appear in the "Other" tab when checked in with '||
450 'outstanding fines. '||
451 '1 = (A) "Items", (B) "Other". 2 = (A) "Other", (B) "Other". ' ||
452 '5 = (A) "Items", (B) do not display. 6 = (A) "Other", (B) do not display.',
456 WHERE name = 'ui.circ.items_out.longoverdue';
458 UPDATE config.org_unit_setting_type
459 set description = oils_i18n_gettext(
460 'ui.circ.items_out.lost',
461 'Value is a numeric code, describing: A. In which tab ("Items Checked Out", '||
462 'or "Other/Special Circulations") the circulation '||
463 'should appear while checked out, and B. Whether the circulation should '||
464 'continue to appear in the "Other" tab when checked in with '||
465 'outstanding fines. '||
466 '1 = (A) "Items", (B) "Other". 2 = (A) "Other", (B) "Other". ' ||
467 '5 = (A) "Items", (B) do not display. 6 = (A) "Other", (B) do not display.',
471 WHERE name = 'ui.circ.items_out.lost';
473 UPDATE config.org_unit_setting_type
474 set description = oils_i18n_gettext(
475 'ui.circ.items_out.claimsreturned',
476 'Value is a numeric code, describing: A. In which tab ("Items Checked Out", '||
477 'or "Other/Special Circulations") the circulation '||
478 'should appear while checked out, and B. Whether the circulation should '||
479 'continue to appear in the "Other" tab when checked in with '||
480 'outstanding fines. '||
481 '1 = (A) "Items", (B) "Other". 2 = (A) "Other", (B) "Other". ' ||
482 '5 = (A) "Items", (B) do not display. 6 = (A) "Other", (B) do not display.',
486 WHERE name = 'ui.circ.items_out.claimsreturned';
489 SELECT evergreen.upgrade_deps_block_check('1303', :eg_version);
491 DROP INDEX authority.authority_full_rec_value_index;
492 CREATE INDEX authority_full_rec_value_index ON authority.full_rec (SUBSTRING(value FOR 1024));
494 DROP INDEX authority.authority_full_rec_value_tpo_index;
495 CREATE INDEX authority_full_rec_value_tpo_index ON authority.full_rec (SUBSTRING(value FOR 1024) text_pattern_ops);
500 -- Update auditor tables to catch changes to source tables.
501 -- Can be removed/skipped if there were no schema changes.
502 SELECT auditor.update_auditors();