Fieldmap: reimplement d3 rebind
[sgn.git] / bin / drop_test_databases.pl
blob5ff376db8225ddc542ae396fc7e0ab10add576ef
2 =head1 NAME
4 drop_test_databases.pl - a script to remove test databases from the postgres instance
6 =head1 DESCRIPTION
8 When using t/test_fixture.pl with the --nocleanup option, a lot of test databases (named test_db_* ) can accumulate in the postgres instance.
10 drop_dest_databases.pl will remove all databases whose names start with test_db_.
12 It will ask for a postgres username (default postgres) and a password and then proceed to deletion immediately.
14 =head1 AUTHOR
16 Lukas Mueller <lam87@cornell.edu>
18 April 14, 2020
20 =cut
23 use strict;
24 use Getopt::Std;
26 use CXGN::DB::InsertDBH;
28 our($opt_h);
30 getopts('h:');
32 print STDERR "Deleting test databases (test_db_%) from $opt_h...\n";
33 my $dbh = CXGN::DB::InsertDBH->new( { dbhost => $opt_h, dbname => 'postgres', dbargs => { AutoCommit => 1 } } );
36 my $q = "SELECT datname FROM pg_database WHERE datname ilike 'test_db_%'";
38 my $h = $dbh->prepare($q);
40 $h->execute();
42 my @dbs;
43 while (my ($dbname) = $h->fetchrow_array()) {
44 push @dbs, $dbname;
47 foreach my $dbname (@dbs) {
48 print STDERR "Dropping database $dbname...\n";
49 my $d = "DROP DATABASE $dbname";
50 my $h = $dbh->prepare($d);
51 $h->execute();
54 print STDERR "Done.\n";