From 2ec8168211ad1d7e98b923385db6562277d9ea48 Mon Sep 17 00:00:00 2001
From: amontero <amontero@166637.no-reply.drupal.org>
Date: Fri, 12 Oct 2012 17:24:00 +0200
Subject: [PATCH] Add option to automatically find all Drupal cache tables for
 skip/structure table lists (via hook_flush_caches)

---
 commands/sql/sql.drush.inc |   11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/commands/sql/sql.drush.inc b/commands/sql/sql.drush.inc
index 2527996..fc2af8d 100644
--- a/commands/sql/sql.drush.inc
+++ b/commands/sql/sql.drush.inc
@@ -92,6 +92,7 @@ function sql_drush_command() {
         'value' => 'optional',
       ),
       'skip-tables-key' => 'A key in the $skip_tables array. @see example.drushrc.php. Optional.',
+      'structure-tables-cache' => 'Ask Drupal for a list of cache tables to ignore their data. Optional.',
       'structure-tables-key' => 'A key in the $structure_tables array. @see example.drushrc.php. Optional.',
       'tables-key' => 'A key in the $tables array. Optional.',
       'tables-list' => 'A comma-separated list of tables to transfer. Optional.',
@@ -375,8 +376,16 @@ function drush_sql_build_dump_command($table_selection, $db_spec = NULL, $file =
   $structure_tables = $table_selection['structure'];
   $tables = $table_selection['tables'];
 
+  if (drush_get_option('structure-tables-cache')) {
+    drush_bootstrap_max();
+    $cache_tables = array_merge(module_invoke_all('flush_caches'), array(
+      'cache', 'cache_menu', 'cache_path', 'cache_filter', 'cache_bootstrap', 'cache_page'));
+    $structure_tables = array_merge($structure_tables, $cache_tables);
+  }
+
   $ignores = array();
-  $skip_tables  = array_merge($structure_tables, $skip_tables);
+  $skip_tables = array_merge($structure_tables, $skip_tables);
+
   $data_only = drush_get_option('data-only');
   // The ordered-dump option is only supported by MySQL for now.
   // @todo add documention once a hook for drush_get_option_help() is available.
-- 
1.7.9.5

