cleaning up the Evergreen repo area; adding Overlay as an option to Vandelay upload...
[Evergreen.git] / Open-ILS / src / extras / import / quick_metarecord_map.sql
1 BEGIN;
2
3 ALTER TABLE metabib.metarecord_source_map DROP CONSTRAINT metabib_metarecord_source_map_metarecord_fkey;
4
5 TRUNCATE metabib.metarecord;
6 TRUNCATE metabib.metarecord_source_map;
7
8 INSERT INTO metabib.metarecord (fingerprint,master_record)
9         SELECT  fingerprint,id
10           FROM  (SELECT DISTINCT ON (fingerprint)
11                         fingerprint, id, quality
12                   FROM  biblio.record_entry
13                   ORDER BY fingerprint, quality desc) AS x
14           WHERE fingerprint IS NOT NULL;
15
16 INSERT INTO metabib.metarecord_source_map (metarecord,source)
17         SELECT  m.id, b.id
18           FROM  biblio.record_entry b
19                 JOIN metabib.metarecord m ON (m.fingerprint = b.fingerprint);
20
21 COMMIT;
22
23 BEGIN;
24
25 ALTER TABLE metabib.metarecord_source_map ADD CONSTRAINT metabib_metarecord_source_map_metarecord_fkey FOREIGN KEY (metarecord) REFERENCES metabib.metarecord (id) DEFERRABLE INITIALLY DEFERRED;
26
27 COMMIT;
28
29 VACUUM FULL ANALYZE VERBOSE metabib.metarecord;
30 VACUUM FULL ANALYZE VERBOSE metabib.metarecord_source_map;
31