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 %>; DROP EVENT IF EXISTS <%- schema %>.<%- name %>;
DELIMITER $$ DELIMITER $$
CREATE DEFINER=<%- definer %> EVENT <%- schema %>.<%- name %> 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 %> ON COMPLETION <%- onCompletion %>
<% if (status == 'ENABLED') { %>ENABLE<% } else { %>DISABLE<% } %> <% if (status == 'ENABLED') { %>ENABLE<% } else { %>DISABLE<% } %>
DO <%- body %>$$ DO <%- body %>$$

View File

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

View File

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

16
lib.js
View File

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

View File

@ -9,7 +9,8 @@ class Pull {
description: 'Incorporate database routine changes into workspace', description: 'Incorporate database routine changes into workspace',
params: { params: {
force: 'Do it even if there are local changes', 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' operand: 'remote'
}; };
@ -17,10 +18,16 @@ class Pull {
get localOpts() { get localOpts() {
return { return {
boolean: { alias: {
force: 'f', force: 'f',
checkout: 'c' checkout: 'c',
} update: 'u'
},
boolean: [
'force',
'checkout',
'update'
]
}; };
} }
@ -112,7 +119,7 @@ class Pull {
const type = exporter.objectType; const type = exporter.objectType;
const oldSums = sums[type] || {}; const oldSums = sums[type] || {};
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() { get localOpts() {
return { return {
boolean: { alias: {
force: 'f' force: 'f'
} },
boolean: [
'force'
]
}; };
} }
@ -261,30 +264,28 @@ class Push {
const typeMsg = `[${change.type.abbr}]`[change.type.color]; const typeMsg = `[${change.type.abbr}]`[change.type.color];
console.log('', actionMsg.bold, typeMsg.bold, change.fullName); console.log('', actionMsg.bold, typeMsg.bold, change.fullName);
if (!isEqual)
try { try {
const scapedSchema = pushConn.escapeId(schema, true); const scapedSchema = pushConn.escapeId(schema, true);
if (exists) { if (exists) {
if (!isEqual) { if (change.type.name === 'VIEW')
if (change.type.name === 'VIEW') await pushConn.query(`USE ${scapedSchema}`);
await pushConn.query(`USE ${scapedSchema}`);
await this.multiQuery(pushConn, newSql); await this.multiQuery(pushConn, newSql);
nRoutines++;
if (change.isRoutine) { if (change.isRoutine) {
await conn.query( await conn.query(
`INSERT IGNORE INTO mysql.procs_priv `INSERT IGNORE INTO mysql.procs_priv
SELECT * FROM tProcsPriv SELECT * FROM tProcsPriv
WHERE Db = ? WHERE Db = ?
AND Routine_name = ? AND Routine_name = ?
AND Routine_type = ?`, AND Routine_type = ?`,
[schema, name, change.type.name] [schema, name, change.type.name]
); );
}
await engine.fetchShaSum(type, schema, name);
} }
await engine.fetchShaSum(type, schema, name);
} else { } else {
const escapedName = const escapedName =
scapedSchema + '.' + scapedSchema + '.' +
@ -294,8 +295,9 @@ class Push {
await pushConn.query(query); await pushConn.query(query);
engine.deleteShaSum(type, schema, name); engine.deleteShaSum(type, schema, name);
nRoutines++;
} }
nRoutines++;
} catch (err) { } catch (err) {
if (err.sqlState) if (err.sqlState)
console.warn('Warning:'.yellow, err.message); console.warn('Warning:'.yellow, err.message);

View File

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

View File

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

View File

@ -32,14 +32,15 @@ class MyVC {
const baseOpts = { const baseOpts = {
alias: { alias: {
remote: 'r', remote: 'r',
workspace: 'w' workspace: 'w',
},
boolean: {
socket: 's', socket: 's',
debug: 'd', debug: 'd',
version: 'v', version: 'v',
help: 'h' help: 'h'
}, },
boolean: [
'd', 'v', 'h'
],
default: { default: {
workspace: process.cwd() workspace: process.cwd()
} }
@ -378,8 +379,6 @@ class MyVC {
if (opts) { if (opts) {
console.log('Options:'.gray); console.log('Options:'.gray);
this.printOpts(opts, usage, 'alias'); 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", "name": "myvc",
"version": "1.2.5", "version": "1.2.6",
"author": "Verdnatura Levante SL", "author": "Verdnatura Levante SL",
"description": "MySQL Version Control", "description": "MySQL Version Control",
"license": "GPL-3.0", "license": "GPL-3.0",