diff --git a/myt-push.js b/myt-push.js index 57db880..393e491 100644 --- a/myt-push.js +++ b/myt-push.js @@ -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(); diff --git a/myt-run.js b/myt-run.js index fb4a166..e833ac3 100644 --- a/myt-run.js +++ b/myt-run.js @@ -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 diff --git a/myt-start.js b/myt-start.js index 9d13ba4..e3a8411 100644 --- a/myt-start.js +++ b/myt-start.js @@ -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; } } diff --git a/myt.js b/myt.js index bac2ff0..aa31c57 100755 --- a/myt.js +++ b/myt.js @@ -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) { diff --git a/package-lock.json b/package-lock.json index ec8f3c0..c6e99d0 100644 --- a/package-lock.json +++ b/package-lock.json @@ -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", diff --git a/package.json b/package.json index 4736c6f..2a8a30d 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/template/package.json b/template/package.json index 72581da..09a9dc6 100644 --- a/template/package.json +++ b/template/package.json @@ -8,6 +8,6 @@ "type": "git" }, "dependencies": { - "@verdnatura/myt": "^1.5.5" + "@verdnatura/myt": "^1.5.6" } }