From 5f224951f81fe494254f7de1d7d69bf51627f0cf Mon Sep 17 00:00:00 2001
From: Greg Anderson <greg.1.anderson@greenknowe.org>
Date: Fri, 12 Apr 2013 17:09:35 -0700
Subject: Issue #716412 by Greg Anderson, greg.1.anderson: add a
 --delete-all-tables-first option for sql-sync ?

---
 commands/sql/sql.drush.inc |    1 +
 commands/sql/sync.sql.inc  |    4 ++++
 2 files changed, 5 insertions(+)

diff --git a/commands/sql/sql.drush.inc b/commands/sql/sql.drush.inc
index e11c5d2..499dbc9 100644
--- a/commands/sql/sql.drush.inc
+++ b/commands/sql/sql.drush.inc
@@ -168,6 +168,7 @@ function sql_drush_command() {
       'temp' => 'Use a temporary file to hold dump files.  Implies --no-cache.',
       'dump-dir' => 'Directory to store sql dump files in when --source-dump or --target-dump are not used.  Takes precedence over --temp.',
       'create-db' => 'Create a new database before importing the database dump on the target machine.',
+      'drop' => 'Drop all tables from the target database before importing the database dump.',
       'db-su' => array(
         'description' => 'Account to use when creating a new database. Optional.',
         'example-value' => 'root',
diff --git a/commands/sql/sync.sql.inc b/commands/sql/sync.sql.inc
index 7dcfbea..bdb78ff 100644
--- a/commands/sql/sync.sql.inc
+++ b/commands/sql/sync.sql.inc
@@ -390,6 +390,7 @@ function drush_sql_sync($source = NULL, $destination = NULL) {
       // permissions to the specified user if said user was not created with this right.
       $pre_import_commands = '';
       $create_db = drush_sitealias_get_option($destination_settings, 'create-db');
+      $drop_tables = drush_sitealias_get_option($destination_settings, 'drop');
       if (isset($create_db)) {
         $create_db_su = drush_sql_su($target_db_url, $destination_settings);
         $db_su_connect = _drush_sql_connect($create_db_su);
@@ -407,6 +408,9 @@ function drush_sql_sync($source = NULL, $destination = NULL) {
           $pre_import_commands = sprintf('echo "%s" | %s; ', $pre_import_sql, $db_su_connect);
         }
       }
+      else if ($drop_tables) {
+        $values = drush_invoke_process($destination_settings, "sql-drop", array(), array('yes' => TRUE), array('integrate' => TRUE));
+      }

       // Generate the import command
       $import_command = _drush_sql_connect($target_db_url);
--
1.7.9.5

