User version fixes

This commit is contained in:
Juan Ferrer 2021-10-16 08:44:19 +02:00
parent ff605249ad
commit 1566847ecd
5 changed files with 52 additions and 39 deletions

View File

@ -10,7 +10,7 @@ Any help is welcomed! Feel free to contribute.
## Requirements
* Node.js >= 12.0
* Node.js >= 14.0
* Git
* Docker (Local server)

View File

@ -37,9 +37,7 @@ class Push {
throw new Error('Wrong database version');
if (opts.user) {
const [[user]] = conn.query(
`SELECT LEFT(USER(), INSTR(USER(), '@') - 1)`
);
const user = await this.getDbUser();
let [[userVersion]] = await conn.query(
`SELECT number, gitCommit
FROM versionUser
@ -55,7 +53,9 @@ class Push {
);
if (userVersion.number > version.number)
version = userVersion;
version.number = userVersion.number;
if (userVersion.gitCommit && userVersion.gitCommit !== version.gitCommit)
version.gitCommit = userVersion.gitCommit;
}
if (opts.remote == 'production') {
@ -204,15 +204,17 @@ class Push {
await pushConn.end();
if (nRoutines > 0) {
const repo = await nodegit.Repository.open(this.opts.workspace);
const head = await repo.getHeadCommit();
await conn.query('FLUSH PRIVILEGES');
await this.updateVersion(nRoutines, 'gitCommit', head.sha());
console.log(` -> ${nRoutines} routines have changed.`);
} else
console.log(` -> No routines changed.`);
const repo = await nodegit.Repository.open(this.opts.workspace);
const head = await repo.getHeadCommit();
if (version.gitCommit !== head.sha())
await this.updateVersion(nRoutines, 'gitCommit', head.sha());
}
parseChanges(changes) {
@ -223,6 +225,11 @@ class Push {
return routines;
}
async getDbUser() {
const [[row]] = await this.conn.query('SELECT USER() `user`');
return row.user.substr(0, row.user.indexOf('@'));
}
async updateVersion(nChanges, column, value) {
if (nChanges == 0) return;
const {opts} = this;
@ -230,6 +237,7 @@ class Push {
column = this.conn.escapeId(column, true);
if (opts.user) {
const user = await this.getDbUser();
await this.conn.query(
`INSERT INTO versionUser
SET code = ?,

51
package-lock.json generated
View File

@ -1,6 +1,6 @@
{
"name": "myvc",
"version": "1.1.1",
"version": "1.1.10",
"lockfileVersion": 1,
"requires": true,
"dependencies": {
@ -10,9 +10,9 @@
"integrity": "sha512-/aPsuoj/1Dw/kzhkgz+ES6TxG0zfTMGLwuK2ZG00k/iJzYHTLCE8mVU8EPqEOp/lmxPoq1C1C9RYToRKb2KEfg=="
},
"@sqltools/formatter": {
"version": "1.2.2",
"resolved": "https://registry.npmjs.org/@sqltools/formatter/-/formatter-1.2.2.tgz",
"integrity": "sha512-/5O7Fq6Vnv8L6ucmPjaWbVG1XkP4FO+w5glqfkIsq3Xw4oyNAdJddbnYodNDAfjVUvo/rrSCTom4kAND7T1o5Q=="
"version": "1.2.3",
"resolved": "https://registry.npmjs.org/@sqltools/formatter/-/formatter-1.2.3.tgz",
"integrity": "sha512-O3uyB/JbkAEMZaP3YqyHH7TMnex7tWyCbCI4EfJdOCoN6HIhqdJBWTM6aCCiWQ/5f5wxjgU735QAIpJbjDvmzg=="
},
"@szmarczak/http-timer": {
"version": "4.0.5",
@ -616,9 +616,9 @@
"integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ=="
},
"ini": {
"version": "1.3.5",
"resolved": "https://registry.npmjs.org/ini/-/ini-1.3.5.tgz",
"integrity": "sha512-RZY5huIKCMRWDUqZlEi72f/lmXKMvuszcMBduliQ3nnWbx9X/ZBQO7DijMEYS9EhHBb2qacRUMtC7svLwe0lcw=="
"version": "1.3.8",
"resolved": "https://registry.npmjs.org/ini/-/ini-1.3.8.tgz",
"integrity": "sha512-JV/yugV2uzW5iMRSiZAyDtQd+nxtUnjeLt0acNdw98kKLrvuRVyB80tsREOE7yvGVgalhZ6RNXCmEHkUKBKxew=="
},
"is-fullwidth-code-point": {
"version": "1.0.0",
@ -734,9 +734,9 @@
}
},
"lodash": {
"version": "4.17.20",
"resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.20.tgz",
"integrity": "sha512-PlhdFcillOINfeV7Ni6oF1TAEayyZBoZ8bcshTHqOYJYlrqzRK5hagpagky5o4HfCzzd1TRkXPMFq6cKk9rGmA=="
"version": "4.17.21",
"resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.21.tgz",
"integrity": "sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg=="
},
"long": {
"version": "4.0.0",
@ -971,9 +971,9 @@
}
},
"normalize-url": {
"version": "4.5.0",
"resolved": "https://registry.npmjs.org/normalize-url/-/normalize-url-4.5.0.tgz",
"integrity": "sha512-2s47yzUxdexf1OhyRi4Em83iQk0aPvwTddtFz4hnSSw9dCEsLEGf6SwIO8ss/19S9iBb5sJaOuTvTGDeZI00BQ=="
"version": "4.5.1",
"resolved": "https://registry.npmjs.org/normalize-url/-/normalize-url-4.5.1.tgz",
"integrity": "sha512-9UZCFRHQdNrfTpGg8+1INIg93B6zE0aXMVFkw1WFwvO4SlZywU6aLg5Of0Ap/PgcbSw4LNxvMWXMeugwMCX0AA=="
},
"npm-bundled": {
"version": "1.1.1",
@ -1303,19 +1303,24 @@
}
},
"tar": {
"version": "4.4.13",
"resolved": "https://registry.npmjs.org/tar/-/tar-4.4.13.tgz",
"integrity": "sha512-w2VwSrBoHa5BsSyH+KxEqeQBAllHhccyMFVHtGtdMpF4W7IRWfZjFiQceJPChOeTsSDVUpER2T8FA93pr0L+QA==",
"version": "4.4.19",
"resolved": "https://registry.npmjs.org/tar/-/tar-4.4.19.tgz",
"integrity": "sha512-a20gEsvHnWe0ygBY8JbxoM4w3SJdhc7ZAuxkLqh+nvNQN2IOt0B5lLgM490X5Hl8FF0dl0tOf2ewFYAlIFgzVA==",
"requires": {
"chownr": "^1.1.1",
"fs-minipass": "^1.2.5",
"minipass": "^2.8.6",
"minizlib": "^1.2.1",
"mkdirp": "^0.5.0",
"safe-buffer": "^5.1.2",
"yallist": "^3.0.3"
"chownr": "^1.1.4",
"fs-minipass": "^1.2.7",
"minipass": "^2.9.0",
"minizlib": "^1.3.3",
"mkdirp": "^0.5.5",
"safe-buffer": "^5.2.1",
"yallist": "^3.1.1"
},
"dependencies": {
"safe-buffer": {
"version": "5.2.1",
"resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.2.1.tgz",
"integrity": "sha512-rp3So07KcdmmKbGvgaNxQSJr7bGVSVk5S9Eq1F+ppbRo70+YeaDxkw5Dd8NPN+GD6bjnYm2VuPuCXmpuYvmCXQ=="
},
"yallist": {
"version": "3.1.1",
"resolved": "https://registry.npmjs.org/yallist/-/yallist-3.1.1.tgz",

View File

@ -1,6 +1,6 @@
{
"name": "myvc",
"version": "1.1.9",
"version": "1.1.10",
"author": "Verdnatura Levante SL",
"description": "MySQL Version Control",
"license": "GPL-3.0",
@ -10,12 +10,12 @@
"url": "https://github.com/verdnatura/myvc.git"
},
"dependencies": {
"@sqltools/formatter": "^1.2.2",
"@sqltools/formatter": "^1.2.3",
"colors": "^1.4.0",
"ejs": "^3.1.5",
"fs-extra": "^8.1.0",
"getopts": "^2.2.5",
"ini": "^1.3.5",
"ini": "^1.3.8",
"mysql2": "^2.2.5",
"nodegit": "^0.27.0",
"require-yaml": "0.0.1"

View File

@ -1,8 +1,8 @@
CREATE TABLE `version` (
`code` varchar(255) NOT NULL,
`number` char(11) NULL,
`gitCommit` varchar(255) NULL,
`number` char(11) NULL DEFAULT NULL,
`gitCommit` varchar(255) NULL DEFAULT NULL,
`updated` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
) ENGINE=InnoDB;
@ -12,8 +12,8 @@ ALTER TABLE `version`
CREATE TABLE `versionUser` (
`code` varchar(255) NOT NULL,
`user` varchar(255) NOT NULL,
`number` char(11) NULL,
`gitCommit` varchar(255) NULL,
`number` char(11) NULL DEFAULT NULL,
`gitCommit` varchar(255) NULL DEFAULT NULL,
`updated` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
) ENGINE=InnoDB;