#4550 Fixtures fix: triggers disabled, code clean, start fix

This commit is contained in:
Juan Ferrer 2022-12-23 14:47:44 +01:00
parent 4e5f446e58
commit 0cb3ec8573
7 changed files with 41 additions and 36 deletions

View File

@ -14,7 +14,8 @@ class Push extends Command {
params: {
force: 'Answer yes to all questions',
commit: 'Wether to save the commit SHA into database',
sums: 'Save SHA sums of pushed objects'
sums: 'Save SHA sums of pushed objects',
triggers: 'Wether to exclude triggers, used to generate local DB'
},
operand: 'remote'
};
@ -23,12 +24,14 @@ class Push extends Command {
alias: {
force: 'f',
commit: 'c',
sums: 's'
sums: 's',
triggers: 't'
},
boolean: [
'force',
'commit',
'sums'
'sums',
'triggers'
]
};
@ -297,6 +300,9 @@ class Push extends Command {
for (const change of changes)
try {
if (opts.trigger && change.type.name === 'TRIGGER')
continue;
const schema = change.schema;
const name = change.name;
const type = change.type.name.toLowerCase();

View File

@ -40,7 +40,7 @@ class Run extends Command {
if (!await fs.pathExists(`${dumpDir}/.dump.sql`))
throw new Error('To run local database you have to create a dump first');
// Build base server image
// Build base image
let serverDockerfile = path.join(dumpDir, 'Dockerfile');
if (!await fs.pathExists(serverDockerfile))
@ -51,7 +51,7 @@ class Run extends Command {
file: serverDockerfile
}, opts.debug);
// Build myt server image
// Build server image
await docker.build(__dirname, {
tag: 'myt/server',
@ -60,17 +60,9 @@ class Run extends Command {
// Build dump image
const today = new Date();
const pad = v => v < 10 ? '0' + v : v;
const year = today.getFullYear();
const month = pad(today.getMonth() + 1);
const day = pad(today.getDate());
const stamp = `${year}-${month}-${day}`;
await docker.build(opts.mytDir, {
tag: opts.code,
file: path.join(serverDir, 'Dockerfile.dump'),
buildArg: `STAMP=${stamp}`
file: path.join(serverDir, 'Dockerfile.dump')
}, opts.debug);
// Run container
@ -98,7 +90,7 @@ class Run extends Command {
Object.assign(runOptions, null, {
env: `RUN_CHOWN=${runChown}`,
detach: true,
volume: `${path.join(dumpDir, 'fixtures.sql')}:/fixtures.sql:ro`
volume: `${this.opts.mytDir}:/workspace`
});
const ct = await docker.run(opts.code, null, runOptions);
const server = new Server(ct, dbConfig);
@ -125,6 +117,7 @@ class Run extends Command {
Object.assign(opts, {
commit: true,
trigger: true,
dbConfig
});
await myt.runCommand(Push, opts);
@ -133,7 +126,11 @@ class Run extends Command {
console.log('Applying fixtures.');
await ct.exec(null,
'docker-import.sh', ['/fixtures'], 'spawn', opts.debug);
'docker-import.sh',
['/workspace/dump/fixtures'],
'spawn',
opts.debug
);
// Create triggers

View File

@ -19,28 +19,32 @@ class Start extends Command {
async run(myt, opts) {
const ct = new Container(opts.code);
let status;
let exists;
let server;
try {
status = await ct.inspect({
format: '{{json .State.Status}}'
});
exists = true;
} catch (err) {
const run = new Run()
return await run.run(myt, opts);
server = await myt.runCommand(Run, opts);
}
switch (status) {
case 'running':
break;
case 'exited':
await ct.start();
break;
default:
throw new Error(`Unknown docker status: ${status}`);
if (exists) {
switch (status) {
case 'running':
break;
case 'exited':
await ct.start();
server = new Server(ct, opts.dbConfig);
await server.wait();
break;
default:
throw new Error(`Unknown docker status: ${status}`);
}
}
const server = new Server(ct, opts.dbConfig);
await server.wait();
return server;
}
}

2
myt.js
View File

@ -172,7 +172,7 @@ class Myt {
async runCommand(CommandClass, opts) {
const command = new CommandClass();
command.opts = opts;
await command.run(this, opts);
return await command.run(this, opts);
}
async load(opts) {

4
package-lock.json generated
View File

@ -1,12 +1,12 @@
{
"name": "@verdnatura/myt",
"version": "1.5.5",
"version": "1.5.6",
"lockfileVersion": 2,
"requires": true,
"packages": {
"": {
"name": "@verdnatura/myt",
"version": "1.5.5",
"version": "1.5.6",
"license": "GPL-3.0",
"dependencies": {
"@sqltools/formatter": "^1.2.3",

View File

@ -1,13 +1,11 @@
{
"name": "@verdnatura/myt",
"version": "1.5.5",
"version": "1.5.6",
"author": "Verdnatura Levante SL",
"description": "MySQL version control",
"license": "GPL-3.0",
"bin": {
"myt": "cli.js",
"myvc": "cli.js",
"myv": "cli.js"
"myt": "cli.js"
},
"repository": {
"type": "git",

View File

@ -8,6 +8,6 @@
"type": "git"
},
"dependencies": {
"@verdnatura/myt": "^1.5.5"
"@verdnatura/myt": "^1.5.6"
}
}