Skip to content

Commit 6ec50d0

Browse files
committed
Merged ignoreTables and MYSQL port options
2 parents 144f7ed + 41e764b commit 6ec50d0

File tree

2 files changed

+31
-11
lines changed

2 files changed

+31
-11
lines changed

README.md

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,8 @@ As a result, it is essential that you define a *single* target *without* an `ssh
9595
"user": "local_db_username",
9696
"pass": "local_db_password",
9797
"host": "local_db_host",
98-
"url": "local_db_url"
98+
"url": "local_db_url",
99+
"ignoreTables": ["table1","table2",...]
99100
// note that the `local` target does not have an "ssh_host"
100101
},
101102
```
@@ -113,7 +114,8 @@ All other targets *must* contain a valid `ssh_host` parameter.
113114
"pass": "development_db_password",
114115
"host": "development_db_host",
115116
"url": "development_db_url",
116-
"ssh_host": "ssh_user@ssh_host"
117+
"ssh_host": "ssh_user@ssh_host",
118+
"ignoreTables": ["table1","table2",...]
117119
},
118120
"stage": {
119121
"title": "Stage",
@@ -122,7 +124,8 @@ All other targets *must* contain a valid `ssh_host` parameter.
122124
"pass": "stage_db_password",
123125
"host": "stage_db_host",
124126
"url": "stage_db_url",
125-
"ssh_host": "ssh_user@ssh_host"
127+
"ssh_host": "ssh_user@ssh_host",
128+
"ignoreTables": ["table1","table2",...]
126129
},
127130
"production": {
128131
"title": "Production",
@@ -131,7 +134,8 @@ All other targets *must* contain a valid `ssh_host` parameter.
131134
"pass": "production_db_password",
132135
"host": "production_db_host",
133136
"url": "production_db_url",
134-
"ssh_host": "ssh_user@ssh_host"
137+
"ssh_host": "ssh_user@ssh_host",
138+
"ignoreTables": ["table1","table2",...]
135139
}
136140
```
137141

@@ -152,7 +156,8 @@ grunt.initConfig({
152156
"user": "local_db_username",
153157
"pass": "local_db_password",
154158
"host": "local_db_host",
155-
"url": "local_db_url"
159+
"url": "local_db_url",
160+
"ignoreTables": ["table1","table2",...]
156161
// note that the `local` target does not have an "ssh_host"
157162
},
158163
// "Remote" targets
@@ -163,7 +168,8 @@ grunt.initConfig({
163168
"pass": "development_db_password",
164169
"host": "development_db_host",
165170
"url": "development_db_url",
166-
"ssh_host": "ssh_user@ssh_host"
171+
"ssh_host": "ssh_user@ssh_host",
172+
"ignoreTables": ["table1","table2",...]
167173
},
168174
"stage": {
169175
"title": "Stage",
@@ -172,7 +178,8 @@ grunt.initConfig({
172178
"pass": "stage_db_password",
173179
"host": "stage_db_host",
174180
"url": "stage_db_url",
175-
"ssh_host": "ssh_user@ssh_host"
181+
"ssh_host": "ssh_user@ssh_host",
182+
"ignoreTables": ["table1","table2",...]
176183
},
177184
"production": {
178185
"title": "Production",
@@ -181,7 +188,8 @@ grunt.initConfig({
181188
"pass": "production_db_password",
182189
"host": "production_db_host",
183190
"url": "production_db_url",
184-
"ssh_host": "ssh_user@ssh_host"
191+
"ssh_host": "ssh_user@ssh_host",
192+
"ignoreTables": ["table1","table2",...]
185193
}
186194
},
187195
})
@@ -223,6 +231,10 @@ Description: the string to search and replace within the database before it is m
223231
Type: `String`
224232
Description: ssh connection string in the format `SSH_USER@SSH_HOST`. The task assumes you have ssh keys setup which allow you to remote into your server without requiring the input of a password. As this is an exhaustive topic we will not cover it here but you might like to start by reading [Github's own advice](https://help.github.com/articles/generating-ssh-keys).
225233

234+
#### ignoreTables
235+
Type: `Array of Strings`
236+
Description: tables to ignore. They won't be in the dump — neither their structure nor their content.
237+
226238
### Options
227239

228240
#### options.backups_dir
@@ -248,6 +260,7 @@ In lieu of a formal styleguide, take care to maintain the existing coding style.
248260

249261
## Release History
250262

263+
* 2013-12-09 v0.3.0 Added `ignoreTables` option.
251264
* 2013-11-12   v0.2.0   Fix escaping issues, ability to define `target` via options, README doc fixes, pass host param to mysqldump.
252265
* 2013-06-11   v0.1.0   Minor updates to docs including addtion of Release History section.
253266
* 2013-06-11   v0.0.1   Initial Plugin release.

tasks/deployments.js

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,10 @@ module.exports = function(grunt) {
181181

182182
grunt.file.mkdir(output_paths.dir);
183183

184+
// 1) Get array of tables to ignore, as defined in the config, and format it correctly
185+
if( config.ignoreTables ) {
186+
var ignoreTables = '--ignore-table=' + config.database + "." + config.ignoreTables.join(' --ignore-table='+config.database+'.');
187+
}
184188

185189
// 2) Compile MYSQL cmd via Lo-Dash template string
186190
var tpl_mysqldump = grunt.template.process(tpls.mysqldump, {
@@ -189,12 +193,13 @@ module.exports = function(grunt) {
189193
pass: config.pass,
190194
database: config.database,
191195
host: config.host,
192-
port: config.port || 3306
196+
port: config.port || 3306,
197+
ignoreTables: ignoreTables || ''
193198
}
194199
});
195200

196-
197201
// 3) Test whether MYSQL DB is local or whether requires remote access via SSH
202+
198203
if (typeof config.ssh_host === "undefined") { // it's a local connection
199204
grunt.log.writeln("Creating DUMP of local database");
200205
cmd = tpl_mysqldump;
@@ -251,7 +256,9 @@ module.exports = function(grunt) {
251256

252257
search_replace: "sed -i '' 's#<%= search %>#<%= replace %>#g' <%= path %>",
253258

254-
mysqldump: "mysqldump -h <%= host %> -u<%= user %> -p<%= pass %> -P<%= port %> <%= database %>",
259+
260+
mysqldump: "mysqldump -h <%= host %> -u<%= user %> -p<%= pass %> -P<%= port %> <%= database %> <%= ignoreTables %>",
261+
255262

256263
mysql: "mysql -h <%= host %> -u <%= user %> -p<%= pass %> -P<%= port %> <%= database %>",
257264

0 commit comments

Comments
 (0)