MARC import tag stripping : SQL / IDL
authorBill Erickson <berick@esilibrary.com>
Wed, 27 Feb 2013 20:32:56 +0000 (15:32 -0500)
committerMike Rylander <mrylander@gmail.com>
Wed, 13 Mar 2013 20:34:34 +0000 (16:34 -0400)
* Adds a new table vandelay.import_bib_trash_group for grouping "trash"
  fields.  Groups may be optional or "always_apply".  Always-apply groups
  contain MARC fields which are to be unconditionally removed during
  import.

* Updates vandelay.import_bib_trash_fields for putting them into groups.

* IDL changes to accommodate the above

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/012.schema.vandelay.sql
Open-ILS/src/sql/Pg/upgrade/XXXX.schema.strip-marc-tags.sql [new file with mode: 0644]

index 1380f85..4d8a299 100644 (file)
@@ -216,10 +216,43 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
        <class id="vibtf" controller="open-ils.cstore open-ils.pcrud" oils_obj:fieldmapper="vandelay::import_bib_trash_fields" oils_persist:tablename="vandelay.import_bib_trash_fields" reporter:label="Import/Overlay Fields for Removal">
                <fields oils_persist:primary="id" oils_persist:sequence="vandelay.import_bib_trash_fields_id_seq">
                        <field reporter:label="Field ID" name="id" reporter:datatype="id"/>
-                       <field reporter:label="Owner" name="owner" reporter:datatype="link"/>
+                       <field reporter:label="Group" name="grp" reporter:datatype="link"/>
                        <field reporter:label="Field" name="field" reporter:datatype="text"/>
                </fields>
                <links>
+                       <link field="grp" reltype="has_a" key="id" map="" class="vibtg"/>
+               </links>
+               <permacrud xmlns="http://open-ils.org/spec/opensrf/IDL/permacrud/v1">
+                       <actions>
+                               <create permission="CREATE_IMPORT_TRASH_FIELD">
+                    <context link="grp" field="owner"/>
+                </create>
+                               <retrieve permission="CREATE_IMPORT_TRASH_FIELD UPDATE_IMPORT_TRASH_FIELD DELETE_IMPORT_TRASH_FIELD">
+                    <context link="grp" field="owner"/>
+                </retrieve>
+                               <update permission="UPDATE_IMPORT_TRASH_FIELD">
+                    <context link="grp" field="owner"/>
+                </update>
+                               <delete permission="DELETE_IMPORT_TRASH_FIELD">
+                    <context link="grp" field="owner"/>
+                </delete>
+                       </actions>
+               </permacrud>
+       </class>
+
+       <class  id="vibtg" 
+            controller="open-ils.cstore open-ils.pcrud" 
+            oils_obj:fieldmapper="vandelay::import_bib_trash_group" 
+            oils_persist:tablename="vandelay.import_bib_trash_group" 
+            reporter:label="Import/Overlay Field Groups for Removal">
+               <fields oils_persist:primary="id" 
+                oils_persist:sequence="vandelay.import_bib_trash_group_id_seq">
+                       <field reporter:label="ID" name="id" reporter:datatype="id" reporter:selector="name"/>
+                       <field reporter:label="Owner" name="owner" reporter:datatype="link"/>
+                       <field reporter:label="Label" name="label" reporter:datatype="text"/>
+                       <field reporter:label="Always Apply" name="always_apply" reporter:datatype="bool"/>
+               </fields>
+               <links>
                        <link field="owner" reltype="has_a" key="id" map="" class="aou"/>
                </links>
                <permacrud xmlns="http://open-ils.org/spec/opensrf/IDL/permacrud/v1">
@@ -232,6 +265,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
                </permacrud>
        </class>
 
+
        <class id="vii" controller="open-ils.cstore open-ils.pcrud" oils_obj:fieldmapper="vandelay::import_item" oils_persist:tablename="vandelay.import_item" reporter:label="Import Item">
                <fields oils_persist:primary="id" oils_persist:sequence="vandelay.import_item_id_seq">
                        <field reporter:label="Import Item ID" name="id" reporter:datatype="id"/>
