From d4e881c77ab98065eaf40b523d0539edba28235f Mon Sep 17 00:00:00 2001 From: Bill Erickson Date: Wed, 27 Feb 2013 15:32:56 -0500 Subject: [PATCH] MARC import tag stripping : SQL / IDL * 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 Signed-off-by: Mike Rylander --- Open-ILS/examples/fm_IDL.xml | 36 +++++++++++++++- Open-ILS/src/sql/Pg/012.schema.vandelay.sql | 16 ++++++-- .../upgrade/XXXX.schema.strip-marc-tags.sql | 41 +++++++++++++++++++ 3 files changed, 88 insertions(+), 5 deletions(-) create mode 100644 Open-ILS/src/sql/Pg/upgrade/XXXX.schema.strip-marc-tags.sql diff --git a/Open-ILS/examples/fm_IDL.xml b/Open-ILS/examples/fm_IDL.xml index 1380f85c17..4d8a299ead 100644 --- a/Open-ILS/examples/fm_IDL.xml +++ b/Open-ILS/examples/fm_IDL.xml @@ -216,9 +216,42 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -232,6 +265,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA + diff --git a/Open-ILS/src/sql/Pg/012.schema.vandelay.sql b/Open-ILS/src/sql/Pg/012.schema.vandelay.sql index def8dfd4f1..4122444ec5 100644 --- a/Open-ILS/src/sql/Pg/012.schema.vandelay.sql +++ b/Open-ILS/src/sql/Pg/012.schema.vandelay.sql @@ -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 index 0000000000..3bf283596a --- /dev/null +++ b/Open-ILS/src/sql/Pg/upgrade/XXXX.schema.strip-marc-tags.sql @@ -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; -- 2.43.2