apptask: asyncify
This commit is contained in:
@@ -19,7 +19,7 @@ const assert = require('assert'),
|
||||
constants = require('./constants.js'),
|
||||
debug = require('debug')('box:database'),
|
||||
mysql = require('mysql'),
|
||||
once = require('once'),
|
||||
safe = require('safetydance'),
|
||||
shell = require('./shell.js'),
|
||||
util = require('util');
|
||||
|
||||
@@ -131,21 +131,18 @@ async function transaction(queries) {
|
||||
});
|
||||
}
|
||||
|
||||
function importFromFile(file, callback) {
|
||||
async function importFromFile(file) {
|
||||
assert.strictEqual(typeof file, 'string');
|
||||
assert.strictEqual(typeof callback, 'function');
|
||||
|
||||
const cmd = `/usr/bin/mysql -h "${gDatabase.hostname}" -u ${gDatabase.username} -p${gDatabase.password} ${gDatabase.name} < ${file}`;
|
||||
|
||||
async.series([
|
||||
query.bind(null, 'CREATE DATABASE IF NOT EXISTS box'),
|
||||
child_process.exec.bind(null, cmd)
|
||||
], callback);
|
||||
await query('CREATE DATABASE IF NOT EXISTS box');
|
||||
const [error] = await safe(shell.promises.exec('importFromFile', cmd));
|
||||
if (error) throw new BoxError(BoxError.DATABASE_ERROR, error);
|
||||
}
|
||||
|
||||
function exportToFile(file, callback) {
|
||||
async function exportToFile(file) {
|
||||
assert.strictEqual(typeof file, 'string');
|
||||
assert.strictEqual(typeof callback, 'function');
|
||||
|
||||
// latest mysqldump enables column stats by default which is not present in MySQL 5.7 server
|
||||
// this option must not be set in production cloudrons which still use the old mysqldump
|
||||
@@ -153,5 +150,6 @@ function exportToFile(file, callback) {
|
||||
|
||||
const cmd = `/usr/bin/mysqldump -h "${gDatabase.hostname}" -u root -p${gDatabase.password} ${disableColStats} --single-transaction --routines --triggers ${gDatabase.name} > "${file}"`;
|
||||
|
||||
child_process.exec(cmd, callback);
|
||||
const [error] = await safe(shell.promises.exec('exportToFile', cmd));
|
||||
if (error) throw new BoxError(BoxError.DATABASE_ERROR, error);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user