index def8dfd..4122444 100644 (file)
@@ -177,12 +177,20 @@ CREATE TABLE vandelay.import_item (
     opac_visible    BOOL,
     internal_id     BIGINT -- queue_type == 'acq' ? acq.lineitem_detail.id : asset.copy.id
 );
+
+CREATE TABLE vandelay.import_bib_trash_group(
+    id           SERIAL  PRIMARY KEY,
+    owner        INTEGER NOT NULL REFERENCES actor.org_unit(id),
+    label        TEXT    NOT NULL, --i18n
+    always_apply BOOLEAN NOT NULL DEFAULT FALSE,
+       CONSTRAINT vand_import_bib_trash_grp_owner_label UNIQUE (owner, label)
+);
  
 CREATE TABLE vandelay.import_bib_trash_fields (
-    id              BIGSERIAL   PRIMARY KEY,
-    owner           INT         NOT NULL REFERENCES actor.org_unit (id) ON UPDATE CASCADE ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED,
-    field           TEXT        NOT NULL,
-       CONSTRAINT vand_import_bib_trash_fields_idx UNIQUE (owner,field)
+    id         BIGSERIAL PRIMARY KEY,
+    grp        INTEGER   NOT NULL REFERENCES vandelay.import_bib_trash_group,
+    field      TEXT      NOT NULL,
+    CONSTRAINT vand_import_bib_trash_fields_once_per UNIQUE (grp, field)
 );
 
 CREATE TABLE vandelay.merge_profile (
diff --git a/Open-ILS/src/sql/Pg/upgrade/XXXX.schema.strip-marc-tags.sql b/Open-ILS/src/sql/Pg/upgrade/XXXX.schema.strip-marc-tags.sql
new file mode 100644 (file)
index 0000000..3bf2835
--- /dev/null
@@ -0,0 +1,41 @@
+BEGIN;
+
+CREATE TABLE vandelay.import_bib_trash_group(
+    id SERIAL PRIMARY KEY,
+    owner INT NOT NULL REFERENCES actor.org_unit(id),
+    label TEXT NOT NULL, --i18n
+    always_apply BOOLEAN NOT NULL DEFAULT FALSE,
+       CONSTRAINT vand_import_bib_trash_grp_owner_label UNIQUE (owner, label)
+);
+
+-- otherwise, the ALTER TABLE statement below
+-- will fail with pending trigger events.
+SET CONSTRAINTS ALL IMMEDIATE;
+
+ALTER TABLE vandelay.import_bib_trash_fields
+    -- allow null-able for now..
+    ADD COLUMN grp INTEGER REFERENCES vandelay.import_bib_trash_group;
+
+-- add any existing trash_fields to "Legacy" groups (one per unique field
+-- owner) as part of the upgrade, since grp is now required.
+-- note that vandelay.import_bib_trash_fields was never used before,
+-- so in most cases this should be a no-op.
+
+INSERT INTO vandelay.import_bib_trash_group (owner, label)
+    SELECT DISTINCT(owner), 'Legacy' FROM vandelay.import_bib_trash_fields;
+
+UPDATE vandelay.import_bib_trash_fields field SET grp = tgroup.id
+    FROM vandelay.import_bib_trash_group tgroup
+    WHERE tgroup.owner = field.owner;
+    
+ALTER TABLE vandelay.import_bib_trash_fields
+    -- now that have values, we can make this non-null
+    ALTER COLUMN grp SET NOT NULL,
+    -- drop outdated constraint
+    DROP CONSTRAINT vand_import_bib_trash_fields_idx,
+    -- owner is implied by the grp
+    DROP COLUMN owner, 
+    -- make grp+field unique
+    ADD CONSTRAINT vand_import_bib_trash_fields_once_per UNIQUE (grp, field);
+
+COMMIT;