From d4dcf0022b9f1d04ff9c57071a058d8ca7a03766 Mon Sep 17 00:00:00 2001
From: jurgenhaas <juergen@paragon-es.de>
Date: Fri, 3 Nov 2017 10:07:24 +0100
Subject: [PATCH] #12 Allow configuration of structure and skip tables for
 Drush sql operations

---
 README.md                  | 114 ++++++++++++++++++++-----------------
 src/Handler.php            |   8 +++
 templates/drushrc.php.twig |   5 +-
 3 files changed, 72 insertions(+), 55 deletions(-)

diff --git a/README.md b/README.md
index ac69d8c..633cbfa 100644
--- a/README.md
+++ b/README.md
@@ -190,60 +190,68 @@ To overwrite the default settings for the Docker environment, add the relevant p
 {
   "extra": {
     "docker4drupal": {
-        "projectname": "[NAME OF CURRENT DIRECTORY]",
-        "live": {
-          "root": "",
-          "uri": "",
-          "host": "",
-          "user": ""
-        },
-        "drupal": {
-          "version": 8
-        },
-        "php": {
-          "version": "7.0",
-          "xdebug": 1
-        },
-        "webserver": {
-          "type": "nginx",
-          "version": "1.13"
-        },
-        "varnish": {
-          "enable": 0
-        },
-        "redis": {
-          "version": "4.0"
-        },
-        "dbbrowser": {
-          "type": "pma"
-        },
-        "solr": {
-          "enable": 0,
-          "version": "6.6"
-        },
-        "node": {
-          "enable": 0,
-          "key": "",
-          "path": ""
-        },
-        "memcached": {
-          "enable": 0
-        },
-        "rsyslog": {
-          "enable": 0
-        },
-        "athenapdf": {
-          "enable": 0,
-          "key": ""
-        },
-        "blackfire": {
-          "enable": 0,
-          "id": "",
-          "token": ""
-        },
-        "webgrind": {
-          "enable": 0
+      "projectname": "[NAME OF CURRENT DIRECTORY]",
+      "live": {
+        "root": "",
+        "uri": "",
+        "host": "",
+        "user": ""
+      },
+      "drush": {
+        "sql": {
+          "tables": {
+            "structure": ["cache", "cache_*", "history", "search_*", "sessions", "watchdog"],
+            "skip": ["none"]
+          }
         }
+      },
+      "drupal": {
+        "version": 8
+      },
+      "php": {
+        "version": "7.0",
+        "xdebug": 1
+      },
+      "webserver": {
+        "type": "nginx",
+        "version": "1.13"
+      },
+      "varnish": {
+        "enable": 0
+      },
+      "redis": {
+        "version": "4.0"
+      },
+      "dbbrowser": {
+        "type": "pma"
+      },
+      "solr": {
+        "enable": 0,
+        "version": "6.6"
+      },
+      "node": {
+        "enable": 0,
+        "key": "",
+        "path": ""
+      },
+      "memcached": {
+        "enable": 0
+      },
+      "rsyslog": {
+        "enable": 0
+      },
+      "athenapdf": {
+        "enable": 0,
+        "key": ""
+      },
+      "blackfire": {
+        "enable": 0,
+        "id": "",
+        "token": ""
+      },
+      "webgrind": {
+        "enable": 0
+      }
     }
   }
 }
diff --git a/src/Handler.php b/src/Handler.php
index 1c476bd..0137228 100644
--- a/src/Handler.php
+++ b/src/Handler.php
@@ -222,6 +222,14 @@ class Handler {
         'host' => '',
         'user' => $env->receive('live_host_username', 'Remote username for host of the live site', getenv('USER')),
       ],
+      'drush' => [
+        'sql' => [
+          'tables' => [
+            'structure' => ['cache', 'cache_*', 'history', 'search_*', 'sessions', 'watchdog',],
+            'skip' => ['none',],
+          ],
+        ],
+      ],
       'drupal' => [
         'version' => '8',
       ],
diff --git a/templates/drushrc.php.twig b/templates/drushrc.php.twig
index 0ebe65e..d710fd2 100644
--- a/templates/drushrc.php.twig
+++ b/templates/drushrc.php.twig
@@ -1,7 +1,8 @@
 <?php
 
-$options['structure-tables']['common'] = array('cache', 'cache_*', 'history', 'search_*', 'sessions', 'watchdog');
+$options['structure-tables']['common'] = array('{{ drush.sql.tables.structure|join('\', \'')|raw }}');
+$options['skip-tables']['common'] = array('{{ drush.sql.tables.skip|join('\', \'')|raw }}');
 
-$options['shell-aliases']['pull-sql'] = '!drush -y --create-db --structure-tables-key=common sql-sync @live @dev && drush -y @dev {{ (drupal.version == 8) ? 'cr' : 'cc all' }} && drush -y @dev dev on';
+$options['shell-aliases']['pull-sql'] = '!drush -y --create-db --structure-tables-key=common --skip-tables-list={{ drush.sql.tables.skip|join(',') }} sql-sync @live @dev && drush -y @dev {{ (drupal.version == 8) ? 'cr' : 'cc all' }} && drush -y @dev dev on';
 $options['shell-aliases']['pull-files'] = '!drush -y rsync @live:%files @dev:%files --mode=rlDzq --chown=www-data:www-data --safe-links --max-size=20M && drush -y rsync @live:%private @dev:%private --mode=rlDzq --chown=www-data:www-data --safe-links --max-size=20M';
 $options['shell-aliases']['pull-all'] = $options['shell-aliases']['pull-sql'] . ' && ' . $options['shell-aliases']['pull-files'];
-- 
GitLab