LP#1251394 Display fields schema/IDL continued
authorBill Erickson <berick@esilibrary.com>
Thu, 14 Nov 2013 21:58:54 +0000 (16:58 -0500)
committerMike Rylander <mrylander@gmail.com>
Fri, 1 Sep 2017 21:17:47 +0000 (17:17 -0400)
* Upgrade SQL repairs
* make display fields field-safe
* Representative fields

Signed-off-by: Bill Erickson <berick@esilibrary.com>
Signed-off-by: Mike Rylander <mrylander@gmail.com>
Open-ILS/examples/fm_IDL.xml
Open-ILS/src/sql/Pg/002.schema.config.sql
Open-ILS/src/sql/Pg/950.data.seed-values.sql
Open-ILS/src/sql/Pg/upgrade/XXXX.schema.metabib-display-field.sql

index a1ab64f..f4c7d6d 100644 (file)
@@ -2810,10 +2810,12 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
                        <field reporter:label="B Weight" name="b_weight" reporter:datatype="float" />
                        <field reporter:label="C Weight" name="c_weight" reporter:datatype="float" />
                        <field reporter:label="D Weight" name="d_weight" reporter:datatype="float" />
+                       <field reporter:label="Representative Field" name="representative_field" reporter:datatype="link" />
                        <field reporter:label="Fields" name="fields" reporter:datatype="link" oils_persist:virtual="true"/>
                </fields>
                <links>
                        <link field="fields" reltype="has_many" key="name" map="" class="cmf"/>
+                       <link field="representative_field" reltype="has_a" key="id" map="" class="cmf"/>
                </links>
         <permacrud xmlns="http://open-ils.org/spec/opensrf/IDL/permacrud/v1">
             <actions>
@@ -3720,6 +3722,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
        <class id="mde" controller="open-ils.cstore open-ils.pcrud" 
                        oils_obj:fieldmapper="metabib::display_entry" 
                        oils_persist:tablename="metabib.display_entry" 
+                       oils_persist:field_safe="true"
                        reporter:label="Display Field Entry" oils_persist:readonly="true">
                <fields oils_persist:primary="id" oils_persist:sequence="metabib.display_entry_id_seq">
                        <field name="id" reporter:datatype="id" />
@@ -3739,17 +3742,20 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
        </class>
        <class id="mfde" controller="open-ils.cstore open-ils.pcrud" 
                oils_obj:fieldmapper="metabib::flat_display_entry" 
+               oils_persist:field_safe="true"
                reporter:label="Flat Display Field Entry View" oils_persist:readonly="true">
                <oils_persist:source_definition>
-                       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)
                </oils_persist:source_definition>
                <fields>
                        <field name="source" reporter:datatype="id" />
@@ -3758,6 +3764,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
                        <field name="field_class" reporter:datatype="text"/>
                        <field name="name" reporter:datatype="text"/>
                        <field name="label" reporter:datatype="text"/>
+                       <field name="representative" reporter:datatype="text"/>
                </fields>
                <links>
                        <link field="source" reltype="has_a" key="id" map="" class="bre"/>
index e8f3f24..a7fc62b 100644 (file)
@@ -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 (
index 7551825..360397b 100644 (file)
@@ -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') );
 
index 9d20e59..775b5eb 100644 (file)
@@ -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'
+);
+
+*/
+