93d1746bb104b2f908f07c074ab90d12adbb5fb4
[migration-tools.git] / remove_ou_data / 08_remove_bibs_stage_2.sql
1 -- Copyright 2015, Equinox Software, Inc.
2 -- Author: Galen Charlton <gmc@esilibrary.com>
3 --
4 -- This program is free software; you can redistribute it and/or
5 -- modify it under the terms of the GNU General Public License
6 -- as published by the Free Software Foundation; either version 2
7 -- of the License, or (at your option) any later version.
8 --
9 -- This program is distributed in the hope that it will be useful,
10 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
11 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 -- GNU General Public License for more details.
13 --
14 -- You should have received a copy of the GNU General Public License
15 -- along with this program; if not, write to the Free Software
16 -- Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
17
18 \set ou_to_del ''''EXAMPLE''''
19 \set ECHO all
20 \timing
21
22 BEGIN;
23
24 DELETE FROM authority.bib_linking WHERE bib IN 
25 (
26     SELECT record FROM esi.albemarle_volume_bibs x
27     WHERE NOT EXISTS (select 1 from asset.call_number where record = x.record)
28 );
29
30 DELETE FROM metabib.browse_entry_def_map WHERE source IN 
31 (
32     SELECT record FROM esi.albemarle_volume_bibs x
33     WHERE NOT EXISTS (select 1 from asset.call_number where record = x.record)
34 );
35
36 DELETE FROM acq.lineitem WHERE eg_bib_id IN 
37 (
38     SELECT record FROM esi.albemarle_volume_bibs x
39     WHERE NOT EXISTS (select 1 from asset.call_number where record = x.record)
40 );
41
42 DELETE FROM biblio.monograph_part WHERE record IN 
43 (
44     SELECT record FROM esi.albemarle_volume_bibs x
45     WHERE NOT EXISTS (select 1 from asset.call_number where record = x.record)
46 );
47
48 DELETE FROM biblio.peer_bib_copy_map WHERE peer_record IN 
49 (
50     SELECT record FROM esi.albemarle_volume_bibs x
51     WHERE NOT EXISTS (select 1 from asset.call_number where record = x.record)
52 );
53
54 DELETE FROM acq.lineitem WHERE queued_record IN (
55     SELECT id FROM vandelay.queued_bib_record WHERE imported_as IN
56     (
57         SELECT record FROM esi.albemarle_volume_bibs x
58         WHERE NOT EXISTS (select 1 from asset.call_number where record = x.record)
59     )
60 );
61
62 DELETE FROM acq.acq_lineitem_history WHERE queued_record IN (
63     SELECT id FROM vandelay.queued_bib_record WHERE imported_as IN
64     (
65         SELECT record FROM esi.albemarle_volume_bibs x
66         WHERE NOT EXISTS (select 1 from asset.call_number where record = x.record)
67     )
68 );
69
70 DELETE FROM vandelay.queued_bib_record WHERE imported_as IN 
71 (
72     SELECT record FROM esi.albemarle_volume_bibs x
73     WHERE NOT EXISTS (select 1 from asset.call_number where record = x.record)
74 );
75
76 DELETE FROM metabib.record_attr_vector_list WHERE source IN 
77 (
78     SELECT record FROM esi.albemarle_volume_bibs x
79     WHERE NOT EXISTS (select 1 from asset.call_number where record = x.record)
80 );
81
82 DELETE FROM metabib.record_sorter WHERE source IN 
83 (
84     SELECT record FROM esi.albemarle_volume_bibs x
85     WHERE NOT EXISTS (select 1 from asset.call_number where record = x.record)
86 );
87
88 DELETE FROM booking.resource_type WHERE record IN 
89 (
90     SELECT record FROM esi.albemarle_volume_bibs x
91     WHERE NOT EXISTS (select 1 from asset.call_number where record = x.record)
92 );
93
94 COMMIT;