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