import torrus 1.0.9
[freeside.git] / bin / test_scrub
1 #!/usr/bin/perl -w
2
3 #This drops anything from the database that could cause live things to happen.
4 #You'd want to do this on a test copy of your live database but NEVER on the
5 #live database itself.
6
7 #-all exports (all records in part_export, part_export_option export_svc)
8 #-all non-POST invoice destinations (cust_main_invoice)
9 #-all payment gateways and agent payment gw overrides (payment_gateway,
10 # payment_gateway_option, agent_payment_gateway)
11 #-everything in the job queue (queue and queue_arg)
12 #-business-onlinepayment and business-onlinepayment-ach config
13
14 use strict;
15 use vars qw( $opt_h );
16 use Getopt::Std;
17 use FS::UID qw(adminsuidsetup dbh);
18 use FS::Conf;
19 use FS::Schema qw(dbdef);
20
21 getopts('h');
22
23 adminsuidsetup shift;
24
25 foreach my $table (qw(
26   part_export
27   part_export_option
28   export_svc
29   payment_gateway
30   payment_gateway_option
31   agent_payment_gateway
32   queue
33   queue_arg
34 )) {
35
36   my $sth = dbh->prepare("DELETE FROM $table") or die dbh->errstr;
37   $sth->execute or die $sth->errstr;
38
39 }
40
41 my $dsth = dbh->prepare("DELETE FROM cust_main_invoice WHERE dest != 'POST'")
42   or die dbh->errstr;
43 $dsth->execute or die $dsth->errstr;
44
45 my $conf = new FS::Conf;
46 foreach my $item (qw(
47   business-onlinepayment
48   business-onlinepayment-ach
49 )) {
50   $conf->delete($item);
51 }
52
53 if ($opt_h) {  # not all history can be safely deleted
54   foreach my $table (grep { /^h_\w+$/ } dbdef->tables) {
55     my $sth = dbh->prepare("DELETE FROM $table") or die dbh->errstr;
56     $sth->execute or die $sth->errstr;
57   }
58 }
59
60 dbh->commit or die dbh->errstr;