2022-12-21 13:17:50 +00:00
|
|
|
const Myt = require('./myt');
|
2022-12-21 12:34:17 +00:00
|
|
|
const Command = require('./lib/command');
|
2020-12-02 07:35:26 +00:00
|
|
|
const fs = require('fs-extra');
|
2022-12-29 09:15:02 +00:00
|
|
|
const Dumper = require('./lib/dumper');
|
2020-12-02 07:35:26 +00:00
|
|
|
|
2022-12-21 12:34:17 +00:00
|
|
|
class Dump extends Command {
|
|
|
|
static usage = {
|
|
|
|
description: 'Dumps structure and fixtures from remote',
|
|
|
|
operand: 'remote'
|
|
|
|
};
|
2021-10-25 13:38:07 +00:00
|
|
|
|
2022-12-29 09:15:02 +00:00
|
|
|
static opts = {
|
2022-12-21 12:34:17 +00:00
|
|
|
default: {
|
|
|
|
remote: 'production'
|
|
|
|
}
|
|
|
|
};
|
2020-12-02 07:35:26 +00:00
|
|
|
|
2022-12-21 13:17:50 +00:00
|
|
|
async run(myt, opts) {
|
2022-12-29 09:15:02 +00:00
|
|
|
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',
|
2023-01-27 08:08:15 +00:00
|
|
|
'--skip-triggers',
|
2020-12-02 07:35:26 +00:00
|
|
|
'--databases'
|
|
|
|
];
|
|
|
|
dumpArgs = dumpArgs.concat(opts.schemas);
|
2022-12-29 09:15:02 +00:00
|
|
|
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.');
|
2022-12-29 09:15:02 +00:00
|
|
|
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);
|
2022-12-29 09:15:02 +00:00
|
|
|
|
|
|
|
await dumper.use('mysql');
|
|
|
|
await dumper.runDump('mysqldump', args);
|
2022-07-12 07:45:05 +00:00
|
|
|
}
|
|
|
|
|
2022-12-29 09:15:02 +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
|
|
|
|