From 74561dbd6b501e49766cedd6dc872bcb2956be91 Mon Sep 17 00:00:00 2001 From: Juan Ferrer Toribio Date: Tue, 12 Jul 2022 09:45:05 +0200 Subject: [PATCH] dump: Dump privileges --- README.md | 3 ++- myvc-dump.js | 20 ++++++++++++++++++++ package-lock.json | 4 ++-- package.json | 2 +- server/Dockerfile.dump | 6 ++++-- template/package.json | 2 +- 6 files changed, 30 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index a2f3b62..57a9c7f 100644 --- a/README.md +++ b/README.md @@ -146,7 +146,8 @@ routines. You can create your local fixture and structure files. -* *dump/structure.sql* +* *dump/beforeDump.sql* +* *dump/afterDump.sql* * *dump/fixtures.sql* ## Versioning commands diff --git a/myvc-dump.js b/myvc-dump.js index 4ccecfe..97b9c77 100644 --- a/myvc-dump.js +++ b/myvc-dump.js @@ -22,6 +22,7 @@ class Dump { async run(myvc, opts) { const dumpStream = await myvc.initDump('.dump.sql'); + console.log('Dumping structure.'); let dumpArgs = [ '--default-character-set=utf8', '--no-data', @@ -34,9 +35,28 @@ class Dump { dumpArgs = dumpArgs.concat(opts.schemas); await myvc.runDump('myvc-dump.sh', dumpArgs, dumpStream); + console.log('Dumping fixtures.'); await myvc.dumpFixtures(dumpStream, opts.fixtures); + + 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 dumpStream.write('USE `mysql`;\n', 'utf8'); + await myvc.runDump('myvc-dump.sh', args, dumpStream); + } + await dumpStream.end(); + console.log('Saving version.'); await myvc.dbConnect(); const version = await myvc.fetchDbVersion(); if (version) { diff --git a/package-lock.json b/package-lock.json index 9cedd8d..cca73e1 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "myvc", - "version": "1.4.14", + "version": "1.4.15", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "myvc", - "version": "1.4.14", + "version": "1.4.15", "license": "GPL-3.0", "dependencies": { "@sqltools/formatter": "^1.2.3", diff --git a/package.json b/package.json index 0058993..af0188e 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "myvc", - "version": "1.4.14", + "version": "1.4.15", "author": "Verdnatura Levante SL", "description": "MySQL Version Control", "license": "GPL-3.0", diff --git a/server/Dockerfile.dump b/server/Dockerfile.dump index 69e389f..1fd154e 100644 --- a/server/Dockerfile.dump +++ b/server/Dockerfile.dump @@ -4,14 +4,16 @@ USER root COPY \ dump/.dump.sql \ - dump/structure.sql \ + dump/beforeDump.sql \ + dump/afterDump.sql \ dump/ COPY myvc.config.yml \ ./ RUN gosu mysql docker-init.sh \ - && docker-dump.sh dump/structure \ + && docker-dump.sh dump/beforeDump \ && docker-dump.sh dump/.dump \ + && docker-dump.sh dump/afterDump \ && gosu mysql docker-temp-stop.sh COPY routines routines diff --git a/template/package.json b/template/package.json index 164ba59..776723a 100644 --- a/template/package.json +++ b/template/package.json @@ -8,6 +8,6 @@ "type": "git" }, "dependencies": { - "myvc": "^1.4.14" + "myvc": "^1.4.15" } }