fixing typo
[migration-tools.git] / remove_ou_data / 09_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 vol_del_table ORGUNIT_volume_bibs
20 \set ECHO all
21 \timing
22
23 BEGIN;
24
25 DELETE FROM authority.bib_linking WHERE bib IN 
26 (
27     SELECT record FROM esi.:vol_del_table x
28     WHERE NOT EXISTS (select 1 from asset.call_number where record = x.record)
29 );
30
31 DELETE FROM metabib.browse_entry_def_map WHERE source IN 
32 (
33     SELECT record FROM esi.:vol_del_table x
34     WHERE NOT EXISTS (select 1 from asset.call_number where record = x.record)
35 );
36
37 DELETE FROM acq.lineitem WHERE eg_bib_id IN 
38 (
39     SELECT record FROM esi.:vol_del_table x
40     WHERE NOT EXISTS (select 1 from asset.call_number where record = x.record)
41 );
42
43 DELETE FROM biblio.monograph_part WHERE record IN 
44 (
45     SELECT record FROM esi.:vol_del_table x
46     WHERE NOT EXISTS (select 1 from asset.call_number where record = x.record)
47 );
48
49 DELETE FROM biblio.peer_bib_copy_map WHERE peer_record IN 
50 (
51     SELECT record FROM esi.:vol_del_table x
52     WHERE NOT EXISTS (select 1 from asset.call_number where record = x.record)
53 );
54
55 DELETE FROM acq.lineitem WHERE queued_record IN (
56     SELECT id FROM vandelay.queued_bib_record WHERE imported_as IN
57     (
58         SELECT record FROM esi.:vol_del_table x
59         WHERE NOT EXISTS (select 1 from asset.call_number where record = x.record)
60     )
61 );
62
63 DELETE FROM acq.acq_lineitem_history WHERE queued_record IN (
64     SELECT id FROM vandelay.queued_bib_record WHERE imported_as IN
65     (
66         SELECT record FROM esi.:vol_del_table x
67         WHERE NOT EXISTS (select 1 from asset.call_number where record = x.record)
68     )
69 );
70
71 DELETE FROM vandelay.queued_bib_record WHERE imported_as IN 
72 (
73     SELECT record FROM esi.:vol_del_table x
74     WHERE NOT EXISTS (select 1 from asset.call_number where record = x.record)
75 );
76
77 DELETE FROM metabib.record_attr_vector_list WHERE source IN 
78 (
79     SELECT record FROM esi.:vol_del_table x
80     WHERE NOT EXISTS (select 1 from asset.call_number where record = x.record)
81 );
82
83 DELETE FROM metabib.record_sorter WHERE source IN 
84 (
85     SELECT record FROM esi.:vol_del_table x
86     WHERE NOT EXISTS (select 1 from asset.call_number where record = x.record)
87 );
88
89 DELETE FROM booking.resource_type WHERE record IN 
90 (
91     SELECT record FROM esi.:vol_del_table x
92     WHERE NOT EXISTS (select 1 from asset.call_number where record = x.record)
93 );
94
95 COMMIT;