shell: make require take a tag
This commit is contained in:
+6
-6
@@ -20,7 +20,7 @@ const assert = require('assert'),
|
||||
fs = require('fs'),
|
||||
mysql = require('mysql'),
|
||||
safe = require('safetydance'),
|
||||
shell = require('./shell.js');
|
||||
shell = require('./shell.js')('database');
|
||||
|
||||
let gConnectionPool = null;
|
||||
|
||||
@@ -80,14 +80,14 @@ async function clear() {
|
||||
await fs.promises.writeFile('/tmp/extra.cnf', `[client]\nhost=${gDatabase.hostname}\nuser=${gDatabase.username}\npassword=${gDatabase.password}\ndatabase=${gDatabase.name}`, 'utf8');
|
||||
|
||||
const cmd = 'mysql --defaults-extra-file=/tmp/extra.cnf -Nse "SHOW TABLES" | grep -v "^migrations$" | while read table; do mysql --defaults-extra-file=/tmp/extra.cnf -e "SET FOREIGN_KEY_CHECKS = 0; TRUNCATE TABLE $table"; done';
|
||||
await shell.exec('clear_database', cmd, { shell: '/bin/bash' });
|
||||
await shell.exec(cmd, { shell: '/bin/bash' });
|
||||
}
|
||||
|
||||
async function query() {
|
||||
assert.notStrictEqual(gConnectionPool, null);
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
let args = Array.prototype.slice.call(arguments);
|
||||
const args = Array.prototype.slice.call(arguments);
|
||||
|
||||
args.push(function queryCallback(error, result) {
|
||||
if (error) return reject(new BoxError(BoxError.DATABASE_ERROR, error, { code: error.code, sqlMessage: error.sqlMessage || null }));
|
||||
@@ -138,7 +138,7 @@ async function importFromFile(file) {
|
||||
const cmd = `/usr/bin/mysql -h "${gDatabase.hostname}" -u ${gDatabase.username} -p${gDatabase.password} ${gDatabase.name} < ${file}`;
|
||||
|
||||
await query('CREATE DATABASE IF NOT EXISTS box');
|
||||
const [error] = await safe(shell.exec('importFromFile', cmd, { shell: '/bin/bash' }));
|
||||
const [error] = await safe(shell.exec(cmd, { shell: '/bin/bash' }));
|
||||
if (error) throw new BoxError(BoxError.DATABASE_ERROR, error);
|
||||
}
|
||||
|
||||
@@ -146,12 +146,12 @@ async function exportToFile(file) {
|
||||
assert.strictEqual(typeof file, 'string');
|
||||
|
||||
// latest mysqldump enables column stats by default which is not present in 5.7 util
|
||||
const mysqlDumpHelp = await shell.exec('exportToFile', '/usr/bin/mysqldump --help', {});
|
||||
const mysqlDumpHelp = await shell.exec('/usr/bin/mysqldump --help', {});
|
||||
const hasColStats = mysqlDumpHelp.includes('column-statistics');
|
||||
const colStats = hasColStats ? '--column-statistics=0' : '';
|
||||
|
||||
const cmd = `/usr/bin/mysqldump -h "${gDatabase.hostname}" -u root -p${gDatabase.password} ${colStats} --single-transaction --routines --triggers ${gDatabase.name} > "${file}"`;
|
||||
|
||||
const [error] = await safe(shell.exec('exportToFile', cmd, { shell: '/bin/bash' }));
|
||||
const [error] = await safe(shell.exec(cmd, { shell: '/bin/bash' }));
|
||||
if (error) throw new BoxError(BoxError.DATABASE_ERROR, error);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user