fixed word error that resulted from copy and paste
[migration-tools.git] / remove_ou_data / 06_remove_copies.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 ALTER TABLE asset.copy DISABLE RULE protect_copy_delete;
23 ALTER TABLE asset.copy DISABLE TRIGGER audit_asset_copy_update_trigger;
24 CREATE INDEX tmp_import_as ON vandelay.import_item(imported_as);
25
26 BEGIN;
27
28 -- NOTE: no FK
29 DELETE FROM asset.opac_visible_copies WHERE copy_id IN (
30   SELECT id FROM asset.copy WHERE circ_lib IN
31     (SELECT (actor.org_unit_descendants(id)).id from actor.org_unit where shortname = :ou_to_del)
32 );
33 -- NOTE: no FK
34 DELETE FROM asset.copy_part_map WHERE target_copy IN (
35   SELECT id FROM asset.copy WHERE circ_lib IN
36     (SELECT (actor.org_unit_descendants(id)).id from actor.org_unit where shortname = :ou_to_del)
37 );
38
39 -- NOTE: no FK
40 DELETE FROM asset.stat_cat_entry_copy_map WHERE owning_copy IN (
41   SELECT id FROM asset.copy WHERE circ_lib IN
42     (SELECT (actor.org_unit_descendants(id)).id from actor.org_unit where shortname = :ou_to_del)
43 );
44
45 DELETE FROM asset.copy_note WHERE owning_copy IN (
46   SELECT id FROM asset.copy WHERE circ_lib IN
47     (SELECT (actor.org_unit_descendants(id)).id from actor.org_unit where shortname = :ou_to_del)
48 );
49
50 DELETE FROM vandelay.import_item WHERE imported_as IN (
51   SELECT id FROM asset.copy WHERE circ_lib IN
52     (SELECT (actor.org_unit_descendants(id)).id from actor.org_unit where shortname = :ou_to_del)
53 );
54
55 DELETE FROM asset.copy WHERE circ_lib IN
56 (SELECT (actor.org_unit_descendants(id)).id from actor.org_unit where shortname = :ou_to_del);
57
58 COMMIT;
59
60 DROP INDEX vandelay.tmp_import_as;
61 ALTER TABLE asset.copy ENABLE RULE protect_copy_delete;
62 ALTER TABLE asset.copy ENABLE TRIGGER audit_asset_copy_update_trigger;