This commit is contained in:
Juan Ferrer 2022-06-09 11:42:03 +02:00
parent 8c3badaa75
commit fa8552c54f
4 changed files with 45 additions and 23 deletions

View File

@ -39,7 +39,7 @@ class Push {
const conn = await myvc.dbConnect();
this.conn = conn;
if (opts.commit == null && opts.remote == 'local')
if (opts.remote == 'local')
opts.commit = true;
// Obtain exclusive lock
@ -557,6 +557,9 @@ class Routine {
const type = typeMap[split[1]];
const name = split[2];
if (split.length !== 3 || !type)
throw new Error(`Wrong routine path for '${path}', check that the sql file is located in the correct directory`);
Object.assign(this, {
path,
mark: change.mark,

29
myvc.js
View File

@ -9,6 +9,7 @@ const ini = require('ini');
const path = require('path');
const mysql = require('mysql2/promise');
const nodegit = require('nodegit');
const { networkInterfaces } = require('os');
const camelToSnake = require('./lib').camelToSnake;
class MyVC {
@ -49,6 +50,11 @@ class MyVC {
};
const opts = this.getopts(baseOpts);
if (opts.debug) {
console.warn('Debug mode enabled.'.yellow);
console.log('Global options:'.magenta, opts);
}
if (opts.version)
process.exit(0);
@ -93,12 +99,17 @@ class MyVC {
}
const commandOpts = this.getopts(allOpts);
if (opts.debug)
console.log('Command options:'.magenta, commandOpts);
Object.assign(opts, commandOpts);
const operandToOpt = command.usage.operand;
if (opts._.length >= 2 && operandToOpt)
opts[operandToOpt] = opts._[1];
if (opts.debug)
console.log('Final options:'.magenta, opts);
if (opts.help) {
this.showHelp(command.localOpts, command.usage, commandName);
process.exit(0);
@ -145,9 +156,9 @@ class MyVC {
} catch (err) {
if (err.name == 'Error' && !opts.debug) {
console.error('Error:'.gray, err.message.red);
process.exit(1);
console.log(`You can get more details about the error by passing the 'debug' option.`.yellow);
} else
throw err;
console.log(err.stack.magenta);
}
function parameter(parameter, value) {
@ -187,8 +198,10 @@ class MyVC {
if (!await fs.pathExists(iniPath))
throw new Error(`Database config file not found: ${iniPath}`);
let dbConfig;
try {
const iniConfig = ini.parse(await fs.readFile(iniPath, 'utf8')).client;
const dbConfig = {
dbConfig = {
host: iniConfig.host,
port: iniConfig.port,
user: iniConfig.user,
@ -200,13 +213,18 @@ class MyVC {
}
}
};
if (iniConfig.ssl_ca) {
dbConfig.ssl = {
ca: await fs.readFile(`${opts.myvcDir}/${iniConfig.ssl_ca}`),
rejectUnauthorized: iniConfig.ssl_verify_server_cert != undefined
}
}
} catch(err) {
const newErr = Error(`Cannot process the ini file, check that the syntax is correct: ${iniPath}`);
newErr.stack += `\nCaused by: ${err.stack}`;
throw newErr;
}
if (opts.socket)
dbConfig.socketPath = '/var/run/mysqld/mysqld.sock';
@ -255,7 +273,8 @@ class MyVC {
);
if (!res.tableExists) {
const structure = await fs.readFile(`${__dirname}/structure.sql`, 'utf8');
const structure = await fs.readFile(
`${__dirname}/structure.sql`, 'utf8');
await conn.query(structure);
}
}

View File

@ -1,6 +1,6 @@
{
"name": "myvc",
"version": "1.4.7",
"version": "1.4.8",
"author": "Verdnatura Levante SL",
"description": "MySQL Version Control",
"license": "GPL-3.0",

View File

@ -8,6 +8,6 @@
"type": "git"
},
"dependencies": {
"myvc": "^1.4.7"
"myvc": "^1.4.8"
}
}