1 --Upgrade Script for 2.7.1 to 2.7.2
2 \set eg_version '''2.7.2'''
4 INSERT INTO config.upgrade_log (version, applied_to) VALUES ('2.7.2', :eg_version);
6 SELECT evergreen.upgrade_deps_block_check('0896', :eg_version);
8 CREATE OR REPLACE FUNCTION asset.acp_location_fixer()
11 new_copy_location INT;
13 IF (TG_OP = 'UPDATE') THEN
14 IF NEW.location = OLD.location AND NEW.call_number = OLD.call_number AND NEW.circ_lib = OLD.circ_lib THEN
18 SELECT INTO new_copy_location acpl.id FROM asset.copy_location acpl JOIN actor.org_unit_ancestors_distance((SELECT owning_lib FROM asset.call_number WHERE id = NEW.call_number)) aouad ON acpl.owning_lib = aouad.id WHERE name = (SELECT name FROM asset.copy_location WHERE id = NEW.location) ORDER BY distance LIMIT 1;
19 IF new_copy_location IS NULL THEN
20 SELECT INTO new_copy_location acpl.id FROM asset.copy_location acpl JOIN actor.org_unit_ancestors_distance(NEW.circ_lib) aouad ON acpl.owning_lib = aouad.id WHERE name = (SELECT name FROM asset.copy_location WHERE id = NEW.location) ORDER BY distance LIMIT 1;
22 IF new_copy_location IS NOT NULL THEN
23 NEW.location = new_copy_location;
29 DROP TRIGGER IF EXISTS acp_location_fixer_trig ON asset.copy;
31 CREATE TRIGGER acp_location_fixer_trig
32 BEFORE INSERT OR UPDATE OF location, call_number, circ_lib ON asset.copy
33 FOR EACH ROW EXECUTE PROCEDURE asset.acp_location_fixer();
36 SELECT evergreen.upgrade_deps_block_check('0897', :eg_version);
38 CREATE OR REPLACE FUNCTION authority.indexing_ingest_or_delete() RETURNS TRIGGER AS $BODY$
40 ashs authority.simple_heading%ROWTYPE;
41 mbe_row metabib.browse_entry%ROWTYPE;
46 IF NEW.deleted IS TRUE THEN -- If this authority is deleted
47 DELETE FROM authority.bib_linking WHERE authority = NEW.id; -- Avoid updating fields in bibs that are no longer visible
48 DELETE FROM authority.full_rec WHERE record = NEW.id; -- Avoid validating fields against deleted authority records
49 DELETE FROM authority.simple_heading WHERE record = NEW.id;
50 -- Should remove matching $0 from controlled fields at the same time?
52 -- XXX What do we about the actual linking subfields present in
53 -- authority records that target this one when this happens?
54 DELETE FROM authority.authority_linking
55 WHERE source = NEW.id OR target = NEW.id;
57 RETURN NEW; -- and we're done
60 IF TG_OP = 'UPDATE' THEN -- re-ingest?
61 PERFORM * FROM config.internal_flag WHERE name = 'ingest.reingest.force_on_same_marc' AND enabled;
63 IF NOT FOUND AND OLD.marc = NEW.marc THEN -- don't do anything if the MARC didn't change
67 -- Unless there's a setting stopping us, propagate these updates to any linked bib records
68 PERFORM * FROM config.internal_flag WHERE name = 'ingest.disable_authority_auto_update' AND enabled;
71 PERFORM authority.propagate_changes(NEW.id);
74 DELETE FROM authority.simple_heading WHERE record = NEW.id;
75 DELETE FROM authority.authority_linking WHERE source = NEW.id;
78 INSERT INTO authority.authority_linking (source, target, field)
79 SELECT source, target, field FROM authority.calculate_authority_linking(
80 NEW.id, NEW.control_set, NEW.marc::XML
83 FOR ashs IN SELECT * FROM authority.simple_heading_set(NEW.marc) LOOP
85 INSERT INTO authority.simple_heading (record,atag,value,sort_value)
86 VALUES (ashs.record, ashs.atag, ashs.value, ashs.sort_value);
87 ash_id := CURRVAL('authority.simple_heading_id_seq'::REGCLASS);
89 SELECT INTO mbe_row * FROM metabib.browse_entry
90 WHERE value = ashs.value AND sort_value = ashs.sort_value;
95 INSERT INTO metabib.browse_entry
96 ( value, sort_value ) VALUES
97 ( ashs.value, ashs.sort_value );
99 mbe_id := CURRVAL('metabib.browse_entry_id_seq'::REGCLASS);
102 INSERT INTO metabib.browse_entry_simple_heading_map (entry,simple_heading) VALUES (mbe_id,ash_id);
106 -- Flatten and insert the afr data
107 PERFORM * FROM config.internal_flag WHERE name = 'ingest.disable_authority_full_rec' AND enabled;
109 PERFORM authority.reingest_authority_full_rec(NEW.id);
110 PERFORM * FROM config.internal_flag WHERE name = 'ingest.disable_authority_rec_descriptor' AND enabled;
112 PERFORM authority.reingest_authority_rec_descriptor(NEW.id);
118 $BODY$ LANGUAGE plpgsql;
122 SELECT evergreen.upgrade_deps_block_check('0898', :eg_version);
124 CREATE OR REPLACE FUNCTION unapi.mmr_mra (
130 depth INT DEFAULT NULL,
131 slimit HSTORE DEFAULT NULL,
132 soffset HSTORE DEFAULT NULL,
133 include_xmlns BOOL DEFAULT TRUE,
134 pref_lib INT DEFAULT NULL
139 CASE WHEN $9 THEN 'http://open-ils.org/spec/indexing/v1' ELSE NULL END AS xmlns,
140 'tag:open-ils.org:U2@mmr/' || $1 AS metarecord
142 (SELECT XMLAGG(foo.y)
145 WITH aou AS (SELECT COALESCE(id, (evergreen.org_top()).id) AS id
146 FROM actor.org_unit WHERE shortname = $5 LIMIT 1)
148 FROM metabib.metarecord_source_map, aou
149 WHERE metarecord = $1 AND (
151 SELECT 1 FROM asset.opac_visible_copies
152 WHERE record = source AND circ_lib IN (
153 SELECT id FROM actor.org_unit_descendants(aou.id, $6))
156 OR EXISTS (SELECT 1 FROM located_uris(source, aou.id, $10) LIMIT 1)
164 cmra.value AS "coded-value",
174 SELECT DISTINCT aid, attr, value
176 SELECT v.source AS id,
180 FROM metabib.record_attr_vector_list v
181 JOIN config.coded_value_map c ON ( c.id = ANY( v.vlist ) )
183 JOIN sourcelist ON (x.id = sourcelist.source)
185 JOIN config.record_attr_definition rad ON (cmra.attr = rad.name)
200 SELECT DISTINCT aid, attr, value
202 SELECT v.source AS id,
206 FROM metabib.record_attr_vector_list v
207 JOIN metabib.uncontrolled_record_attr_value m ON ( m.id = ANY( v.vlist ) )
209 JOIN sourcelist ON (x.id = sourcelist.source)
211 JOIN config.record_attr_definition rad ON (umra.attr = rad.name)
217 $F$ LANGUAGE SQL STABLE;
221 SELECT evergreen.upgrade_deps_block_check('0899', :eg_version);
223 ALTER FUNCTION asset.label_normalizer_generic(TEXT) IMMUTABLE;
224 ALTER FUNCTION asset.label_normalizer_dewey(TEXT) IMMUTABLE;
225 ALTER FUNCTION asset.label_normalizer_lc(TEXT) IMMUTABLE;
228 SELECT evergreen.upgrade_deps_block_check('0900', :eg_version);
230 CREATE OR REPLACE VIEW metabib.record_attr AS
231 SELECT id, HSTORE( ARRAY_AGG( attr ), ARRAY_AGG( value ) ) AS attrs
232 FROM metabib.record_attr_flat
233 WHERE attr IS NOT NULL
239 -- Include helpful note to run 2.6.2-2.6.3 if missed during 2.6-2.7 upgrade
240 \qecho **** NOTICE ****
241 \qecho 'There was a missed upgrade script on the path from 2.6 series'
242 \qecho 'to 2.7 series. If you are upgrading from 2.7.1 and have not'
243 \qecho 'already run 2.6.2-2.6.3-upgrade-db.sql script, please go back'
244 \qecho 'and run now to receive those missed fixes.'