--- /dev/null
+BEGIN;
+
+-- SELECT evergreen.upgrade_deps_block_check('TODO', :eg_version);
+
+-- EDITION -----
+INSERT INTO config.metabib_field
+ (id, field_class, name, label, xpath, display_field)
+VALUES (
+ 38, 'identifier', 'edition',
+ oils_i18n_gettext(38, 'Edition', 'cmf', 'label'),
+ $$//mods33:mods/mods33:originInfo//mods33:edition[1]$$,
+ TRUE
+);
+INSERT INTO config.display_field_map
+ (name, field, multi) VALUES ('edition', 38, FALSE);
+
+-- ISSN -----
+
+UPDATE config.metabib_field SET display_field = TRUE WHERE id = 19;
+INSERT INTO config.display_field_map
+ (name, field, multi) VALUES ('issn', 19, TRUE);
+
+-- UPC -----
+
+UPDATE config.metabib_field SET display_field = TRUE WHERE id = 20;
+INSERT INTO config.display_field_map
+ (name, field, multi) VALUES ('upc', 20, TRUE);
+
+-- Physical Description -----
+
+/* TODO: concatenate the phys desc fields into a single string,
+ since that's likely what the caller will do with it ? */
+INSERT INTO config.metabib_field
+ (id, field_class, name, label, xpath, display_field)
+VALUES (
+ 39, 'identifier', 'physical_description',
+ oils_i18n_gettext(39, 'Physical Descrption', 'cmf', 'label'),
+ $$(//mods33:mods/mods33:physicalDescription/mods33:form|//mods33:mods/mods33:physicalDescription/mods33:extent|//mods33:mods/mods33:physicalDescription/mods33:reformattingQuality|//mods33:mods/mods33:physicalDescription/mods33:internetMediaType|//mods33:mods/mods33:physicalDescription/mods33:digitalOrigin)$$,
+ TRUE
+);
+INSERT INTO config.display_field_map
+ (name, field, multi) VALUES ('physical_description', 39, TRUE);
+
+-- Publisher -----
+
+INSERT INTO config.metabib_field
+ (id, field_class, name, label, xpath, display_field)
+VALUES (
+ 40, 'identifier', 'publisher',
+ oils_i18n_gettext(40, 'Publisher', 'cmf', 'label'),
+ $$//mods33:mods/mods33:originInfo//mods33:publisher[1]$$,
+ TRUE
+);
+INSERT INTO config.display_field_map
+ (name, field, multi) VALUES ('publisher', 40, FALSE);
+
+-- Series -----
+
+UPDATE config.metabib_field SET display_field = TRUE WHERE id = 1;
+INSERT INTO config.display_field_map
+ (name, field, multi) VALUES ('seriestitle', 1, FALSE);
+
+-- Add a column to wide-display-entry per well-known field
+
+DROP VIEW metabib.wide_display_entry;
+CREATE VIEW metabib.wide_display_entry AS
+ SELECT
+ bre.id AS source,
+ COALESCE(mcde_title.value, 'null') AS title,
+ COALESCE(mcde_author.value, 'null') AS author,
+ COALESCE(mcde_subject.value, 'null') AS subject,
+ COALESCE(mcde_creators.value, 'null') AS creators,
+ COALESCE(mcde_isbn.value, 'null') AS isbn,
+ COALESCE(mcde_issn.value, 'null') AS issn,
+ COALESCE(mcde_upc.value, 'null') AS upc,
+ COALESCE(mcde_edition.value, 'null') AS edition,
+ COALESCE(mcde_physical_description.value, 'null') AS physical_description,
+ COALESCE(mcde_publisher.value, 'null') AS publisher,
+ COALESCE(mcde_seriestitle.value, 'null') AS seriestitle
+ FROM biblio.record_entry bre
+ LEFT JOIN metabib.compressed_display_entry mcde_title
+ ON (bre.id = mcde_title.source AND mcde_title.name = 'title')
+ LEFT JOIN metabib.compressed_display_entry mcde_author
+ ON (bre.id = mcde_author.source AND mcde_author.name = 'author')
+ LEFT JOIN metabib.compressed_display_entry mcde_subject
+ ON (bre.id = mcde_subject.source AND mcde_subject.name = 'subject')
+ LEFT JOIN metabib.compressed_display_entry mcde_creators
+ ON (bre.id = mcde_creators.source AND mcde_creators.name = 'creators')
+ LEFT JOIN metabib.compressed_display_entry mcde_isbn
+ ON (bre.id = mcde_isbn.source AND mcde_isbn.name = 'isbn')
+ LEFT JOIN metabib.compressed_display_entry mcde_issn
+ ON (bre.id = mcde_issn.source AND mcde_issn.name = 'issn')
+ LEFT JOIN metabib.compressed_display_entry mcde_upc
+ ON (bre.id = mcde_upc.source AND mcde_upc.name = 'upc')
+ LEFT JOIN metabib.compressed_display_entry mcde_edition
+ ON (bre.id = mcde_edition.source AND mcde_edition.name = 'edition')
+ LEFT JOIN metabib.compressed_display_entry mcde_physical_description
+ ON (bre.id = mcde_physical_description.source
+ AND mcde_physical_description.name = 'physical_description')
+ LEFT JOIN metabib.compressed_display_entry mcde_publisher
+ ON (bre.id = mcde_publisher.source AND mcde_publisher.name = 'publisher')
+ LEFT JOIN metabib.compressed_display_entry mcde_seriestitle
+ ON (bre.id = mcde_seriestitle.source AND mcde_seriestitle.name = 'seriestitle')
+;
+
+COMMIT;
+
+/** ROLLBACK
+
+BEGIN;
+DELETE FROM metabib.display_entry WHERE field IN (1,19,20,38,39,40);
+DELETE FROM config.display_field_map WHERE field IN (1,19,20,38,39,40);
+DELETE FROM config.metabib_field WHERE id IN (38,39,40);
+COMMIT;
+
+*/
+
+-- Perform a full display field reingest, since we didn't do one during
+-- the 3.0 upgrade when display fields were introduced.
+
+\qecho
+\qecho Reingesting display field entries. This may take a while.
+\qecho This command can be stopped (control-c) and rerun later if needed:
+\qecho SELECT metabib.reingest_metabib_field_entries(id, TRUE, FALSE, TRUE, TRUE,
+\qecho (SELECT ARRAY_AGG(id)::INT[] FROM config.metabib_field WHERE display_field))
+\qecho FROM biblio.record_entry WHERE NOT deleted AND id > 0;
+\qecho
+
+-- avoid displaying a row per entry by selecting the total count.
+SELECT COUNT(*) AS bib_count FROM (
+ SELECT metabib.reingest_metabib_field_entries(id, TRUE, FALSE, TRUE, TRUE,
+ (SELECT ARRAY_AGG(id)::INT[] FROM config.metabib_field WHERE display_field))
+ FROM biblio.record_entry WHERE NOT deleted AND id > 0
+) x;
+