From: Dan Wells Date: Fri, 20 Feb 2015 19:37:51 +0000 (-0500) Subject: LP#1251394 Fix DB order of operations X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=a7569731e26be4a563a643bb50e746fdf9c113c5;p=working%2FEvergreen.git LP#1251394 Fix DB order of operations 'representative_field' (and its check function) create circular references between metabib_class and metabib_field. The most straightforward fix is to deal with those fields separate from the initial table creation and field insertion. Signed-off-by: Dan Wells --- diff --git a/Open-ILS/src/sql/Pg/002.schema.config.sql b/Open-ILS/src/sql/Pg/002.schema.config.sql index 70f0a4a040..382a6bfc03 100644 --- a/Open-ILS/src/sql/Pg/002.schema.config.sql +++ b/Open-ILS/src/sql/Pg/002.schema.config.sql @@ -169,16 +169,6 @@ INSERT INTO config.biblio_fingerprint (name, xpath, format, first_word) 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. -$$; - CREATE TABLE config.metabib_class ( name TEXT PRIMARY KEY, label TEXT NOT NULL UNIQUE, @@ -189,12 +179,6 @@ 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 ( @@ -226,6 +210,26 @@ a "class" of either title, subject, author, keyword, series or identifier. $$; +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 UNIQUE INDEX config_metabib_field_class_name_idx ON config.metabib_field (field_class, name); CREATE TABLE config.ts_config_list ( 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 e6982aaacc..4f0ebb2c0e 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, 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 ( '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 ) 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') ); @@ -126,11 +126,13 @@ INSERT INTO config.metabib_field ( id, field_class, name, label, format, xpath, (5, 'title', 'uniform', oils_i18n_gettext(5, 'Uniform Title', 'cmf', 'label'), 'mods32', $$//mods32:mods/mods32:titleInfo[mods32:title and (@type='uniform-nfi')]$$, '//@xlink:href', $$*[local-name() != "nonSort"]$$ ); INSERT INTO config.metabib_field ( id, field_class, name, label, format, xpath, authority_xpath, browse_field ) VALUES (6, 'title', 'proper', oils_i18n_gettext(6, 'Title Proper', 'cmf', 'label'), 'mods32', $$//mods32:mods/mods32:titleNonfiling[mods32:title and not (@type)]$$, '//@xlink:href', FALSE ); +UPDATE config.metabib_class SET representative_field = 6 WHERE name = 'title'; INSERT INTO config.metabib_field ( id, field_class, name, label, format, xpath, facet_xpath, facet_field , authority_xpath, browse_xpath) VALUES (7, 'author', 'corporate', oils_i18n_gettext(7, 'Corporate Author', 'cmf', 'label'), 'mods32', $$//mods32:mods/mods32:name[@type='corporate' and (mods32:role/mods32:roleTerm[text()='creator'] or mods32:role/mods32:roleTerm[text()='aut'] or mods32:role/mods32:roleTerm[text()='cre'])]$$, $$//*[local-name()='namePart']$$, TRUE, '//@xlink:href',$$//*[local-name()='namePart']$$ ); -- /* to fool vim */; INSERT INTO config.metabib_field ( id, field_class, name, label, format, xpath, facet_xpath, facet_field, authority_xpath, browse_xpath ) VALUES (8, 'author', 'personal', oils_i18n_gettext(8, 'Personal Author', 'cmf', 'label'), 'mods32', $$//mods32:mods/mods32:name[@type='personal' and mods32:role/mods32:roleTerm[text()='creator']]$$, $$//*[local-name()='namePart']$$, TRUE, '//@xlink:href',$$//*[local-name()='namePart']$$ ); -- /* to fool vim */; +UPDATE config.metabib_class SET representative_field = 8 WHERE name = 'author'; INSERT INTO config.metabib_field ( id, field_class, name, label, format, xpath, facet_xpath, facet_field, authority_xpath, browse_xpath ) VALUES (9, 'author', 'conference', oils_i18n_gettext(9, 'Conference Author', 'cmf', 'label'), 'mods32', $$//mods32:mods/mods32:name[@type='conference' and mods32:role/mods32:roleTerm[text()='creator']]$$, $$//*[local-name()='namePart']$$, TRUE, '//@xlink:href',$$//*[local-name()='namePart']$$ ); -- /* to fool vim */; INSERT INTO config.metabib_field ( id, field_class, name, label, format, xpath, facet_xpath, facet_field, authority_xpath, browse_xpath ) VALUES