Event template fix, opts fix, pull update option

This commit is contained in:
Juan Ferrer 2022-02-07 11:46:13 +01:00
parent 0c21859a52
commit 685e02055c
11 changed files with 116 additions and 1890 deletions

View File

@ -1,7 +1,18 @@
DROP EVENT IF EXISTS <%- schema %>.<%- name %>;
DELIMITER $$
CREATE DEFINER=<%- definer %> EVENT <%- schema %>.<%- name %>
ON SCHEDULE EVERY <%- intervalValue %> <%- intervalField %>
ON SCHEDULE <%
if (type == 'RECURRING') {
%>EVERY <%- intervalValue %> <%- intervalField %><%
if (starts) { %>
STARTS <%- starts %><%
} %><%
if (ends) { %>
ENDS <%- ends %><%
} %><%
} else {
%>AT <%- executeAt %><%
} %>
ON COMPLETION <%- onCompletion %>
<% if (status == 'ENABLED') { %>ENABLE<% } else { %>DISABLE<% } %>
DO <%- body %>$$

View File

@ -1,5 +1,10 @@
module.exports = {
schemaCol: 'EVENT_SCHEMA',
nameCol: 'EVENT_NAME'
nameCol: 'EVENT_NAME',
escapeCols: [
'starts',
'ends',
'executeAt'
]
};

View File

@ -5,7 +5,7 @@ SELECT
`DEFINER` AS `definer`,
`EVENT_DEFINITION` AS `body`,
`EVENT_TYPE` AS `type`,
`EXECUTE_AT` AS `execute_at`,
`EXECUTE_AT` AS `executeAt`,
`INTERVAL_VALUE` AS `intervalValue`,
`INTERVAL_FIELD` AS `intervalField`,
`STARTS` AS `starts`,

16
lib.js
View File

@ -24,7 +24,7 @@ class Exporter {
this.attrs = require(`${templateDir}.js`);
}
async export(exportDir, schema, newSums, oldSums) {
async export(exportDir, schema, newSums, oldSums, update) {
const res = await this.query(schema);
if (!res.length) return;
@ -53,7 +53,7 @@ class Exporter {
const shaSum = this.engine.shaSum(sql);
newSums[routineName] = shaSum;
if (oldSums[routineName] !== shaSum)
if (oldSums[routineName] !== shaSum || update)
await fs.writeFile(routineFile, sql);
}
}
@ -81,10 +81,16 @@ class Exporter {
}
format(params) {
const {conn} = this;
const {conn, attrs} = this;
if (this.attrs.formatter)
this.attrs.formatter(params);
if (attrs.formatter)
attrs.formatter(params, conn);
if (attrs.escapeCols)
for (const escapeCol of attrs.escapeCols) {
if (params[escapeCol])
params[escapeCol] = conn.escape(params[escapeCol])
}
const split = params.definer.split('@');
params.schema = conn.escapeId(params.schema, true);

View File

@ -9,7 +9,8 @@ class Pull {
description: 'Incorporate database routine changes into workspace',
params: {
force: 'Do it even if there are local changes',
checkout: 'Move to same database commit before pull'
checkout: 'Move to same database commit before pull',
update: 'Update routine file even is shasum is the same'
},
operand: 'remote'
};
@ -17,10 +18,16 @@ class Pull {
get localOpts() {
return {
boolean: {
alias: {
force: 'f',
checkout: 'c'
}
checkout: 'c',
update: 'u'
},
boolean: [
'force',
'checkout',
'update'
]
};
}
@ -112,7 +119,7 @@ class Pull {
const type = exporter.objectType;
const oldSums = sums[type] || {};
sums[type] = {};
await exporter.export(exportDir, schema, sums[type], oldSums);
await exporter.export(exportDir, schema, sums[type], oldSums, opts.update);
}
}

View File

@ -20,9 +20,12 @@ class Push {
get localOpts() {
return {
boolean: {
alias: {
force: 'f'
}
},
boolean: [
'force'
]
};
}
@ -261,30 +264,28 @@ class Push {
const typeMsg = `[${change.type.abbr}]`[change.type.color];
console.log('', actionMsg.bold, typeMsg.bold, change.fullName);
if (!isEqual)
try {
const scapedSchema = pushConn.escapeId(schema, true);
if (exists) {
if (!isEqual) {
if (change.type.name === 'VIEW')
await pushConn.query(`USE ${scapedSchema}`);
if (change.type.name === 'VIEW')
await pushConn.query(`USE ${scapedSchema}`);
await this.multiQuery(pushConn, newSql);
nRoutines++;
await this.multiQuery(pushConn, newSql);
if (change.isRoutine) {
await conn.query(
`INSERT IGNORE INTO mysql.procs_priv
SELECT * FROM tProcsPriv
WHERE Db = ?
AND Routine_name = ?
AND Routine_type = ?`,
[schema, name, change.type.name]
);
}
await engine.fetchShaSum(type, schema, name);
if (change.isRoutine) {
await conn.query(
`INSERT IGNORE INTO mysql.procs_priv
SELECT * FROM tProcsPriv
WHERE Db = ?
AND Routine_name = ?
AND Routine_type = ?`,
[schema, name, change.type.name]
);
}
await engine.fetchShaSum(type, schema, name);
} else {
const escapedName =
scapedSchema + '.' +
@ -294,8 +295,9 @@ class Push {
await pushConn.query(query);
engine.deleteShaSum(type, schema, name);
nRoutines++;
}
nRoutines++;
} catch (err) {
if (err.sqlState)
console.warn('Warning:'.yellow, err.message);

View File

@ -25,10 +25,14 @@ class Run {
get localOpts() {
return {
boolean: {
alias: {
ci: 'c',
random: 'r'
}
},
boolean: [
'ci',
'random'
]
};
}

View File

@ -18,9 +18,12 @@ class Version {
get localOpts() {
return {
string: {
alias: {
name: 'n'
},
string: [
'name'
],
default: {
remote: 'production'
}

11
myvc.js
View File

@ -32,14 +32,15 @@ class MyVC {
const baseOpts = {
alias: {
remote: 'r',
workspace: 'w'
},
boolean: {
workspace: 'w',
socket: 's',
debug: 'd',
version: 'v',
help: 'h'
},
boolean: [
'd', 'v', 'h'
],
default: {
workspace: process.cwd()
}
@ -70,7 +71,7 @@ class MyVC {
this.showHelp(baseOpts, usage);
process.exit(0);
}
const commandOpts = this.getopts(command.localOpts);
Object.assign(opts, commandOpts);
@ -378,8 +379,6 @@ class MyVC {
if (opts) {
console.log('Options:'.gray);
this.printOpts(opts, usage, 'alias');
this.printOpts(opts, usage, 'boolean');
this.printOpts(opts, usage, 'string');
}
}

1883
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

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