From 054027e6340baf5d2f7e58287ed6e1253cab4382 Mon Sep 17 00:00:00 2001 From: Bill Erickson Date: Thu, 14 Nov 2013 16:58:54 -0500 Subject: [PATCH] LP#1251394 Display fields schema/IDL continued * Upgrade SQL repairs * make display fields field-safe * Representative fields Signed-off-by: Bill Erickson Signed-off-by: Mike Rylander --- Open-ILS/examples/fm_IDL.xml | 23 +++-- Open-ILS/src/sql/Pg/002.schema.config.sql | 16 ++++ Open-ILS/src/sql/Pg/950.data.seed-values.sql | 4 +- .../upgrade/XXXX.schema.metabib-display-field.sql | 98 ++++++++++++++++++---- 4 files changed, 113 insertions(+), 28 deletions(-) diff --git a/Open-ILS/examples/fm_IDL.xml b/Open-ILS/examples/fm_IDL.xml index a1ab64f722..f4c7d6d4cd 100644 --- a/Open-ILS/examples/fm_IDL.xml +++ b/Open-ILS/examples/fm_IDL.xml @@ -2810,10 +2810,12 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA + + @@ -3720,6 +3722,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA @@ -3739,17 +3742,20 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA - SELECT - mde.source, - mde.value, + SELECT + mde.source, + mde.value, cmf.id AS field, - cmf.field_class, - cmf.name, - cmf.label - FROM metabib.display_entry mde - JOIN config.metabib_field cmf ON (cmf.id = mde.field) + cmf.field_class, + cmf.name, + cmf.label, + cmc.name AS representative + FROM metabib.display_entry mde + JOIN config.metabib_field cmf ON (cmf.id = mde.field) LEFT JOIN config.metabib_class cmc ON + (cmc.name = cmf.field_class AND cmc.representative_field = cmf.id) @@ -3758,6 +3764,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA + diff --git a/Open-ILS/src/sql/Pg/002.schema.config.sql b/Open-ILS/src/sql/Pg/002.schema.config.sql index e8f3f24673..a7fc62b15e 100644 --- a/Open-ILS/src/sql/Pg/002.schema.config.sql +++ b/Open-ILS/src/sql/Pg/002.schema.config.sql @@ -183,6 +183,16 @@ INSERT INTO config.biblio_fingerprint (name, xpath, format) 'mods32' ); +CREATE OR REPLACE FUNCTION + config.metabib_representative_field_is_valid(INTEGER, TEXT) RETURNS BOOLEAN AS $$ + SELECT EXISTS (SELECT 1 FROM config.metabib_field WHERE id = $1 AND field_class = $2); +$$ LANGUAGE SQL STRICT IMMUTABLE; + +COMMENT ON FUNCTION config.metabib_representative_field_is_valid(INTEGER, TEXT) IS $$ +Ensure the field_class value on the selected representative field matches +the class name. +$$; + CREATE TABLE config.metabib_class ( name TEXT PRIMARY KEY, label TEXT NOT NULL UNIQUE, @@ -193,6 +203,12 @@ CREATE TABLE config.metabib_class ( b_weight NUMERIC DEFAULT 0.4 NOT NULL, c_weight NUMERIC DEFAULT 0.2 NOT NULL, d_weight NUMERIC DEFAULT 0.1 NOT NULL + representative_field INTEGER REFERENCES config.metabib_field(id), + CONSTRAINT rep_field_unique UNIQUE(representative_field), + CONSTRAINT rep_field_is_valid CHECK ( + representative_field IS NULL OR + config.metabib_representative_field_is_valid(representative_field, name) + ) ); CREATE TABLE config.metabib_field ( diff --git a/Open-ILS/src/sql/Pg/950.data.seed-values.sql b/Open-ILS/src/sql/Pg/950.data.seed-values.sql index 75518259cb..360397b9ab 100644 --- a/Open-ILS/src/sql/Pg/950.data.seed-values.sql +++ b/Open-ILS/src/sql/Pg/950.data.seed-values.sql @@ -96,8 +96,8 @@ SELECT SETVAL('config.standing_penalty_id_seq', 100); INSERT INTO config.metabib_class ( name, label ) VALUES ( 'identifier', oils_i18n_gettext('identifier', 'Identifier', 'cmc', 'label') ); INSERT INTO config.metabib_class ( name, label ) VALUES ( 'keyword', oils_i18n_gettext('keyword', 'Keyword', 'cmc', 'label') ); -INSERT INTO config.metabib_class ( name, label ) VALUES ( 'title', oils_i18n_gettext('title', 'Title', 'cmc', 'label') ); -INSERT INTO config.metabib_class ( name, label ) VALUES ( 'author', oils_i18n_gettext('author', 'Author', 'cmc', 'label') ); +INSERT INTO config.metabib_class ( name, label, representative_field ) VALUES ( 'title', oils_i18n_gettext('title', 'Title', 'cmc', 'label'), 6 ); +INSERT INTO config.metabib_class ( name, label, representative_field ) VALUES ( 'author', oils_i18n_gettext('author', 'Author', 'cmc', 'label'), 8 ); INSERT INTO config.metabib_class ( name, label ) VALUES ( 'subject', oils_i18n_gettext('subject', 'Subject', 'cmc', 'label') ); INSERT INTO config.metabib_class ( name, label ) VALUES ( 'series', oils_i18n_gettext('series', 'Series', 'cmc', 'label') ); diff --git a/Open-ILS/src/sql/Pg/upgrade/XXXX.schema.metabib-display-field.sql b/Open-ILS/src/sql/Pg/upgrade/XXXX.schema.metabib-display-field.sql index 9d20e593c9..775b5ebf59 100644 --- a/Open-ILS/src/sql/Pg/upgrade/XXXX.schema.metabib-display-field.sql +++ b/Open-ILS/src/sql/Pg/upgrade/XXXX.schema.metabib-display-field.sql @@ -1,8 +1,28 @@ BEGIN; -ALTER TABLE config.metabib_field ADD COLUMN display_xpath TEXT, display_field BOOL NOT NULL DEFAULT TRUE; -UPDATE config.metabib_field SET display_field = FALSE WHERE field_class = 'keyword' OR name = 'complete'; +ALTER TABLE config.metabib_field + ADD COLUMN display_xpath TEXT, + ADD COLUMN display_field BOOL NOT NULL DEFAULT TRUE; + +CREATE OR REPLACE FUNCTION + config.metabib_representative_field_is_valid(INTEGER, TEXT) RETURNS BOOLEAN AS $$ + SELECT EXISTS (SELECT 1 FROM config.metabib_field WHERE id = $1 AND field_class = $2); +$$ LANGUAGE SQL STRICT IMMUTABLE; + +COMMENT ON FUNCTION config.metabib_representative_field_is_valid(INTEGER, TEXT) IS $$ +Ensure the field_class value on the selected representative field matches +the class name. +$$; + +ALTER TABLE config.metabib_class + ADD COLUMN representative_field + INTEGER REFERENCES config.metabib_field(id), + ADD CONSTRAINT rep_field_unique UNIQUE(representative_field), + ADD CONSTRAINT rep_field_is_valid CHECK ( + representative_field IS NULL OR + config.metabib_representative_field_is_valid(representative_field, name) + ); CREATE TABLE metabib.display_entry ( id BIGSERIAL PRIMARY KEY, @@ -67,9 +87,6 @@ CREATE TRIGGER display_field_force_nfc_tgr BEFORE UPDATE OR INSERT ON metabib.display_entry FOR EACH ROW EXECUTE PROCEDURE evergreen.display_field_force_nfc(); -ALTER TABLE config.metabib_field - ADD COLUMN display_field BOOL NOT NULL DEFAULT TRUE; - ALTER TYPE metabib.field_entry_template ADD ATTRIBUTE display_field BOOL; CREATE OR REPLACE FUNCTION biblio.extract_metabib_field_entry ( rid BIGINT, default_joiner TEXT ) RETURNS SETOF metabib.field_entry_template AS $func$ @@ -392,23 +409,68 @@ END; $func$ LANGUAGE PLPGSQL; --- DATA ------------------- +-- DATA -------------------------------------- --- "General Keywords" and "All Subjects" --- more? -UPDATE config.metabib_field SET display_field = FALSE WHERE id IN (15, 16); +UPDATE config.metabib_field SET display_field = FALSE + WHERE field_class = 'keyword' OR name = 'complete'; INSERT INTO config.internal_flag (name, enabled) VALUES ('ingest.skip_display_indexing', FALSE); --- TODO: targeted ingest? - --- Dumb Reingest --- ---UPDATE config.internal_flag SET enabled = TRUE --- WHERE name = 'ingest.reingest.force_on_same_marc'; ---UPDATE biblio.record_entry SET marc = marc; ---UPDATE config.internal_flag SET enabled = FALSE --- WHERE name = 'ingest.reingest.force_on_same_marc'; +-- personal author +UPDATE config.metabib_class SET representative_field = 8 WHERE name = 'author'; +-- title proper +UPDATE config.metabib_class SET representative_field = 6 WHERE name = 'title'; COMMIT; ---ROLLBACK; + + +/* +-- Ham-fisted reingest for Testing --------------------- + +-- disable everything we can for reindexing +UPDATE config.internal_flag SET enabled = TRUE WHERE name IN ( + 'ingest.assume_inserts_only', + 'ingest.disable_authority_auto_update', + 'ingest.disable_authority_linking', + 'ingest.disable_located_uri', + 'ingest.disable_metabib_field_entry', + 'ingest.disable_metabib_full_rec', + 'ingest.disable_metabib_rec_descriptor', + 'ingest.metarecord_mapping.preserve_on_delete', + 'ingest.metarecord_mapping.skip_on_insert', + 'ingest.metarecord_mapping.skip_on_update', + 'ingest.reingest.force_on_same_marc', + 'ingest.skip_browse_indexing', + 'ingest.skip_facet_indexing', + 'ingest.skip_search_indexing' +); + +UPDATE config.internal_flag SET enabled = TRUE + WHERE name = 'ingest.reingest.force_on_same_marc'; + +UPDATE biblio.record_entry SET marc = marc; + +UPDATE config.internal_flag SET enabled = FALSE + WHERE name = 'ingest.reingest.force_on_same_marc'; + +-- re-enable the default ingest flags +UPDATE config.internal_flag SET enabled = FALSE WHERE name IN ( + 'ingest.assume_inserts_only', + 'ingest.disable_authority_auto_update', + 'ingest.disable_authority_linking', + 'ingest.disable_located_uri', + 'ingest.disable_metabib_field_entry', + 'ingest.disable_metabib_full_rec', + 'ingest.disable_metabib_rec_descriptor', + 'ingest.metarecord_mapping.preserve_on_delete', + 'ingest.metarecord_mapping.skip_on_insert', + 'ingest.metarecord_mapping.skip_on_update', + 'ingest.reingest.force_on_same_marc', + 'ingest.skip_browse_indexing', + 'ingest.skip_facet_indexing', + 'ingest.skip_search_indexing' +); + +*/ + -- 2.11.0