]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/src/sql/Pg/upgrade/1073.schema.metabib-display-field.sql
LP#1772955: Only include xacts with balance in summary
[Evergreen.git] / Open-ILS / src / sql / Pg / upgrade / 1073.schema.metabib-display-field.sql
1
2 BEGIN;
3
4 SELECT evergreen.upgrade_deps_block_check('1073', :eg_version);
5
6 ALTER TABLE config.metabib_field 
7     ADD COLUMN display_xpath TEXT, 
8     ADD COLUMN display_field BOOL NOT NULL DEFAULT FALSE;
9
10 CREATE TABLE config.display_field_map (
11     name    TEXT   PRIMARY KEY,
12     field   INTEGER REFERENCES config.metabib_field (id),
13     multi   BOOLEAN DEFAULT FALSE
14 );
15
16 CREATE TABLE metabib.display_entry (
17     id      BIGSERIAL  PRIMARY KEY,
18     source  BIGINT     NOT NULL REFERENCES biblio.record_entry (id),
19     field   INT        NOT NULL REFERENCES config.metabib_field (id),
20     value   TEXT       NOT NULL
21 );
22
23 CREATE INDEX metabib_display_entry_field_idx ON metabib.display_entry (field);
24 CREATE INDEX metabib_display_entry_source_idx ON metabib.display_entry (source);
25
26 -- one row per display entry fleshed with field info
27 CREATE VIEW metabib.flat_display_entry AS
28     SELECT
29         mde.source,
30         cdfm.name,
31         cdfm.multi,
32         cmf.label,
33         cmf.id AS field,
34         mde.value
35     FROM metabib.display_entry mde
36     JOIN config.metabib_field cmf ON (cmf.id = mde.field)
37     JOIN config.display_field_map cdfm ON (cdfm.field = mde.field)
38 ;
39
40 -- like flat_display_entry except values are compressed 
41 -- into one row per display_field_map and JSON-ified.
42 CREATE VIEW metabib.compressed_display_entry AS
43     SELECT 
44         source,
45         name,
46         multi,
47         label,
48         field,
49         CASE WHEN multi THEN
50             TO_JSON(ARRAY_AGG(value))
51         ELSE
52             TO_JSON(MIN(value))
53         END AS value
54     FROM metabib.flat_display_entry
55     GROUP BY 1, 2, 3, 4, 5
56 ;
57
58 -- TODO: expand to encompass all well-known fields
59 CREATE VIEW metabib.wide_display_entry AS
60     SELECT 
61         bre.id AS source,
62         COALESCE(mcde_title.value, 'null') AS title,
63         COALESCE(mcde_author.value, 'null') AS author,
64         COALESCE(mcde_subject.value, 'null') AS subject,
65         COALESCE(mcde_creators.value, 'null') AS creators,
66         COALESCE(mcde_isbn.value, 'null') AS isbn
67     -- ensure one row per bre regardless of any display fields
68     FROM biblio.record_entry bre 
69     LEFT JOIN metabib.compressed_display_entry mcde_title 
70         ON (bre.id = mcde_title.source AND mcde_title.name = 'title')
71     LEFT JOIN metabib.compressed_display_entry mcde_author 
72         ON (bre.id = mcde_author.source AND mcde_author.name = 'author')
73     LEFT JOIN metabib.compressed_display_entry mcde_subject 
74         ON (bre.id = mcde_subject.source AND mcde_subject.name = 'subject')
75     LEFT JOIN metabib.compressed_display_entry mcde_creators 
76         ON (bre.id = mcde_creators.source AND mcde_creators.name = 'creators')
77     LEFT JOIN metabib.compressed_display_entry mcde_isbn 
78         ON (bre.id = mcde_isbn.source AND mcde_isbn.name = 'isbn')
79 ;
80
81
82 CREATE OR REPLACE FUNCTION metabib.display_field_normalize_trigger () 
83     RETURNS TRIGGER AS $$
84 DECLARE
85     normalizer  RECORD;
86     display_field_text  TEXT;
87 BEGIN
88     display_field_text := NEW.value;
89
90     FOR normalizer IN
91         SELECT  n.func AS func,
92                 n.param_count AS param_count,
93                 m.params AS params
94           FROM  config.index_normalizer n
95                 JOIN config.metabib_field_index_norm_map m ON (m.norm = n.id)
96           WHERE m.field = NEW.field AND m.pos < 0
97           ORDER BY m.pos LOOP
98
99             EXECUTE 'SELECT ' || normalizer.func || '(' ||
100                 quote_literal( display_field_text ) ||
101                 CASE
102                     WHEN normalizer.param_count > 0
103                         THEN ',' || REPLACE(REPLACE(BTRIM(
104                             normalizer.params,'[]'),E'\'',E'\\\''),E'"',E'\'')
105                         ELSE ''
106                     END ||
107                 ')' INTO display_field_text;
108
109     END LOOP;
110
111     NEW.value = display_field_text;
112
113     RETURN NEW;
114 END;
115 $$ LANGUAGE PLPGSQL;
116
117 CREATE TRIGGER display_field_normalize_tgr
118         BEFORE UPDATE OR INSERT ON metabib.display_entry
119         FOR EACH ROW EXECUTE PROCEDURE metabib.display_field_normalize_trigger();
120
121 CREATE OR REPLACE FUNCTION evergreen.display_field_force_nfc() 
122     RETURNS TRIGGER AS $$
123 BEGIN
124     NEW.value := force_unicode_normal_form(NEW.value,'NFC');
125     RETURN NEW;
126 END;
127 $$ LANGUAGE PLPGSQL;
128
129 CREATE TRIGGER display_field_force_nfc_tgr
130         BEFORE UPDATE OR INSERT ON metabib.display_entry
131         FOR EACH ROW EXECUTE PROCEDURE evergreen.display_field_force_nfc();
132
133 ALTER TYPE metabib.field_entry_template ADD ATTRIBUTE display_field BOOL;
134
135 DROP FUNCTION metabib.reingest_metabib_field_entries(BIGINT, BOOL, BOOL, BOOL);
136 DROP FUNCTION biblio.extract_metabib_field_entry(BIGINT);
137 DROP FUNCTION biblio.extract_metabib_field_entry(BIGINT, TEXT);
138
139 CREATE OR REPLACE FUNCTION biblio.extract_metabib_field_entry (
140     rid BIGINT,
141     default_joiner TEXT,
142     field_types TEXT[],
143     only_fields INT[]
144 ) RETURNS SETOF metabib.field_entry_template AS $func$
145 DECLARE
146     bib     biblio.record_entry%ROWTYPE;
147     idx     config.metabib_field%ROWTYPE;
148     xfrm        config.xml_transform%ROWTYPE;
149     prev_xfrm   TEXT;
150     transformed_xml TEXT;
151     xml_node    TEXT;
152     xml_node_list   TEXT[];
153     facet_text  TEXT;
154     display_text TEXT;
155     browse_text TEXT;
156     sort_value  TEXT;
157     raw_text    TEXT;
158     curr_text   TEXT;
159     joiner      TEXT := default_joiner; -- XXX will index defs supply a joiner?
160     authority_text TEXT;
161     authority_link BIGINT;
162     output_row  metabib.field_entry_template%ROWTYPE;
163     process_idx BOOL;
164 BEGIN
165
166     -- Start out with no field-use bools set
167     output_row.browse_field = FALSE;
168     output_row.facet_field = FALSE;
169     output_row.display_field = FALSE;
170     output_row.search_field = FALSE;
171
172     -- Get the record
173     SELECT INTO bib * FROM biblio.record_entry WHERE id = rid;
174
175     -- Loop over the indexing entries
176     FOR idx IN SELECT * FROM config.metabib_field WHERE id = ANY (only_fields) ORDER BY format LOOP
177
178         process_idx := FALSE;
179         IF idx.display_field AND 'display' = ANY (field_types) THEN process_idx = TRUE; END IF;
180         IF idx.browse_field AND 'browse' = ANY (field_types) THEN process_idx = TRUE; END IF;
181         IF idx.search_field AND 'search' = ANY (field_types) THEN process_idx = TRUE; END IF;
182         IF idx.facet_field AND 'facet' = ANY (field_types) THEN process_idx = TRUE; END IF;
183         CONTINUE WHEN process_idx = FALSE;
184
185         joiner := COALESCE(idx.joiner, default_joiner);
186
187         SELECT INTO xfrm * from config.xml_transform WHERE name = idx.format;
188
189         -- See if we can skip the XSLT ... it's expensive
190         IF prev_xfrm IS NULL OR prev_xfrm <> xfrm.name THEN
191             -- Can't skip the transform
192             IF xfrm.xslt <> '---' THEN
193                 transformed_xml := oils_xslt_process(bib.marc,xfrm.xslt);
194             ELSE
195                 transformed_xml := bib.marc;
196             END IF;
197
198             prev_xfrm := xfrm.name;
199         END IF;
200
201         xml_node_list := oils_xpath( idx.xpath, transformed_xml, ARRAY[ARRAY[xfrm.prefix, xfrm.namespace_uri]] );
202
203         raw_text := NULL;
204         FOR xml_node IN SELECT x FROM unnest(xml_node_list) AS x LOOP
205             CONTINUE WHEN xml_node !~ E'^\\s*<';
206
207             -- XXX much of this should be moved into oils_xpath_string...
208             curr_text := ARRAY_TO_STRING(evergreen.array_remove_item_by_value(evergreen.array_remove_item_by_value(
209                 oils_xpath( '//text()', -- get the content of all the nodes within the main selected node
210                     REGEXP_REPLACE( xml_node, E'\\s+', ' ', 'g' ) -- Translate adjacent whitespace to a single space
211                 ), ' '), ''),  -- throw away morally empty (bankrupt?) strings
212                 joiner
213             );
214
215             CONTINUE WHEN curr_text IS NULL OR curr_text = '';
216
217             IF raw_text IS NOT NULL THEN
218                 raw_text := raw_text || joiner;
219             END IF;
220
221             raw_text := COALESCE(raw_text,'') || curr_text;
222
223             -- autosuggest/metabib.browse_entry
224             IF idx.browse_field THEN
225
226                 IF idx.browse_xpath IS NOT NULL AND idx.browse_xpath <> '' THEN
227                     browse_text := oils_xpath_string( idx.browse_xpath, xml_node, joiner, ARRAY[ARRAY[xfrm.prefix, xfrm.namespace_uri]] );
228                 ELSE
229                     browse_text := curr_text;
230                 END IF;
231
232                 IF idx.browse_sort_xpath IS NOT NULL AND
233                     idx.browse_sort_xpath <> '' THEN
234
235                     sort_value := oils_xpath_string(
236                         idx.browse_sort_xpath, xml_node, joiner,
237                         ARRAY[ARRAY[xfrm.prefix, xfrm.namespace_uri]]
238                     );
239                 ELSE
240                     sort_value := browse_text;
241                 END IF;
242
243                 output_row.field_class = idx.field_class;
244                 output_row.field = idx.id;
245                 output_row.source = rid;
246                 output_row.value = BTRIM(REGEXP_REPLACE(browse_text, E'\\s+', ' ', 'g'));
247                 output_row.sort_value :=
248                     public.naco_normalize(sort_value);
249
250                 output_row.authority := NULL;
251
252                 IF idx.authority_xpath IS NOT NULL AND idx.authority_xpath <> '' THEN
253                     authority_text := oils_xpath_string(
254                         idx.authority_xpath, xml_node, joiner,
255                         ARRAY[
256                             ARRAY[xfrm.prefix, xfrm.namespace_uri],
257                             ARRAY['xlink','http://www.w3.org/1999/xlink']
258                         ]
259                     );
260
261                     IF authority_text ~ '^\d+$' THEN
262                         authority_link := authority_text::BIGINT;
263                         PERFORM * FROM authority.record_entry WHERE id = authority_link;
264                         IF FOUND THEN
265                             output_row.authority := authority_link;
266                         END IF;
267                     END IF;
268
269                 END IF;
270
271                 output_row.browse_field = TRUE;
272                 -- Returning browse rows with search_field = true for search+browse
273                 -- configs allows us to retain granularity of being able to search
274                 -- browse fields with "starts with" type operators (for example, for
275                 -- titles of songs in music albums)
276                 IF idx.search_field THEN
277                     output_row.search_field = TRUE;
278                 END IF;
279                 RETURN NEXT output_row;
280                 output_row.browse_field = FALSE;
281                 output_row.search_field = FALSE;
282                 output_row.sort_value := NULL;
283             END IF;
284
285             -- insert raw node text for faceting
286             IF idx.facet_field THEN
287
288                 IF idx.facet_xpath IS NOT NULL AND idx.facet_xpath <> '' THEN
289                     facet_text := oils_xpath_string( idx.facet_xpath, xml_node, joiner, ARRAY[ARRAY[xfrm.prefix, xfrm.namespace_uri]] );
290                 ELSE
291                     facet_text := curr_text;
292                 END IF;
293
294                 output_row.field_class = idx.field_class;
295                 output_row.field = -1 * idx.id;
296                 output_row.source = rid;
297                 output_row.value = BTRIM(REGEXP_REPLACE(facet_text, E'\\s+', ' ', 'g'));
298
299                 output_row.facet_field = TRUE;
300                 RETURN NEXT output_row;
301                 output_row.facet_field = FALSE;
302             END IF;
303
304             -- insert raw node text for display
305             IF idx.display_field THEN
306
307                 IF idx.display_xpath IS NOT NULL AND idx.display_xpath <> '' THEN
308                     display_text := oils_xpath_string( idx.display_xpath, xml_node, joiner, ARRAY[ARRAY[xfrm.prefix, xfrm.namespace_uri]] );
309                 ELSE
310                     display_text := curr_text;
311                 END IF;
312
313                 output_row.field_class = idx.field_class;
314                 output_row.field = -1 * idx.id;
315                 output_row.source = rid;
316                 output_row.value = BTRIM(REGEXP_REPLACE(display_text, E'\\s+', ' ', 'g'));
317
318                 output_row.display_field = TRUE;
319                 RETURN NEXT output_row;
320                 output_row.display_field = FALSE;
321             END IF;
322
323         END LOOP;
324
325         CONTINUE WHEN raw_text IS NULL OR raw_text = '';
326
327         -- insert combined node text for searching
328         IF idx.search_field THEN
329             output_row.field_class = idx.field_class;
330             output_row.field = idx.id;
331             output_row.source = rid;
332             output_row.value = BTRIM(REGEXP_REPLACE(raw_text, E'\\s+', ' ', 'g'));
333
334             output_row.search_field = TRUE;
335             RETURN NEXT output_row;
336             output_row.search_field = FALSE;
337         END IF;
338
339     END LOOP;
340
341 END;
342
343 $func$ LANGUAGE PLPGSQL;
344
345 CREATE OR REPLACE FUNCTION metabib.reingest_metabib_field_entries( 
346     bib_id BIGINT,
347     skip_facet BOOL DEFAULT FALSE, 
348     skip_display BOOL DEFAULT FALSE,
349     skip_browse BOOL DEFAULT FALSE, 
350     skip_search BOOL DEFAULT FALSE,
351     only_fields INT[] DEFAULT '{}'::INT[]
352 ) RETURNS VOID AS $func$
353 DECLARE
354     fclass          RECORD;
355     ind_data        metabib.field_entry_template%ROWTYPE;
356     mbe_row         metabib.browse_entry%ROWTYPE;
357     mbe_id          BIGINT;
358     b_skip_facet    BOOL;
359     b_skip_display    BOOL;
360     b_skip_browse   BOOL;
361     b_skip_search   BOOL;
362     value_prepped   TEXT;
363     field_list      INT[] := only_fields;
364     field_types     TEXT[] := '{}'::TEXT[];
365 BEGIN
366
367     IF field_list = '{}'::INT[] THEN
368         SELECT ARRAY_AGG(id) INTO field_list FROM config.metabib_field;
369     END IF;
370
371     SELECT COALESCE(NULLIF(skip_facet, FALSE), EXISTS (SELECT enabled FROM config.internal_flag WHERE name =  'ingest.skip_facet_indexing' AND enabled)) INTO b_skip_facet;
372     SELECT COALESCE(NULLIF(skip_display, FALSE), EXISTS (SELECT enabled FROM config.internal_flag WHERE name =  'ingest.skip_display_indexing' AND enabled)) INTO b_skip_display;
373     SELECT COALESCE(NULLIF(skip_browse, FALSE), EXISTS (SELECT enabled FROM config.internal_flag WHERE name =  'ingest.skip_browse_indexing' AND enabled)) INTO b_skip_browse;
374     SELECT COALESCE(NULLIF(skip_search, FALSE), EXISTS (SELECT enabled FROM config.internal_flag WHERE name =  'ingest.skip_search_indexing' AND enabled)) INTO b_skip_search;
375
376     IF NOT b_skip_facet THEN field_types := field_types || '{facet}'; END IF;
377     IF NOT b_skip_display THEN field_types := field_types || '{display}'; END IF;
378     IF NOT b_skip_browse THEN field_types := field_types || '{browse}'; END IF;
379     IF NOT b_skip_search THEN field_types := field_types || '{search}'; END IF;
380
381     PERFORM * FROM config.internal_flag WHERE name = 'ingest.assume_inserts_only' AND enabled;
382     IF NOT FOUND THEN
383         IF NOT b_skip_search THEN
384             FOR fclass IN SELECT * FROM config.metabib_class LOOP
385                 -- RAISE NOTICE 'Emptying out %', fclass.name;
386                 EXECUTE $$DELETE FROM metabib.$$ || fclass.name || $$_field_entry WHERE source = $$ || bib_id;
387             END LOOP;
388         END IF;
389         IF NOT b_skip_facet THEN
390             DELETE FROM metabib.facet_entry WHERE source = bib_id;
391         END IF;
392         IF NOT b_skip_display THEN
393             DELETE FROM metabib.display_entry WHERE source = bib_id;
394         END IF;
395         IF NOT b_skip_browse THEN
396             DELETE FROM metabib.browse_entry_def_map WHERE source = bib_id;
397         END IF;
398     END IF;
399
400     FOR ind_data IN SELECT * FROM biblio.extract_metabib_field_entry( bib_id, ' ', field_types, field_list ) LOOP
401
402         -- don't store what has been normalized away
403         CONTINUE WHEN ind_data.value IS NULL;
404
405         IF ind_data.field < 0 THEN
406             ind_data.field = -1 * ind_data.field;
407         END IF;
408
409         IF ind_data.facet_field AND NOT b_skip_facet THEN
410             INSERT INTO metabib.facet_entry (field, source, value)
411                 VALUES (ind_data.field, ind_data.source, ind_data.value);
412         END IF;
413
414         IF ind_data.display_field AND NOT b_skip_display THEN
415             INSERT INTO metabib.display_entry (field, source, value)
416                 VALUES (ind_data.field, ind_data.source, ind_data.value);
417         END IF;
418
419
420         IF ind_data.browse_field AND NOT b_skip_browse THEN
421             -- A caveat about this SELECT: this should take care of replacing
422             -- old mbe rows when data changes, but not if normalization (by
423             -- which I mean specifically the output of
424             -- evergreen.oils_tsearch2()) changes.  It may or may not be
425             -- expensive to add a comparison of index_vector to index_vector
426             -- to the WHERE clause below.
427
428             CONTINUE WHEN ind_data.sort_value IS NULL;
429
430             value_prepped := metabib.browse_normalize(ind_data.value, ind_data.field);
431             SELECT INTO mbe_row * FROM metabib.browse_entry
432                 WHERE value = value_prepped AND sort_value = ind_data.sort_value;
433
434             IF FOUND THEN
435                 mbe_id := mbe_row.id;
436             ELSE
437                 INSERT INTO metabib.browse_entry
438                     ( value, sort_value ) VALUES
439                     ( value_prepped, ind_data.sort_value );
440
441                 mbe_id := CURRVAL('metabib.browse_entry_id_seq'::REGCLASS);
442             END IF;
443
444             INSERT INTO metabib.browse_entry_def_map (entry, def, source, authority)
445                 VALUES (mbe_id, ind_data.field, ind_data.source, ind_data.authority);
446         END IF;
447
448         IF ind_data.search_field AND NOT b_skip_search THEN
449             -- Avoid inserting duplicate rows
450             EXECUTE 'SELECT 1 FROM metabib.' || ind_data.field_class ||
451                 '_field_entry WHERE field = $1 AND source = $2 AND value = $3'
452                 INTO mbe_id USING ind_data.field, ind_data.source, ind_data.value;
453                 -- RAISE NOTICE 'Search for an already matching row returned %', mbe_id;
454             IF mbe_id IS NULL THEN
455                 EXECUTE $$
456                 INSERT INTO metabib.$$ || ind_data.field_class || $$_field_entry (field, source, value)
457                     VALUES ($$ ||
458                         quote_literal(ind_data.field) || $$, $$ ||
459                         quote_literal(ind_data.source) || $$, $$ ||
460                         quote_literal(ind_data.value) ||
461                     $$);$$;
462             END IF;
463         END IF;
464
465     END LOOP;
466
467     IF NOT b_skip_search THEN
468         PERFORM metabib.update_combined_index_vectors(bib_id);
469     END IF;
470
471     RETURN;
472 END;
473 $func$ LANGUAGE PLPGSQL;
474
475 -- AFTER UPDATE OR INSERT trigger for biblio.record_entry
476 CREATE OR REPLACE FUNCTION biblio.indexing_ingest_or_delete () RETURNS TRIGGER AS $func$
477 DECLARE
478     tmp_bool BOOL;
479 BEGIN
480
481     IF NEW.deleted THEN -- If this bib is deleted
482
483         PERFORM * FROM config.internal_flag WHERE
484             name = 'ingest.metarecord_mapping.preserve_on_delete' AND enabled;
485
486         tmp_bool := FOUND; -- Just in case this is changed by some other statement
487
488         PERFORM metabib.remap_metarecord_for_bib( NEW.id, NEW.fingerprint, TRUE, tmp_bool );
489
490         IF NOT tmp_bool THEN
491             -- One needs to keep these around to support searches
492             -- with the #deleted modifier, so one should turn on the named
493             -- internal flag for that functionality.
494             DELETE FROM metabib.record_attr_vector_list WHERE source = NEW.id;
495         END IF;
496
497         DELETE FROM authority.bib_linking WHERE bib = NEW.id; -- Avoid updating fields in bibs that are no longer visible
498         DELETE FROM biblio.peer_bib_copy_map WHERE peer_record = NEW.id; -- Separate any multi-homed items
499         DELETE FROM metabib.browse_entry_def_map WHERE source = NEW.id; -- Don't auto-suggest deleted bibs
500         RETURN NEW; -- and we're done
501     END IF;
502
503     IF TG_OP = 'UPDATE' THEN -- re-ingest?
504         PERFORM * FROM config.internal_flag WHERE name = 'ingest.reingest.force_on_same_marc' AND enabled;
505
506         IF NOT FOUND AND OLD.marc = NEW.marc THEN -- don't do anything if the MARC didn't change
507             RETURN NEW;
508         END IF;
509     END IF;
510
511     -- Record authority linking
512     PERFORM * FROM config.internal_flag WHERE name = 'ingest.disable_authority_linking' AND enabled;
513     IF NOT FOUND THEN
514         PERFORM biblio.map_authority_linking( NEW.id, NEW.marc );
515     END IF;
516
517     -- Flatten and insert the mfr data
518     PERFORM * FROM config.internal_flag WHERE name = 'ingest.disable_metabib_full_rec' AND enabled;
519     IF NOT FOUND THEN
520         PERFORM metabib.reingest_metabib_full_rec(NEW.id);
521
522         -- Now we pull out attribute data, which is dependent on the mfr for all but XPath-based fields
523         PERFORM * FROM config.internal_flag WHERE name = 'ingest.disable_metabib_rec_descriptor' AND enabled;
524         IF NOT FOUND THEN
525             PERFORM metabib.reingest_record_attributes(NEW.id, NULL, NEW.marc, TG_OP = 'INSERT' OR OLD.deleted);
526         END IF;
527     END IF;
528
529     -- Gather and insert the field entry data
530     PERFORM metabib.reingest_metabib_field_entries(NEW.id);
531
532     -- Located URI magic
533     PERFORM * FROM config.internal_flag WHERE name = 'ingest.disable_located_uri' AND enabled;
534     IF NOT FOUND THEN PERFORM biblio.extract_located_uris( NEW.id, NEW.marc, NEW.editor ); END IF;
535
536     -- (re)map metarecord-bib linking
537     IF TG_OP = 'INSERT' THEN -- if not deleted and performing an insert, check for the flag
538         PERFORM * FROM config.internal_flag WHERE name = 'ingest.metarecord_mapping.skip_on_insert' AND enabled;
539         IF NOT FOUND THEN
540             PERFORM metabib.remap_metarecord_for_bib( NEW.id, NEW.fingerprint );
541         END IF;
542     ELSE -- we're doing an update, and we're not deleted, remap
543         PERFORM * FROM config.internal_flag WHERE name = 'ingest.metarecord_mapping.skip_on_update' AND enabled;
544         IF NOT FOUND THEN
545             PERFORM metabib.remap_metarecord_for_bib( NEW.id, NEW.fingerprint );
546         END IF;
547     END IF;
548
549     RETURN NEW;
550 END;
551 $func$ LANGUAGE PLPGSQL;
552
553 COMMIT;
554