changing verbage for bib loading table
[migration-tools.git] / sql / nuke-patrons-and-circs.sql
1 -- Copyright 2009-2013, Equinox Software, Inc.
2 --
3 -- This program is free software; you can redistribute it and/or
4 -- modify it under the terms of the GNU General Public License
5 -- as published by the Free Software Foundation; either version 2
6 -- of the License, or (at your option) any later version.
7 --
8 -- This program is distributed in the hope that it will be useful,
9 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
10 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11 -- GNU General Public License for more details.
12 --
13 -- You should have received a copy of the GNU General Public License
14 -- along with this program; if not, write to the Free Software
15 -- Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
16
17 ALTER TABLE actor.usr DISABLE RULE protect_user_delete;
18 BEGIN;
19
20 -- get transactions out of the way first
21 TRUNCATE TABLE action.circulation CASCADE;
22 TRUNCATE TABLE action.hold_request CASCADE;
23 TRUNCATE TABLE money.payment CASCADE;
24 TRUNCATE TABLE money.billing CASCADE;
25 TRUNCATE TABLE money.grocery CASCADE;
26 TRUNCATE TABLE money.materialized_billable_xact_summary CASCADE;
27 TRUNCATE TABLE action.non_cataloged_circulation CASCADE;
28 TRUNCATE TABLE action.in_house_use CASCADE;
29
30 -- This statement is meant to be customized
31 DELETE FROM actor.usr WHERE usrname !~ 'admin' 
32 AND profile NOT IN (SELECT id FROM permission.grp_tree WHERE name IN ('SIP', 'Unique Mgmt'));
33
34 \echo List of patrons that are left
35 SELECT id, usrname FROM actor.usr;
36
37 DELETE FROM actor.usr_note WHERE usr NOT IN (SELECT id FROM actor.usr);
38 DELETE FROM actor.usr_address WHERE usr NOT IN (SELECT id FROM actor.usr);
39 DELETE FROM actor.card WHERE usr NOT IN (SELECT id FROM actor.usr);
40 DELETE FROM money.collections_tracker WHERE usr NOT IN (SELECT id FROM actor.usr);
41 DELETE FROM reporter.template_folder WHERE owner NOT IN (SELECT id FROM actor.usr);
42 DELETE FROM reporter.report_folder WHERE owner NOT IN (SELECT id FROM actor.usr);
43 DELETE FROM reporter.output_folder WHERE owner NOT IN (SELECT id FROM actor.usr);
44 DELETE FROM reporter.template WHERE owner NOT IN (SELECT id FROM actor.usr);
45 DELETE FROM reporter.report WHERE owner NOT IN (SELECT id FROM actor.usr);
46 DELETE FROM reporter.schedule WHERE runner NOT IN (SELECT id FROM actor.usr);
47
48 \echo If you are happy with the purge, please run the following:
49 \echo
50 \echo COMMIT;
51 \echo ALTER TABLE actor.usr ENABLE RULE protect_user_delete;
52 \echo
53 \echo Finally, please do a VACUUM ANALYZE