Skip to content

Commit 9846e99

Browse files
JinzheJinzhe
Jinzhe
authored and
Jinzhe
committed
Backward compatible for mysql client
1 parent 9446fcb commit 9846e99

File tree

5 files changed

+121
-8
lines changed

5 files changed

+121
-8
lines changed

dist/database.js

+68-4
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,12 @@
33
Object.defineProperty(exports, "__esModule", {
44
value: true
55
});
6-
exports.removeDb = exports.importDb = exports.clearDb = exports.unzipDb = exports.checkForDb = exports.importDbQuery = exports.doLocalDbDump = exports.doImportDb = exports.dropDbQuery = exports.doDropAllDbTables = exports.getDbDumpZipCommands = void 0;
6+
exports.isMysql8 = exports.removeDb = exports.importDb = exports.clearDb = exports.unzipDb = exports.checkForDb = exports.importDbQuery = exports.doLocalDbDump = exports.doImportDb = exports.dropDbQuery = exports.doDropAllDbTables = exports.getDbDumpZipCommands = void 0;
77

88
var _promiseMysql = _interopRequireDefault(require("promise-mysql"));
99

10+
var _react = require("react");
11+
1012
var _utils = require("./utils");
1113

1214
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
@@ -89,6 +91,11 @@ const doLocalDbDump =
8991
function () {
9092
var _ref3 = _asyncToGenerator(function* (config) {
9193
let errorMessage;
94+
config = Object.assign(config, {
95+
isMysql8: yield isMysql8({
96+
localCmd: _utils.cmdPromise
97+
})
98+
});
9299
yield (0, _utils.cmdPromise)(getDbDumpZipCommands(config)).catch(e => errorMessage = e);
93100
if (errorMessage) return new Error(errorMessage);
94101
});
@@ -106,9 +113,10 @@ const getDbDumpZipCommands = ({
106113
user,
107114
password,
108115
database,
109-
gzipFilePath
116+
gzipFilePath,
117+
isMysql8 = false
110118
}) => // Dump and zip the db - this can make it around 9 times smaller
111-
`mysqldump --host='${host}' --port='${port}' --user='${user}' --password='${password}' --no-tablespaces --column-statistics=0 ${database} | gzip > '${gzipFilePath}'`;
119+
`mysqldump --host='${host}' --port='${port}' --user='${user}' --password='${password}' --no-tablespaces ${isMysql8 ? '--column-statistics=0' : ''} ${database} | gzip > '${gzipFilePath}'`;
112120

113121
exports.getDbDumpZipCommands = getDbDumpZipCommands;
114122

@@ -263,6 +271,62 @@ function () {
263271
return function removeDb(_x8) {
264272
return _ref8.apply(this, arguments);
265273
};
274+
}(); // Check the version of mysqldump (mysql)
275+
// cmd can be either
276+
// - sshConn(remote)
277+
// or
278+
// - localCmd(local)
279+
280+
281+
exports.removeDb = removeDb;
282+
283+
const isMysql8 =
284+
/*#__PURE__*/
285+
function () {
286+
var _ref9 = _asyncToGenerator(function* ({
287+
sshConn,
288+
localCmd
289+
}) {
290+
if (sshConn) {
291+
let output = "",
292+
errorMessage = "";
293+
yield sshConn.execCommand(`mysqldump --version`).then(({
294+
stdout,
295+
stderr
296+
}) => {
297+
output = stdout; // If error running command
298+
299+
if (stderr) errorMessage = `There was an issue checking mysql version\n\n${stderr}`;
300+
});
301+
302+
if (output.indexOf("Ver 8") !== -1) {
303+
return true;
304+
}
305+
306+
return false;
307+
} else if (localCmd) {
308+
let output = "",
309+
errorMessage = "";
310+
yield localCmd(`mysqldump --version`).then(stdout => {
311+
output = stdout;
312+
}).catch(stderr => {
313+
// If error running command
314+
if (stderr) errorMessage = `There was an issue checking mysql version\n\n${stderr}`;
315+
});
316+
317+
if (output.indexOf("Ver 8") !== -1) {
318+
return true;
319+
}
320+
321+
return false;
322+
}
323+
324+
return false;
325+
});
326+
327+
return function isMysql8(_x9) {
328+
return _ref9.apply(this, arguments);
329+
};
266330
}();
267331

268-
exports.removeDb = removeDb;
332+
exports.isMysql8 = isMysql8;

dist/ssh.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,10 @@ function () {
343343
user: remoteEnv.DB_USER,
344344
password: remoteEnv.DB_PASSWORD,
345345
database: remoteEnv.DB_DATABASE,
346-
gzipFilePath: gzipFileName
346+
gzipFilePath: gzipFileName,
347+
isMysql8: yield (0, _database.isMysql8)({
348+
sshConn: ssh
349+
})
347350
};
348351
let errorMessage;
349352
yield ssh.execCommand((0, _database.getDbDumpZipCommands)(zipCommandConfig), {

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "swiff",
3-
"version": "1.5.5",
3+
"version": "1.5.6",
44
"description": "Swiff saves you time with common SSH tasks during the development of websites/apps",
55
"main": "index.js",
66
"scripts": {

src/database.js

+44-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import mysql from 'promise-mysql'
2+
import { version } from 'react'
23
import { cmdPromise } from './utils'
34
import { isEmpty } from './utils'
45

@@ -50,6 +51,11 @@ const doImportDb = async config => {
5051

5152
const doLocalDbDump = async config => {
5253
let errorMessage
54+
config = Object.assign(config, {
55+
isMysql8: await isMysql8({
56+
localCmd:cmdPromise
57+
})
58+
})
5359
await cmdPromise(getDbDumpZipCommands(config)).catch(
5460
e => (errorMessage = e)
5561
)
@@ -63,9 +69,10 @@ const getDbDumpZipCommands = ({
6369
password,
6470
database,
6571
gzipFilePath,
72+
isMysql8 = false
6673
}) =>
6774
// Dump and zip the db - this can make it around 9 times smaller
68-
`mysqldump --host='${host}' --port='${port}' --user='${user}' --password='${password}' --no-tablespaces --column-statistics=0 ${database} | gzip > '${gzipFilePath}'`
75+
`mysqldump --host='${host}' --port='${port}' --user='${user}' --password='${password}' --no-tablespaces ${isMysql8?'--column-statistics=0':''} ${database} | gzip > '${gzipFilePath}'`
6976

7077
const checkForDb = async ({ dbFilePath, sshConn }) => {
7178
let errorMessage
@@ -178,6 +185,41 @@ const removeDb = async ({ dbFilePath, sshConn }) => {
178185
return
179186
}
180187

188+
// Check the version of mysqldump (mysql)
189+
// cmd can be either
190+
// - sshConn(remote)
191+
// or
192+
// - localCmd(local)
193+
const isMysql8 = async ({sshConn, localCmd}) => {
194+
if (sshConn) {
195+
let output = "", errorMessage = "";
196+
await sshConn.execCommand(`mysqldump --version`).then(({ stdout, stderr }) => {
197+
output = stdout;
198+
// If error running command
199+
if (stderr)
200+
errorMessage = `There was an issue checking mysql version\n\n${stderr}`
201+
})
202+
if (output.indexOf("Ver 8") !== -1) {
203+
return true;
204+
}
205+
return false;
206+
} else if (localCmd) {
207+
let output = "", errorMessage = "";
208+
await localCmd(`mysqldump --version`).then(stdout => {
209+
output = stdout;
210+
}).catch(stderr => {
211+
// If error running command
212+
if (stderr)
213+
errorMessage = `There was an issue checking mysql version\n\n${stderr}`
214+
})
215+
if (output.indexOf("Ver 8") !== -1) {
216+
return true;
217+
}
218+
return false;
219+
}
220+
return false;
221+
}
222+
181223
export {
182224
getDbDumpZipCommands,
183225
doDropAllDbTables,
@@ -190,4 +232,5 @@ export {
190232
clearDb,
191233
importDb,
192234
removeDb,
235+
isMysql8,
193236
}

src/ssh.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import resolveUsername from 'username'
33
import path from 'path'
44
import { executeCommands, cmdPromise, isEmpty, isFunction } from './utils'
55
import { getParsedEnv } from './env'
6-
import { getDbDumpZipCommands } from './database'
6+
import { getDbDumpZipCommands, isMysql8 } from './database'
77
import { pathBackups, pathApp } from './paths'
88
import { colourAttention, colourNotice } from './palette'
99
import chalk from 'chalk'
@@ -314,6 +314,9 @@ const getSshDatabase = async ({
314314
password: remoteEnv.DB_PASSWORD,
315315
database: remoteEnv.DB_DATABASE,
316316
gzipFilePath: gzipFileName,
317+
isMysql8: await isMysql8({
318+
sshConn:ssh
319+
})
317320
}
318321
let errorMessage
319322
await ssh

0 commit comments

Comments
 (0)