myt/myt-dump.js

63 lines
1.6 KiB
JavaScript
Raw Normal View History

2022-12-21 13:17:50 +00:00
const Myt = require('./myt');
const Command = require('./lib/command');
2020-12-02 07:35:26 +00:00
const fs = require('fs-extra');
const Dumper = require('./lib/dumper');
2020-12-02 07:35:26 +00:00
class Dump extends Command {
static usage = {
description: 'Dumps structure and fixtures from remote',
operand: 'remote'
};
static opts = {
default: {
remote: 'production'
}
};
2020-12-02 07:35:26 +00:00
2022-12-21 13:17:50 +00:00
async run(myt, opts) {
const dumper = new Dumper(opts);
await dumper.init('.dump.sql');
2020-12-02 07:35:26 +00:00
2022-07-12 07:45:05 +00:00
console.log('Dumping structure.');
2020-12-02 07:35:26 +00:00
let dumpArgs = [
'--default-character-set=utf8',
'--no-data',
'--comments',
'--routines',
'--events',
'--skip-triggers',
2020-12-02 07:35:26 +00:00
'--databases'
];
dumpArgs = dumpArgs.concat(opts.schemas);
await dumper.runDump('docker-dump.sh', dumpArgs);
2020-12-02 07:35:26 +00:00
2022-07-12 07:45:05 +00:00
console.log('Dumping fixtures.');
await dumper.dumpFixtures(opts.fixtures);
2022-07-12 07:45:05 +00:00
console.log('Dumping privileges.');
const privs = opts.privileges;
if (privs && Array.isArray(privs.tables)) {
let args = [
'--no-create-info',
'--skip-triggers',
'--insert-ignore',
'--complete-insert'
];
if (privs.where) args.push('--where', privs.where);
args = args.concat(['mysql'], privs.tables);
await dumper.use('mysql');
await dumper.runDump('mysqldump', args);
2022-07-12 07:45:05 +00:00
}
await dumper.end();
2020-12-02 07:35:26 +00:00
}
}
module.exports = Dump;
if (require.main === module)
2022-12-21 13:17:50 +00:00
new Myt().run(Dump);
2020-12-02 07:35:26 +00:00