From a9d9e208c45fd1ea916db25aad8b9340a47b43e6 Mon Sep 17 00:00:00 2001 From: Juan Ferrer Toribio Date: Wed, 15 Mar 2023 18:13:01 +0100 Subject: [PATCH] fixes #5421 push order/logging fix, check version fix, time mock --- assets/myt.default.yml | 1 + myt-push.js | 26 ++++++++++++++++++-------- myt-run.js | 15 +++++++++++++++ myt.js | 4 ++-- package-lock.json | 16 ++++++++-------- package.json | 2 +- 6 files changed, 45 insertions(+), 19 deletions(-) diff --git a/assets/myt.default.yml b/assets/myt.default.yml index f9cadf9..e7e66f7 100755 --- a/assets/myt.default.yml +++ b/assets/myt.default.yml @@ -1,6 +1,7 @@ versionSchema: myt versionDigits: 5 maxOldVersions: 20 +mockDate: false sumViews: true schemas: - myt diff --git a/myt-push.js b/myt-push.js index dfd032c..1909252 100644 --- a/myt-push.js +++ b/myt-push.js @@ -321,16 +321,26 @@ class Push extends Command { const oldSum = engine.getShaSum(type, schema, name); const isEqual = newSql == oldSql; - let actionMsg; - if ((exists && isEqual) || (!exists && !oldSql)) - actionMsg = '[I]'.blue; - else if (exists) - actionMsg = '[+]'.green; + let statusMsg; + if (exists && !oldSql) + statusMsg = '[+]'.green; + else if (!exists) + statusMsg = '[-]'.red; else - actionMsg = '[-]'.red; + statusMsg = '[ยท]'.yellow; + + let actionMsg; + if (isEqual) + actionMsg = '[I]'.blue; + else + actionMsg = '[A]'.green; const typeMsg = `[${change.type.abbr}]`[change.type.color]; - console.log('', actionMsg.bold, typeMsg.bold, change.fullName); + console.log('', + (statusMsg + actionMsg).bold, + typeMsg.bold, + change.fullName + ); if (!isEqual) { const scapedSchema = SqlString.escapeId(schema, true); @@ -475,7 +485,7 @@ class Push extends Command { return routines.sort((a, b) => { if (b.mark != a.mark) - return b.mark == '-' ? 1 : -1; + return b.mark == '-' ? -1 : 1; if (b.type.name !== a.type.name) { if (b.type.name == 'VIEW') diff --git a/myt-run.js b/myt-run.js index 9bd7450..b9d8aad 100644 --- a/myt-run.js +++ b/myt-run.js @@ -6,6 +6,7 @@ const fs = require('fs-extra'); const path = require('path'); const Server = require('./lib/server'); const connExt = require('./lib/conn'); +const SqlString = require('sqlstring'); /** * Builds the database image and runs a container. It only rebuilds the @@ -152,6 +153,20 @@ class Run extends Command { await connExt.queryFromFile(conn, `${triggersPath}/${triggerFile}`); } + // Mock date functions + + console.log('Mocking date functions.'); + const mockDateScript = path.join(dumpDir, 'mockDate.sql'); + + if (opts.mockDate) { + if (!await fs.pathExists(mockDateScript)) + throw new Error(`Date mock enabled but mock script does not exist: ${mockDateScript}`); + + let sql = await fs.readFile(mockDateScript, 'utf8'); + sql = sql.replace(/@mockDate/g, SqlString.escape(opts.mockDate)); + await connExt.multiQuery(conn, sql); + } + return server; } } diff --git a/myt.js b/myt.js index ee86e4d..492a4ea 100755 --- a/myt.js +++ b/myt.js @@ -120,8 +120,8 @@ class Myt { const wsPackageJson = require(wsPackageFile); try { depVersion = wsPackageJson - .dependencies - .myt.match(versionRegex); + .dependencies[packageJson.name] + .match(versionRegex); } catch (e) {} } diff --git a/package-lock.json b/package-lock.json index 8c5c349..4a92fd2 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@verdnatura/myt", - "version": "1.5.14", + "version": "1.5.15", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@verdnatura/myt", - "version": "1.5.14", + "version": "1.5.15", "license": "GPL-3.0", "dependencies": { "@sqltools/formatter": "^1.2.5", @@ -722,9 +722,9 @@ "integrity": "sha512-8Rf9Y83NBReMnx0gFzA8JImQACstCYWUplepDa9xprwwtmgEZUF0h/i5xSA625zB/I37EtrswSST6OXxwaaIJQ==" }, "node_modules/http-cache-semantics": { - "version": "4.1.0", - "resolved": "https://registry.npmjs.org/http-cache-semantics/-/http-cache-semantics-4.1.0.tgz", - "integrity": "sha512-carPklcUh7ROWRK7Cv27RPtdhYhUsela/ue5/jKzjegVvXDqM2ILE9Q2BGn9JZJh1g87cp56su/FgQSzcWS8cQ==" + "version": "4.1.1", + "resolved": "https://registry.npmjs.org/http-cache-semantics/-/http-cache-semantics-4.1.1.tgz", + "integrity": "sha512-er295DKPVsV82j5kw1Gjt+ADA/XYHsajl82cGNQG2eyoPkvgUhX+nDIyelzhIWbbsXP39EHcI6l5tYs2FYqYXQ==" }, "node_modules/http-signature": { "version": "1.2.0", @@ -2411,9 +2411,9 @@ "integrity": "sha512-8Rf9Y83NBReMnx0gFzA8JImQACstCYWUplepDa9xprwwtmgEZUF0h/i5xSA625zB/I37EtrswSST6OXxwaaIJQ==" }, "http-cache-semantics": { - "version": "4.1.0", - "resolved": "https://registry.npmjs.org/http-cache-semantics/-/http-cache-semantics-4.1.0.tgz", - "integrity": "sha512-carPklcUh7ROWRK7Cv27RPtdhYhUsela/ue5/jKzjegVvXDqM2ILE9Q2BGn9JZJh1g87cp56su/FgQSzcWS8cQ==" + "version": "4.1.1", + "resolved": "https://registry.npmjs.org/http-cache-semantics/-/http-cache-semantics-4.1.1.tgz", + "integrity": "sha512-er295DKPVsV82j5kw1Gjt+ADA/XYHsajl82cGNQG2eyoPkvgUhX+nDIyelzhIWbbsXP39EHcI6l5tYs2FYqYXQ==" }, "http-signature": { "version": "1.2.0", diff --git a/package.json b/package.json index a1ee400..0f4d99d 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@verdnatura/myt", - "version": "1.5.14", + "version": "1.5.15", "author": "Verdnatura Levante SL", "description": "MySQL version control", "license": "GPL-3.0",