From d4b48798f66a0fc7a9034d39dc396786771a3962 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Andreas=20Kusalananda=20K=C3=A4h=C3=A4ri?=
 <ak4@sanger.ac.uk>
Date: Wed, 28 Mar 2012 12:04:58 +0000
Subject: [PATCH] Added a --dropbak/-dB option for dropping the backup table
 before the script exits.

---
 .../scripts/populate_analysis_description.pl  | 19 +++++++++++++++++--
 1 file changed, 17 insertions(+), 2 deletions(-)

diff --git a/misc-scripts/production_database/scripts/populate_analysis_description.pl b/misc-scripts/production_database/scripts/populate_analysis_description.pl
index 146fdc1eca..3bc323bd05 100755
--- a/misc-scripts/production_database/scripts/populate_analysis_description.pl
+++ b/misc-scripts/production_database/scripts/populate_analysis_description.pl
@@ -26,6 +26,8 @@ my $core    = 0;
 my $verbose = 0;
 my $dumppath;
 
+my $do_drop_backup_table = 0;
+
 # Do command line parsing.
 if ( !GetOptions( 'mhost|mh=s'     => \$mhost,
                   'mport|mP=i'     => \$mport,
@@ -42,7 +44,8 @@ if ( !GetOptions( 'mhost|mh=s'     => \$mhost,
                   'type|t=s'       => \$dbtype,
                   'verbose|v!'     => \$verbose,
                   'core=i'         => \$core,
-                  'dumppath|dp=s'  => \$dumppath )
+                  'dumppath|dp=s'  => \$dumppath,
+                  'dropbak|dB!'   => \$do_drop_backup_table, )
      ||
      !( defined($host) &&
         defined($user) &&
@@ -65,7 +68,7 @@ Usage:
   $0 -h host [-P port] \\
   $indent -u user [-p password]
   $indent -d database | --pattern pattern \\
-  $indent -dp dumppath \\
+  $indent -dp dumppath [-dB] \\
   $indent [-s species -t type] \\
   $indent [-mh host] [-mP port] \\
   $indent [-mu user] [-mp password] [-md database] \\
@@ -84,6 +87,9 @@ Usage:
   -dp / --dumppath    Dump path.
                       Back-up table into the specified directory path.
 
+  -dB / --dropbak     Drop the backup table before exiting.  This reuires
+                      the use of the -dp option.
+
   --pattern           User database by Perl regular expressionm
                       e.g. --pattern="^homo.*(rnaseq|vega)_62".
 
@@ -138,6 +144,10 @@ if ( defined($dbname) && defined($dbpattern) ) {
   die("-d/--database and --pattern/--core are mutually exclusive\n");
 }
 
+if ( $do_drop_backup_table && !defined($dumppath) ) {
+  die("The --dropbak (-dB) option required --dumppath (-dp)\n");
+}
+
 # Fetch all data from the master database.
 my %data;
 {
@@ -367,6 +377,11 @@ my %data;
         print("\n");
       }
 
+      if ($do_drop_backup_table) {
+        printf( "Dropping the backup table '%s'\n",
+                $full_table_name_bak );
+        $dbh->do( sprintf( "DROP TABLE %s", $full_table_name_bak ) );
+      }
     }
 
   } ## end while ( $sth->fetch() )
-- 
GitLab