Commit 13c281f6 authored by Andy Yates's avatar Andy Yates
Browse files

Adding support for mart temporary tables and making the documentation clearer

parent 54299532
#!/usr/bin/env perl
=head1 NAME
......@@ -6,7 +6,11 @@ - delete temporary and backup tables from a database
=head1 SYNOPSIS [arguments]
./ [arguments]
./ --nolog --host localhost --port 3306 --user user --dbname DB --dry_run
./ --nolog --host localhost --port 3306 --user user --dbname DB --interactive 0
Required arguments:
......@@ -18,6 +22,10 @@ Required arguments:
Optional arguments:
--mart Indicates we wish to search for mart
temporary tables which are normally
prefixed with MTMP_
--conffile, --conf=FILE read parameters from FILE
(default: conf/Conversion.ini)
......@@ -32,6 +40,26 @@ Optional arguments:
A script which looks for any table which we believe could be a temporary
table. This means any table which contains
=over 8
=item tmp
=item temp
=item bak
=item backup
=item MTMP_ (only used when --mart is specified)
The code is designed to be run over a single database to avoid the
unintentional and accidental dropping of temporary tables which are still
in use.
=head1 LICENCE
......@@ -72,8 +100,9 @@ my $support = new Bio::EnsEMBL::Utils::ConversionSupport($SERVERROOT);
# parse options
$support->get_common_params, 'mart'
if ($support->param('help') or $support->error) {
......@@ -91,33 +120,34 @@ $support->check_required_params;
# connect to database and get adaptors
my $dba = $support->get_database('ensembl');
my $dbh = $dba->dbc->db_handle;
# find all temporary and backup tables
my @tables;
foreach my $pattern (qw(tmp temp bak backup)) {
my $sql = qq(SHOW TABLES LIKE '\%$pattern\%');
my $sth = $dbh->prepare($sql);
while (my ($table) = $sth->fetchrow_array) {
push @tables, $table;
my @patterns = map { '%'.$_.'%' } qw/tmp temp bak backup/;
push(@patterns, 'MTMP\_%') if $support->param('mart');
foreach my $pattern (@patterns) {
my $results = $dba->dbc()->sql_helper()->execute_simple(
-SQL => 'SHOW TABLES LIKE ?', -PARAMS => [$pattern]);
push(@tables, @{$results});
@tables = sort @tables;
if ($support->param('dry_run')) {
# for a dry run, only show which databases would be deleted
$support->log("Temporary and backup tables found:\n");
foreach my $table (sort @tables) {
foreach my $table (@tables) {
$support->log("$table\n", 1);
} else {
# delete tables
foreach my $table (sort @tables) {
foreach my $table (@tables) {
if ($support->user_proceed("Drop table $table?")) {
$support->log("Dropping table $table...\n");
$dbh->do("DROP TABLE $table");
$dba->dbc()->do("DROP TABLE $table");
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment