1 -- Copyright 2015, Equinox Software, Inc.
2 -- Author: Galen Charlton <gmc@esilibrary.com>
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.
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.
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.
18 \set ou_to_del ''''EXAMPLE''''
22 ALTER TABLE serial.record_entry DISABLE RULE protect_mfhd_delete;
26 DELETE FROM serial.basic_summary WHERE distribution IN
27 (SELECT id FROM serial.distribution WHERE holding_lib IN (SELECT (actor.org_unit_descendants(id)).id from actor.org_unit where shortname = :ou_to_del));
29 DELETE FROM serial.distribution_note WHERE distribution IN
30 (SELECT id FROM serial.distribution WHERE holding_lib IN (SELECT (actor.org_unit_descendants(id)).id from actor.org_unit where shortname = :ou_to_del));
32 DELETE FROM serial.index_summary WHERE distribution IN
33 (SELECT id FROM serial.distribution WHERE holding_lib IN (SELECT (actor.org_unit_descendants(id)).id from actor.org_unit where shortname = :ou_to_del));
35 DELETE FROM serial.item WHERE stream IN
36 (SELECT id FROM serial.stream WHERE distribution IN
37 (SELECT id FROM serial.distribution WHERE holding_lib IN (SELECT (actor.org_unit_descendants(id)).id from actor.org_unit where shortname = :ou_to_del)));
39 DELETE FROM serial.item_note WHERE id IN
40 (SELECT id FROM serial.item WHERE stream IN (SELECT id FROM serial.stream WHERE distribution IN
41 (SELECT id FROM serial.distribution WHERE holding_lib IN (SELECT (actor.org_unit_descendants(id)).id from actor.org_unit where shortname = :ou_to_del))));
43 DELETE FROM serial.stream WHERE distribution IN
44 (SELECT id FROM serial.distribution WHERE holding_lib IN (SELECT (actor.org_unit_descendants(id)).id from actor.org_unit where shortname = :ou_to_del));
46 DELETE FROM serial.supplement_summary WHERE distribution IN
47 (SELECT id FROM serial.distribution WHERE holding_lib IN (SELECT (actor.org_unit_descendants(id)).id from actor.org_unit where shortname = :ou_to_del));
49 DELETE FROM serial.distribution WHERE holding_lib IN (SELECT (actor.org_unit_descendants(id)).id from actor.org_unit where shortname = :ou_to_del);
51 UPDATE serial.record_entry SET editor = 1 WHERE editor IN
52 (SELECT id FROM actor.usr WHERE home_ou IN (SELECT (actor.org_unit_descendants(id)).id from actor.org_unit where shortname = :ou_to_del));
54 UPDATE serial.record_entry SET creator = 1 WHERE creator IN
55 (SELECT id FROM actor.usr WHERE home_ou IN (SELECT (actor.org_unit_descendants(id)).id from actor.org_unit where shortname = :ou_to_del));
57 UPDATE serial.record_entry SET owning_lib = 1
58 WHERE owning_lib IN (SELECT (actor.org_unit_descendants(id)).id from actor.org_unit where shortname = :ou_to_del)
59 AND id IN (SELECT record_entry FROM serial.distribution WHERE holding_lib NOT IN (SELECT (actor.org_unit_descendants(id)).id from actor.org_unit where shortname = :ou_to_del));
61 DELETE FROM serial.record_entry WHERE owning_lib IN (SELECT (actor.org_unit_descendants(id)).id from actor.org_unit where shortname = :ou_to_del);
65 ALTER TABLE serial.record_entry ENABLE RULE protect_mfhd_delete;