]> git.evergreen-ils.org Git - working/Evergreen.git/blob - Open-ILS/src/sql/Pg/upgrade/0452.schema.authority.propagate_changes.sql
Add default Vandelay match set to schema
[working/Evergreen.git] / Open-ILS / src / sql / Pg / upgrade / 0452.schema.authority.propagate_changes.sql
1 BEGIN;
2
3 INSERT INTO config.upgrade_log (version) VALUES ('0452'); -- dbs
4
5 -- AFTER UPDATE OR INSERT trigger for authority.record_entry
6 CREATE OR REPLACE FUNCTION authority.indexing_ingest_or_delete () RETURNS TRIGGER AS $func$
7 BEGIN
8
9     IF NEW.deleted IS TRUE THEN -- If this authority is deleted
10         DELETE FROM authority.bib_linking WHERE authority = NEW.id; -- Avoid updating fields in bibs that are no longer visible
11         DELETE FROM authority.full_rec WHERE record = NEW.id; -- Avoid validating fields against deleted authority records
12           -- Should remove matching $0 from controlled fields at the same time?
13         RETURN NEW; -- and we're done
14     END IF;
15
16     IF TG_OP = 'UPDATE' THEN -- re-ingest?
17         PERFORM * FROM config.internal_flag WHERE name = 'ingest.reingest.force_on_same_marc' AND enabled;
18
19         IF NOT FOUND AND OLD.marc = NEW.marc THEN -- don't do anything if the MARC didn't change
20             RETURN NEW;
21         END IF;
22         -- Propagate these updates to any linked bib records
23         PERFORM authority.propagate_changes(NEW.id) FROM authority.record_entry WHERE id = NEW.id;
24     END IF;
25
26     -- Flatten and insert the afr data
27     PERFORM * FROM config.internal_flag WHERE name = 'ingest.disable_authority_full_rec' AND enabled;
28     IF NOT FOUND THEN
29         PERFORM authority.reingest_authority_full_rec(NEW.id);
30 -- authority.rec_descriptor is not currently used
31 --        PERFORM * FROM config.internal_flag WHERE name = 'ingest.disable_authority_rec_descriptor' AND enabled;
32 --        IF NOT FOUND THEN
33 --            PERFORM authority.reingest_authority_rec_descriptor(NEW.id);
34 --        END IF;
35     END IF;
36
37     RETURN NEW;
38 END;
39 $func$ LANGUAGE PLPGSQL;
40
41 COMMIT;