User version fixes
This commit is contained in:
parent
ff605249ad
commit
1566847ecd
|
@ -10,7 +10,7 @@ Any help is welcomed! Feel free to contribute.
|
||||||
|
|
||||||
## Requirements
|
## Requirements
|
||||||
|
|
||||||
* Node.js >= 12.0
|
* Node.js >= 14.0
|
||||||
* Git
|
* Git
|
||||||
* Docker (Local server)
|
* Docker (Local server)
|
||||||
|
|
||||||
|
|
24
myvc-push.js
24
myvc-push.js
|
@ -37,9 +37,7 @@ class Push {
|
||||||
throw new Error('Wrong database version');
|
throw new Error('Wrong database version');
|
||||||
|
|
||||||
if (opts.user) {
|
if (opts.user) {
|
||||||
const [[user]] = conn.query(
|
const user = await this.getDbUser();
|
||||||
`SELECT LEFT(USER(), INSTR(USER(), '@') - 1)`
|
|
||||||
);
|
|
||||||
let [[userVersion]] = await conn.query(
|
let [[userVersion]] = await conn.query(
|
||||||
`SELECT number, gitCommit
|
`SELECT number, gitCommit
|
||||||
FROM versionUser
|
FROM versionUser
|
||||||
|
@ -55,7 +53,9 @@ class Push {
|
||||||
);
|
);
|
||||||
|
|
||||||
if (userVersion.number > version.number)
|
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') {
|
if (opts.remote == 'production') {
|
||||||
|
@ -204,15 +204,17 @@ class Push {
|
||||||
await pushConn.end();
|
await pushConn.end();
|
||||||
|
|
||||||
if (nRoutines > 0) {
|
if (nRoutines > 0) {
|
||||||
const repo = await nodegit.Repository.open(this.opts.workspace);
|
|
||||||
const head = await repo.getHeadCommit();
|
|
||||||
|
|
||||||
await conn.query('FLUSH PRIVILEGES');
|
await conn.query('FLUSH PRIVILEGES');
|
||||||
await this.updateVersion(nRoutines, 'gitCommit', head.sha());
|
|
||||||
|
|
||||||
console.log(` -> ${nRoutines} routines have changed.`);
|
console.log(` -> ${nRoutines} routines have changed.`);
|
||||||
} else
|
} else
|
||||||
console.log(` -> No routines changed.`);
|
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) {
|
parseChanges(changes) {
|
||||||
|
@ -223,6 +225,11 @@ class Push {
|
||||||
return routines;
|
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) {
|
async updateVersion(nChanges, column, value) {
|
||||||
if (nChanges == 0) return;
|
if (nChanges == 0) return;
|
||||||
const {opts} = this;
|
const {opts} = this;
|
||||||
|
@ -230,6 +237,7 @@ class Push {
|
||||||
column = this.conn.escapeId(column, true);
|
column = this.conn.escapeId(column, true);
|
||||||
|
|
||||||
if (opts.user) {
|
if (opts.user) {
|
||||||
|
const user = await this.getDbUser();
|
||||||
await this.conn.query(
|
await this.conn.query(
|
||||||
`INSERT INTO versionUser
|
`INSERT INTO versionUser
|
||||||
SET code = ?,
|
SET code = ?,
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "myvc",
|
"name": "myvc",
|
||||||
"version": "1.1.1",
|
"version": "1.1.10",
|
||||||
"lockfileVersion": 1,
|
"lockfileVersion": 1,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
@ -10,9 +10,9 @@
|
||||||
"integrity": "sha512-/aPsuoj/1Dw/kzhkgz+ES6TxG0zfTMGLwuK2ZG00k/iJzYHTLCE8mVU8EPqEOp/lmxPoq1C1C9RYToRKb2KEfg=="
|
"integrity": "sha512-/aPsuoj/1Dw/kzhkgz+ES6TxG0zfTMGLwuK2ZG00k/iJzYHTLCE8mVU8EPqEOp/lmxPoq1C1C9RYToRKb2KEfg=="
|
||||||
},
|
},
|
||||||
"@sqltools/formatter": {
|
"@sqltools/formatter": {
|
||||||
"version": "1.2.2",
|
"version": "1.2.3",
|
||||||
"resolved": "https://registry.npmjs.org/@sqltools/formatter/-/formatter-1.2.2.tgz",
|
"resolved": "https://registry.npmjs.org/@sqltools/formatter/-/formatter-1.2.3.tgz",
|
||||||
"integrity": "sha512-/5O7Fq6Vnv8L6ucmPjaWbVG1XkP4FO+w5glqfkIsq3Xw4oyNAdJddbnYodNDAfjVUvo/rrSCTom4kAND7T1o5Q=="
|
"integrity": "sha512-O3uyB/JbkAEMZaP3YqyHH7TMnex7tWyCbCI4EfJdOCoN6HIhqdJBWTM6aCCiWQ/5f5wxjgU735QAIpJbjDvmzg=="
|
||||||
},
|
},
|
||||||
"@szmarczak/http-timer": {
|
"@szmarczak/http-timer": {
|
||||||
"version": "4.0.5",
|
"version": "4.0.5",
|
||||||
|
@ -616,9 +616,9 @@
|
||||||
"integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ=="
|
"integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ=="
|
||||||
},
|
},
|
||||||
"ini": {
|
"ini": {
|
||||||
"version": "1.3.5",
|
"version": "1.3.8",
|
||||||
"resolved": "https://registry.npmjs.org/ini/-/ini-1.3.5.tgz",
|
"resolved": "https://registry.npmjs.org/ini/-/ini-1.3.8.tgz",
|
||||||
"integrity": "sha512-RZY5huIKCMRWDUqZlEi72f/lmXKMvuszcMBduliQ3nnWbx9X/ZBQO7DijMEYS9EhHBb2qacRUMtC7svLwe0lcw=="
|
"integrity": "sha512-JV/yugV2uzW5iMRSiZAyDtQd+nxtUnjeLt0acNdw98kKLrvuRVyB80tsREOE7yvGVgalhZ6RNXCmEHkUKBKxew=="
|
||||||
},
|
},
|
||||||
"is-fullwidth-code-point": {
|
"is-fullwidth-code-point": {
|
||||||
"version": "1.0.0",
|
"version": "1.0.0",
|
||||||
|
@ -734,9 +734,9 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"lodash": {
|
"lodash": {
|
||||||
"version": "4.17.20",
|
"version": "4.17.21",
|
||||||
"resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.20.tgz",
|
"resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.21.tgz",
|
||||||
"integrity": "sha512-PlhdFcillOINfeV7Ni6oF1TAEayyZBoZ8bcshTHqOYJYlrqzRK5hagpagky5o4HfCzzd1TRkXPMFq6cKk9rGmA=="
|
"integrity": "sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg=="
|
||||||
},
|
},
|
||||||
"long": {
|
"long": {
|
||||||
"version": "4.0.0",
|
"version": "4.0.0",
|
||||||
|
@ -971,9 +971,9 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"normalize-url": {
|
"normalize-url": {
|
||||||
"version": "4.5.0",
|
"version": "4.5.1",
|
||||||
"resolved": "https://registry.npmjs.org/normalize-url/-/normalize-url-4.5.0.tgz",
|
"resolved": "https://registry.npmjs.org/normalize-url/-/normalize-url-4.5.1.tgz",
|
||||||
"integrity": "sha512-2s47yzUxdexf1OhyRi4Em83iQk0aPvwTddtFz4hnSSw9dCEsLEGf6SwIO8ss/19S9iBb5sJaOuTvTGDeZI00BQ=="
|
"integrity": "sha512-9UZCFRHQdNrfTpGg8+1INIg93B6zE0aXMVFkw1WFwvO4SlZywU6aLg5Of0Ap/PgcbSw4LNxvMWXMeugwMCX0AA=="
|
||||||
},
|
},
|
||||||
"npm-bundled": {
|
"npm-bundled": {
|
||||||
"version": "1.1.1",
|
"version": "1.1.1",
|
||||||
|
@ -1303,19 +1303,24 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"tar": {
|
"tar": {
|
||||||
"version": "4.4.13",
|
"version": "4.4.19",
|
||||||
"resolved": "https://registry.npmjs.org/tar/-/tar-4.4.13.tgz",
|
"resolved": "https://registry.npmjs.org/tar/-/tar-4.4.19.tgz",
|
||||||
"integrity": "sha512-w2VwSrBoHa5BsSyH+KxEqeQBAllHhccyMFVHtGtdMpF4W7IRWfZjFiQceJPChOeTsSDVUpER2T8FA93pr0L+QA==",
|
"integrity": "sha512-a20gEsvHnWe0ygBY8JbxoM4w3SJdhc7ZAuxkLqh+nvNQN2IOt0B5lLgM490X5Hl8FF0dl0tOf2ewFYAlIFgzVA==",
|
||||||
"requires": {
|
"requires": {
|
||||||
"chownr": "^1.1.1",
|
"chownr": "^1.1.4",
|
||||||
"fs-minipass": "^1.2.5",
|
"fs-minipass": "^1.2.7",
|
||||||
"minipass": "^2.8.6",
|
"minipass": "^2.9.0",
|
||||||
"minizlib": "^1.2.1",
|
"minizlib": "^1.3.3",
|
||||||
"mkdirp": "^0.5.0",
|
"mkdirp": "^0.5.5",
|
||||||
"safe-buffer": "^5.1.2",
|
"safe-buffer": "^5.2.1",
|
||||||
"yallist": "^3.0.3"
|
"yallist": "^3.1.1"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"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": {
|
"yallist": {
|
||||||
"version": "3.1.1",
|
"version": "3.1.1",
|
||||||
"resolved": "https://registry.npmjs.org/yallist/-/yallist-3.1.1.tgz",
|
"resolved": "https://registry.npmjs.org/yallist/-/yallist-3.1.1.tgz",
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "myvc",
|
"name": "myvc",
|
||||||
"version": "1.1.9",
|
"version": "1.1.10",
|
||||||
"author": "Verdnatura Levante SL",
|
"author": "Verdnatura Levante SL",
|
||||||
"description": "MySQL Version Control",
|
"description": "MySQL Version Control",
|
||||||
"license": "GPL-3.0",
|
"license": "GPL-3.0",
|
||||||
|
@ -10,12 +10,12 @@
|
||||||
"url": "https://github.com/verdnatura/myvc.git"
|
"url": "https://github.com/verdnatura/myvc.git"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@sqltools/formatter": "^1.2.2",
|
"@sqltools/formatter": "^1.2.3",
|
||||||
"colors": "^1.4.0",
|
"colors": "^1.4.0",
|
||||||
"ejs": "^3.1.5",
|
"ejs": "^3.1.5",
|
||||||
"fs-extra": "^8.1.0",
|
"fs-extra": "^8.1.0",
|
||||||
"getopts": "^2.2.5",
|
"getopts": "^2.2.5",
|
||||||
"ini": "^1.3.5",
|
"ini": "^1.3.8",
|
||||||
"mysql2": "^2.2.5",
|
"mysql2": "^2.2.5",
|
||||||
"nodegit": "^0.27.0",
|
"nodegit": "^0.27.0",
|
||||||
"require-yaml": "0.0.1"
|
"require-yaml": "0.0.1"
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
|
|
||||||
CREATE TABLE `version` (
|
CREATE TABLE `version` (
|
||||||
`code` varchar(255) NOT NULL,
|
`code` varchar(255) NOT NULL,
|
||||||
`number` char(11) NULL,
|
`number` char(11) NULL DEFAULT NULL,
|
||||||
`gitCommit` varchar(255) NULL,
|
`gitCommit` varchar(255) NULL DEFAULT NULL,
|
||||||
`updated` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
|
`updated` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
|
||||||
) ENGINE=InnoDB;
|
) ENGINE=InnoDB;
|
||||||
|
|
||||||
|
@ -12,8 +12,8 @@ ALTER TABLE `version`
|
||||||
CREATE TABLE `versionUser` (
|
CREATE TABLE `versionUser` (
|
||||||
`code` varchar(255) NOT NULL,
|
`code` varchar(255) NOT NULL,
|
||||||
`user` varchar(255) NOT NULL,
|
`user` varchar(255) NOT NULL,
|
||||||
`number` char(11) NULL,
|
`number` char(11) NULL DEFAULT NULL,
|
||||||
`gitCommit` varchar(255) NULL,
|
`gitCommit` varchar(255) NULL DEFAULT NULL,
|
||||||
`updated` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
|
`updated` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
|
||||||
) ENGINE=InnoDB;
|
) ENGINE=InnoDB;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue