1 DROP SCHEMA vandelay CASCADE;
5 CREATE SCHEMA vandelay;
7 CREATE TABLE vandelay.queue (
8 id BIGSERIAL PRIMARY KEY,
9 owner INT NOT NULL REFERENCES actor.usr (id) DEFERRABLE INITIALLY DEFERRED,
11 complete BOOL NOT NULL DEFAULT FALSE,
12 queue_type TEXT NOT NULL DEFAULT 'bib' CHECK (queue_type IN ('bib','authority')),
13 CONSTRAINT vand_queue_name_once_per_owner_const UNIQUE (owner,name,queue_type)
16 CREATE TABLE vandelay.queued_record (
17 id BIGSERIAL PRIMARY KEY,
18 create_time TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW(),
19 import_time TIMESTAMP WITH TIME ZONE,
20 purpose TEXT NOT NULL DEFAULT 'import' CHECK (purpose IN ('import','overlay')),
26 /* Bib stuff at the top */
27 ----------------------------------------------------
29 CREATE TABLE vandelay.bib_attr_definition (
30 id SERIAL PRIMARY KEY,
31 code TEXT UNIQUE NOT NULL,
34 remove TEXT NOT NULL DEFAULT '',
35 ident BOOL NOT NULL DEFAULT FALSE
38 -- Each TEXT field (other than 'name') should hold an XPath predicate for pulling the data needed
39 -- DROP TABLE vandelay.import_item_attr_definition CASCADE;
40 CREATE TABLE vandelay.import_item_attr_definition (
41 id BIGSERIAL PRIMARY KEY,
42 owner INT NOT NULL REFERENCES actor.org_unit (id) ON UPDATE CASCADE ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED,
45 keep BOOL NOT NULL DEFAULT FALSE,
67 CONSTRAINT vand_import_item_attr_def_idx UNIQUE (owner,name)
70 CREATE TABLE vandelay.bib_queue (
71 queue_type TEXT NOT NULL DEFAULT 'bib' CHECK (queue_type = 'bib'),
72 item_attr_def TEXT REFERENCES vandelay.import_item_attr_definition (id) ON DELETE SET NULL DEFERRABLE INITIALLY DEFERRED,
73 CONSTRAINT vand_bib_queue_name_once_per_owner_const UNIQUE (owner,name,queue_type)
74 ) INHERITS (vandelay.queue);
75 ALTER TABLE vandelay.bib_queue ADD PRIMARY KEY (id);
77 CREATE TABLE vandelay.queued_bib_record (
78 queue INT NOT NULL REFERENCES vandelay.bib_queue (id) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED,
79 bib_source INT REFERENCES config.bib_source (id) DEFERRABLE INITIALLY DEFERRED,
80 imported_as INT REFERENCES biblio.record_entry (id) DEFERRABLE INITIALLY DEFERRED
81 ) INHERITS (vandelay.queued_record);
82 ALTER TABLE vandelay.queued_bib_record ADD PRIMARY KEY (id);
84 CREATE TABLE vandelay.queued_bib_record_attr (
85 id BIGSERIAL PRIMARY KEY,
86 record BIGINT NOT NULL REFERENCES vandelay.queued_bib_record (id) DEFERRABLE INITIALLY DEFERRED,
87 field INT NOT NULL REFERENCES vandelay.bib_attr_definition (id) DEFERRABLE INITIALLY DEFERRED,
88 attr_value TEXT NOT NULL
91 CREATE TABLE vandelay.bib_match (
92 id BIGSERIAL PRIMARY KEY,
93 field_type TEXT NOT NULL CHECK (field_type in ('isbn','tcn_value','id')),
94 matched_attr INT REFERENCES vandelay.queued_bib_record_attr (id) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED,
95 queued_record BIGINT REFERENCES vandelay.queued_bib_record (id) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED,
96 eg_record BIGINT REFERENCES biblio.record_entry (id) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED
99 -- DROP TABLE vandelay.import_item CASCADE;
100 CREATE TABLE vandelay.import_item (
101 id BIGSERIAL PRIMARY KEY,
102 record BIGINT NOT NULL REFERENCES vandelay.queued_bib_record (id) ON DELETE CASCADE,
103 definition BIGINT NOT NULL REFERENCES vandelay.import_item_attr_definition (id) ON DELETE CASCADE,
112 deposit_amount NUMERIC(8,2),
125 CREATE TABLE vandelay.import_bib_trash_fields (
126 id BIGSERIAL PRIMARY KEY,
127 owner INT NOT NULL REFERENCES actor.org_unit (id) ON UPDATE CASCADE ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED,
129 CONSTRAINT vand_import_bib_trash_fields_idx UNIQUE (owner,field)
132 CREATE OR REPLACE FUNCTION vandelay.strip_field ( xml TEXT, field TEXT ) RETURNS TEXT AS $_$
138 my $field_spec = shift;
140 my $r = MARC::Record->new_from_xml( $xml );
141 $r->delete_field( $_ ) for ( $r->field( $field_spec ) );
143 $xml = $r->as_xml_record;
144 $xml =~ s/^<\?.+?\?>$//mo;
146 $xml =~ s/>\s+</></sgo;
150 $_$ LANGUAGE PLPERLU;
153 CREATE OR REPLACE FUNCTION vandelay.ingest_items ( import_id BIGINT, attr_def_id BIGINT ) RETURNS SETOF vandelay.import_item AS $$
178 attr_set vandelay.import_item%ROWTYPE;
184 SELECT * INTO attr_def FROM vandelay.import_item_attr_definition WHERE id = attr_def_id;
188 attr_set.definition := attr_def.id;
190 -- Build the combined XPath
194 WHEN attr_def.owning_lib IS NULL THEN 'null()'
195 WHEN LENGTH( attr_def.owning_lib ) = 1 THEN '//*[@tag="' || attr_def.tag || '"]/*[@code="' || attr_def.owning_lib || '"]'
196 ELSE '//*[@tag="' || attr_def.tag || '"]/*' || attr_def.owning_lib
201 WHEN attr_def.circ_lib IS NULL THEN 'null()'
202 WHEN LENGTH( attr_def.circ_lib ) = 1 THEN '//*[@tag="' || attr_def.tag || '"]/*[@code="' || attr_def.circ_lib || '"]'
203 ELSE '//*[@tag="' || attr_def.tag || '"]/*' || attr_def.circ_lib
208 WHEN attr_def.call_number IS NULL THEN 'null()'
209 WHEN LENGTH( attr_def.call_number ) = 1 THEN '//*[@tag="' || attr_def.tag || '"]/*[@code="' || attr_def.call_number || '"]'
210 ELSE '//*[@tag="' || attr_def.tag || '"]/*' || attr_def.call_number
215 WHEN attr_def.copy_number IS NULL THEN 'null()'
216 WHEN LENGTH( attr_def.copy_number ) = 1 THEN '//*[@tag="' || attr_def.tag || '"]/*[@code="' || attr_def.copy_number || '"]'
217 ELSE '//*[@tag="' || attr_def.tag || '"]/*' || attr_def.copy_number
222 WHEN attr_def.status IS NULL THEN 'null()'
223 WHEN LENGTH( attr_def.status ) = 1 THEN '//*[@tag="' || attr_def.tag || '"]/*[@code="' || attr_def.status || '"]'
224 ELSE '//*[@tag="' || attr_def.tag || '"]/*' || attr_def.status
229 WHEN attr_def.location IS NULL THEN 'null()'
230 WHEN LENGTH( attr_def.location ) = 1 THEN '//*[@tag="' || attr_def.tag || '"]/*[@code="' || attr_def.location || '"]'
231 ELSE '//*[@tag="' || attr_def.tag || '"]/*' || attr_def.location
236 WHEN attr_def.circulate IS NULL THEN 'null()'
237 WHEN LENGTH( attr_def.circulate ) = 1 THEN '//*[@tag="' || attr_def.tag || '"]/*[@code="' || attr_def.circulate || '"]'
238 ELSE '//*[@tag="' || attr_def.tag || '"]/*' || attr_def.circulate
243 WHEN attr_def.deposit IS NULL THEN 'null()'
244 WHEN LENGTH( attr_def.deposit ) = 1 THEN '//*[@tag="' || attr_def.tag || '"]/*[@code="' || attr_def.deposit || '"]'
245 ELSE '//*[@tag="' || attr_def.tag || '"]/*' || attr_def.deposit
250 WHEN attr_def.deposit_amount IS NULL THEN 'null()'
251 WHEN LENGTH( attr_def.deposit_amount ) = 1 THEN '//*[@tag="' || attr_def.tag || '"]/*[@code="' || attr_def.deposit_amount || '"]'
252 ELSE '//*[@tag="' || attr_def.tag || '"]/*' || attr_def.deposit_amount
257 WHEN attr_def.ref IS NULL THEN 'null()'
258 WHEN LENGTH( attr_def.ref ) = 1 THEN '//*[@tag="' || attr_def.tag || '"]/*[@code="' || attr_def.ref || '"]'
259 ELSE '//*[@tag="' || attr_def.tag || '"]/*' || attr_def.ref
264 WHEN attr_def.holdable IS NULL THEN 'null()'
265 WHEN LENGTH( attr_def.holdable ) = 1 THEN '//*[@tag="' || attr_def.tag || '"]/*[@code="' || attr_def.holdable || '"]'
266 ELSE '//*[@tag="' || attr_def.tag || '"]/*' || attr_def.holdable
271 WHEN attr_def.price IS NULL THEN 'null()'
272 WHEN LENGTH( attr_def.price ) = 1 THEN '//*[@tag="' || attr_def.tag || '"]/*[@code="' || attr_def.price || '"]'
273 ELSE '//*[@tag="' || attr_def.tag || '"]/*' || attr_def.price
278 WHEN attr_def.barcode IS NULL THEN 'null()'
279 WHEN LENGTH( attr_def.barcode ) = 1 THEN '//*[@tag="' || attr_def.tag || '"]/*[@code="' || attr_def.barcode || '"]'
280 ELSE '//*[@tag="' || attr_def.tag || '"]/*' || attr_def.barcode
285 WHEN attr_def.circ_modifier IS NULL THEN 'null()'
286 WHEN LENGTH( attr_def.circ_modifier ) = 1 THEN '//*[@tag="' || attr_def.tag || '"]/*[@code="' || attr_def.circ_modifier || '"]'
287 ELSE '//*[@tag="' || attr_def.tag || '"]/*' || attr_def.circ_modifier
292 WHEN attr_def.circ_as_type IS NULL THEN 'null()'
293 WHEN LENGTH( attr_def.circ_as_type ) = 1 THEN '//*[@tag="' || attr_def.tag || '"]/*[@code="' || attr_def.circ_as_type || '"]'
294 ELSE '//*[@tag="' || attr_def.tag || '"]/*' || attr_def.circ_as_type
299 WHEN attr_def.alert_message IS NULL THEN 'null()'
300 WHEN LENGTH( attr_def.alert_message ) = 1 THEN '//*[@tag="' || attr_def.tag || '"]/*[@code="' || attr_def.alert_message || '"]'
301 ELSE '//*[@tag="' || attr_def.tag || '"]/*' || attr_def.alert_message
306 WHEN attr_def.opac_visible IS NULL THEN 'null()'
307 WHEN LENGTH( attr_def.opac_visible ) = 1 THEN '//*[@tag="' || attr_def.tag || '"]/*[@code="' || attr_def.opac_visible || '"]'
308 ELSE '//*[@tag="' || attr_def.tag || '"]/*' || attr_def.opac_visible
313 WHEN attr_def.pub_note IS NULL THEN 'null()'
314 WHEN LENGTH( attr_def.pub_note ) = 1 THEN '//*[@tag="' || attr_def.tag || '"]/*[@code="' || attr_def.pub_note || '"]'
315 ELSE '//*[@tag="' || attr_def.tag || '"]/*' || attr_def.pub_note
319 WHEN attr_def.priv_note IS NULL THEN 'null()'
320 WHEN LENGTH( attr_def.priv_note ) = 1 THEN '//*[@tag="' || attr_def.tag || '"]/*[@code="' || attr_def.priv_note || '"]'
321 ELSE '//*[@tag="' || attr_def.tag || '"]/*' || attr_def.priv_note
328 call_number || '|' ||
329 copy_number || '|' ||
334 deposit_amount || '|' ||
339 circ_modifier || '|' ||
340 circ_as_type || '|' ||
341 alert_message || '|' ||
346 -- RAISE NOTICE 'XPath: %', xpath;
350 FROM xpath_table( 'id', 'marc', 'vandelay.queued_bib_record', xpath, 'id = ' || import_id )
351 AS t( id BIGINT, ol TEXT, clib TEXT, cn TEXT, cnum TEXT, cs TEXT, cl TEXT, circ TEXT,
352 dep TEXT, dep_amount TEXT, r TEXT, hold TEXT, pr TEXT, bc TEXT, circ_mod TEXT,
353 circ_as TEXT, amessage TEXT, note TEXT, pnote TEXT, opac_vis TEXT )
356 tmp_attr_set.pr = REGEXP_REPLACE(tmp_attr_set.pr, E'[^0-9\\.]', '', 'g');
357 tmp_attr_set.dep_amount = REGEXP_REPLACE(tmp_attr_set.dep_amount, E'[^0-9\\.]', '', 'g');
359 tmp_attr_set.pr := NULLIF( tmp_attr_set.pr, '' );
360 tmp_attr_set.dep_amount := NULLIF( tmp_attr_set.dep_amount, '' );
362 SELECT id INTO attr_set.owning_lib FROM actor.org_unit WHERE shortname = UPPER(tmp_attr_set.ol); -- INT
363 SELECT id INTO attr_set.circ_lib FROM actor.org_unit WHERE shortname = UPPER(tmp_attr_set.clib); -- INT
364 SELECT id INTO attr_set.status FROM config.copy_status WHERE LOWER(name) = LOWER(tmp_attr_set.cs); -- INT
366 SELECT id INTO attr_set.location
367 FROM asset.copy_location
368 WHERE LOWER(name) = LOWER(tmp_attr_set.cl)
369 AND owning_lib = COALESCE(attr_set.owning_lib, attr_set.circ_lib); -- INT
371 attr_set.circulate :=
372 LOWER( SUBSTRING( tmp_attr_set.circ, 1, 1)) IN ('t','y','1')
373 OR LOWER(tmp_attr_set.circ) = 'circulating'; -- BOOL
376 LOWER( SUBSTRING( tmp_attr_set.dep, 1, 1 ) ) IN ('t','y','1')
377 OR LOWER(tmp_attr_set.dep) = 'deposit'; -- BOOL
380 LOWER( SUBSTRING( tmp_attr_set.hold, 1, 1 ) ) IN ('t','y','1')
381 OR LOWER(tmp_attr_set.hold) = 'holdable'; -- BOOL
383 attr_set.opac_visible :=
384 LOWER( SUBSTRING( tmp_attr_set.opac_vis, 1, 1 ) ) IN ('t','y','1')
385 OR LOWER(tmp_attr_set.opac_vis) = 'visible'; -- BOOL
388 LOWER( SUBSTRING( tmp_attr_set.r, 1, 1 ) ) IN ('t','y','1')
389 OR LOWER(tmp_attr_set.r) = 'reference'; -- BOOL
391 attr_set.copy_number := tmp_attr_set.cnum::INT; -- INT,
392 attr_set.deposit_amount := tmp_attr_set.dep_amount::NUMERIC(6,2); -- NUMERIC(6,2),
393 attr_set.price := tmp_attr_set.pr::NUMERIC(8,2); -- NUMERIC(8,2),
395 attr_set.call_number := tmp_attr_set.cn; -- TEXT
396 attr_set.barcode := tmp_attr_set.bc; -- TEXT,
397 attr_set.circ_modifier := tmp_attr_set.circ_mod; -- TEXT,
398 attr_set.circ_as_type := tmp_attr_set.circ_as; -- TEXT,
399 attr_set.alert_message := tmp_attr_set.amessage; -- TEXT,
400 attr_set.pub_note := tmp_attr_set.note; -- TEXT,
401 attr_set.priv_note := tmp_attr_set.pnote; -- TEXT,
402 attr_set.alert_message := tmp_attr_set.amessage; -- TEXT,
404 RETURN NEXT attr_set;
414 CREATE OR REPLACE FUNCTION vandelay.ingest_bib_marc ( ) RETURNS TRIGGER AS $$
420 FOR adef IN SELECT * FROM vandelay.bib_attr_definition LOOP
422 SELECT extract_marc_field('vandelay.queued_bib_record', id, adef.xpath, adef.remove) INTO value FROM vandelay.queued_bib_record WHERE id = NEW.id;
423 IF (value IS NOT NULL AND value <> '') THEN
424 INSERT INTO vandelay.queued_bib_record_attr (record, field, attr_value) VALUES (NEW.id, adef.id, value);
433 CREATE OR REPLACE FUNCTION vandelay.ingest_bib_items ( ) RETURNS TRIGGER AS $func$
437 item_data vandelay.import_item%ROWTYPE;
440 SELECT * INTO queue_rec FROM vandelay.bib_queue WHERE id = NEW.queue;
442 FOR item_rule IN SELECT r.* FROM actor.org_unit_ancestors( queue_rec.owner ) o JOIN vandelay.import_item_attr_definition r ON ( r.owner = o.id ) LOOP
443 FOR item_data IN SELECT * FROM vandelay.ingest_items( NEW.id::BIGINT, item_rule.id::BIGINT ) LOOP
444 INSERT INTO vandelay.import_item (
468 item_data.definition,
469 item_data.owning_lib,
471 item_data.call_number,
472 item_data.copy_number,
477 item_data.deposit_amount,
482 item_data.circ_modifier,
483 item_data.circ_as_type,
484 item_data.alert_message,
487 item_data.opac_visible
494 $func$ LANGUAGE PLPGSQL;
496 CREATE OR REPLACE FUNCTION vandelay.match_bib_record ( ) RETURNS TRIGGER AS $func$
501 FOR attr IN SELECT a.* FROM vandelay.queued_bib_record_attr a JOIN vandelay.bib_attr_definition d ON (d.id = a.field) WHERE record = NEW.id AND d.ident IS TRUE LOOP
503 -- All numbers? check for an id match
504 IF (attr.attr_value ~ $r$^\d+$$r$) THEN
505 FOR eg_rec IN SELECT * FROM biblio.record_entry WHERE id = attr.attr_value::BIGINT AND deleted IS FALSE LOOP
506 INSERT INTO vandelay.bib_match (field_type, matched_attr, queued_record, eg_record) VALUES ('id', attr.id, NEW.id, eg_rec.id);
510 -- Looks like an ISBN? check for an isbn match
511 IF (attr.attr_value ~* $r$^[0-9x]+$$r$ AND character_length(attr.attr_value) IN (10,13)) THEN
512 FOR eg_rec IN EXECUTE $$SELECT * FROM metabib.full_rec fr WHERE fr.value LIKE LOWER('$$ || attr.attr_value || $$%') AND fr.tag = '020' AND fr.subfield = 'a'$$ LOOP
513 PERFORM id FROM biblio.record_entry WHERE id = eg_rec.record AND deleted IS FALSE;
515 INSERT INTO vandelay.bib_match (field_type, matched_attr, queued_record, eg_record) VALUES ('isbn', attr.id, NEW.id, eg_rec.record);
519 -- subcheck for isbn-as-tcn
520 FOR eg_rec IN SELECT * FROM biblio.record_entry WHERE tcn_value = 'i' || attr.attr_value AND deleted IS FALSE LOOP
521 INSERT INTO vandelay.bib_match (field_type, matched_attr, queued_record, eg_record) VALUES ('tcn_value', attr.id, NEW.id, eg_rec.id);
525 -- check for an OCLC tcn_value match
526 IF (attr.attr_value ~ $r$^o\d+$$r$) THEN
527 FOR eg_rec IN SELECT * FROM biblio.record_entry WHERE tcn_value = regexp_replace(attr.attr_value,'^o','ocm') AND deleted IS FALSE LOOP
528 INSERT INTO vandelay.bib_match (field_type, matched_attr, queued_record, eg_record) VALUES ('tcn_value', attr.id, NEW.id, eg_rec.id);
532 -- check for a direct tcn_value match
533 FOR eg_rec IN SELECT * FROM biblio.record_entry WHERE tcn_value = attr.attr_value AND deleted IS FALSE LOOP
534 INSERT INTO vandelay.bib_match (field_type, matched_attr, queued_record, eg_record) VALUES ('tcn_value', attr.id, NEW.id, eg_rec.id);
541 $func$ LANGUAGE PLPGSQL;
543 CREATE OR REPLACE FUNCTION vandelay.cleanup_bib_marc ( ) RETURNS TRIGGER AS $$
545 DELETE FROM vandelay.queued_bib_record_attr WHERE record = OLD.id;
546 DELETE FROM vandelay.import_item WHERE record = OLD.id;
548 IF TG_OP = 'UPDATE' THEN
555 CREATE TRIGGER cleanup_bib_trigger
556 BEFORE UPDATE OR DELETE ON vandelay.queued_bib_record
557 FOR EACH ROW EXECUTE PROCEDURE vandelay.cleanup_bib_marc();
559 CREATE TRIGGER ingest_bib_trigger
560 AFTER INSERT OR UPDATE ON vandelay.queued_bib_record
561 FOR EACH ROW EXECUTE PROCEDURE vandelay.ingest_bib_marc();
563 CREATE TRIGGER ingest_item_trigger
564 AFTER INSERT OR UPDATE ON vandelay.queued_bib_record
565 FOR EACH ROW EXECUTE PROCEDURE vandelay.ingest_bib_items();
567 CREATE TRIGGER zz_match_bibs_trigger
568 AFTER INSERT OR UPDATE ON vandelay.queued_bib_record
569 FOR EACH ROW EXECUTE PROCEDURE vandelay.match_bib_record();
572 /* Authority stuff down here */
573 ---------------------------------------
574 CREATE TABLE vandelay.authority_attr_definition (
575 id SERIAL PRIMARY KEY,
576 code TEXT UNIQUE NOT NULL,
579 remove TEXT NOT NULL DEFAULT '',
580 ident BOOL NOT NULL DEFAULT FALSE
583 CREATE TABLE vandelay.authority_queue (
584 queue_type TEXT NOT NULL DEFAULT 'authority' CHECK (queue_type = 'authority'),
585 CONSTRAINT vand_authority_queue_name_once_per_owner_const UNIQUE (owner,name,queue_type)
586 ) INHERITS (vandelay.queue);
587 ALTER TABLE vandelay.authority_queue ADD PRIMARY KEY (id);
589 CREATE TABLE vandelay.queued_authority_record (
590 queue INT NOT NULL REFERENCES vandelay.authority_queue (id) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED,
591 imported_as INT REFERENCES authority.record_entry (id) DEFERRABLE INITIALLY DEFERRED
592 ) INHERITS (vandelay.queued_record);
593 ALTER TABLE vandelay.queued_authority_record ADD PRIMARY KEY (id);
595 CREATE TABLE vandelay.queued_authority_record_attr (
596 id BIGSERIAL PRIMARY KEY,
597 record BIGINT NOT NULL REFERENCES vandelay.queued_authority_record (id) DEFERRABLE INITIALLY DEFERRED,
598 field INT NOT NULL REFERENCES vandelay.authority_attr_definition (id) DEFERRABLE INITIALLY DEFERRED,
599 attr_value TEXT NOT NULL
602 CREATE TABLE vandelay.authority_match (
603 id BIGSERIAL PRIMARY KEY,
604 matched_attr INT REFERENCES vandelay.queued_authority_record_attr (id) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED,
605 queued_record BIGINT REFERENCES vandelay.queued_authority_record (id) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED,
606 eg_record BIGINT REFERENCES authority.record_entry (id) DEFERRABLE INITIALLY DEFERRED
609 CREATE OR REPLACE FUNCTION vandelay.ingest_authority_marc ( ) RETURNS TRIGGER AS $$
615 FOR adef IN SELECT * FROM vandelay.authority_attr_definition LOOP
617 SELECT extract_marc_field('vandelay.queued_authority_record', id, adef.xpath, adef.remove) INTO value FROM vandelay.queued_authority_record WHERE id = NEW.id;
618 IF (value IS NOT NULL AND value <> '') THEN
619 INSERT INTO vandelay.queued_authority_record_attr (record, field, attr_value) VALUES (NEW.id, adef.id, value);
628 CREATE OR REPLACE FUNCTION vandelay.cleanup_authority_marc ( ) RETURNS TRIGGER AS $$
630 DELETE FROM vandelay.queued_authority_record_attr WHERE record = OLD.id;
631 IF TG_OP = 'UPDATE' THEN
638 CREATE TRIGGER cleanup_authority_trigger
639 BEFORE UPDATE OR DELETE ON vandelay.queued_authority_record
640 FOR EACH ROW EXECUTE PROCEDURE vandelay.cleanup_authority_marc();
642 CREATE TRIGGER ingest_authority_trigger
643 AFTER INSERT OR UPDATE ON vandelay.queued_authority_record
644 FOR EACH ROW EXECUTE PROCEDURE vandelay.ingest_authority_marc();
646 -- Vandelay (for importing and exporting records) 012.schema.vandelay.sql
647 --INSERT INTO vandelay.bib_attr_definition ( id, code, description, xpath ) VALUES (1, 'title', oils_i18n_gettext(1, 'vqbrad', 'Title of work', 'description'),'//*[@tag="245"]/*[contains("abcmnopr",@code)]');
648 --INSERT INTO vandelay.bib_attr_definition ( id, code, description, xpath ) VALUES (2, 'author', oils_i18n_gettext(1, 'vqbrad', 'Author of work', 'description'),'//*[@tag="100" or @tag="110" or @tag="113"]/*[contains("ad",@code)]');
649 --INSERT INTO vandelay.bib_attr_definition ( id, code, description, xpath ) VALUES (3, 'language', oils_i18n_gettext(3, 'vqbrad', 'Language of work', 'description'),'//*[@tag="240"]/*[@code="l"][1]');
650 --INSERT INTO vandelay.bib_attr_definition ( id, code, description, xpath ) VALUES (4, 'pagination', oils_i18n_gettext(4, 'vqbrad', 'Pagination', 'description'),'//*[@tag="300"]/*[@code="a"][1]');
651 --INSERT INTO vandelay.bib_attr_definition ( id, code, description, xpath, ident, remove ) VALUES (5, 'isbn',oils_i18n_gettext(5, 'vqbrad', 'ISBN', 'description'),'//*[@tag="020"]/*[@code="a"]', TRUE, $r$(?:-|\s.+$)$r$);
652 --INSERT INTO vandelay.bib_attr_definition ( id, code, description, xpath, ident, remove ) VALUES (6, 'issn',oils_i18n_gettext(6, 'vqbrad', 'ISSN', 'description'),'//*[@tag="022"]/*[@code="a"]', TRUE, $r$(?:-|\s.+$)$r$);
653 --INSERT INTO vandelay.bib_attr_definition ( id, code, description, xpath ) VALUES (7, 'price',oils_i18n_gettext(7, 'vqbrad', 'Price', 'description'),'//*[@tag="020" or @tag="022"]/*[@code="c"][1]');
654 --INSERT INTO vandelay.bib_attr_definition ( id, code, description, xpath, ident ) VALUES (8, 'rec_identifier',oils_i18n_gettext(8, 'vqbrad', 'Accession Number', 'description'),'//*[@tag="001"]', TRUE);
655 --INSERT INTO vandelay.bib_attr_definition ( id, code, description, xpath, ident ) VALUES (9, 'eg_tcn',oils_i18n_gettext(9, 'vqbrad', 'TCN Value', 'description'),'//*[@tag="901"]/*[@code="a"]', TRUE);
656 --INSERT INTO vandelay.bib_attr_definition ( id, code, description, xpath, ident ) VALUES (10, 'eg_tcn_source',oils_i18n_gettext(10, 'vqbrad', 'TCN Source', 'description'),'//*[@tag="901"]/*[@code="b"]', TRUE);
657 --INSERT INTO vandelay.bib_attr_definition ( id, code, description, xpath, ident ) VALUES (11, 'eg_identifier',oils_i18n_gettext(11, 'vqbrad', 'Internal ID', 'description'),'//*[@tag="901"]/*[@code="c"]', TRUE);
658 --INSERT INTO vandelay.bib_attr_definition ( id, code, description, xpath ) VALUES (12, 'publisher',oils_i18n_gettext(12, 'vqbrad', 'Publisher', 'description'),'//*[@tag="260"]/*[@code="b"][1]');
659 --INSERT INTO vandelay.bib_attr_definition ( id, code, description, xpath, remove ) VALUES (13, 'pubdate',oils_i18n_gettext(13, 'vqbrad', 'Publication Date', 'description'),'//*[@tag="260"]/*[@code="c"][1]',$r$\D$r$);
660 --INSERT INTO vandelay.bib_attr_definition ( id, code, description, xpath ) VALUES (14, 'edition',oils_i18n_gettext(14, 'vqbrad', 'Edition', 'description'),'//*[@tag="250"]/*[@code="a"][1]');
662 --INSERT INTO vandelay.import_item_attr_definition (
663 -- owner, name, tag, owning_lib, circ_lib, location,
664 -- call_number, circ_modifier, barcode, price, copy_number,
665 -- circulate, ref, holdable, opac_visible, status
668 -- 'Evergreen 852 export format',
670 -- '[@code = "b"][1]',
671 -- '[@code = "b"][2]',
678 -- '[@code = "x" and text() = "circulating"]',
679 -- '[@code = "x" and text() = "reference"]',
680 -- '[@code = "x" and text() = "holdable"]',
681 -- '[@code = "x" and text() = "visible"]',
685 --INSERT INTO vandelay.import_item_attr_definition (
698 -- 'Unicorn Import format -- 999',
709 --INSERT INTO vandelay.authority_attr_definition ( code, description, xpath, ident ) VALUES ('rec_identifier','Identifier','//*[@tag="001"]', TRUE);