Event template fix, opts fix, pull update option
This commit is contained in:
parent
0c21859a52
commit
685e02055c
|
@ -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 %>$$
|
||||
|
|
|
@ -1,5 +1,10 @@
|
|||
|
||||
module.exports = {
|
||||
schemaCol: 'EVENT_SCHEMA',
|
||||
nameCol: 'EVENT_NAME'
|
||||
nameCol: 'EVENT_NAME',
|
||||
escapeCols: [
|
||||
'starts',
|
||||
'ends',
|
||||
'executeAt'
|
||||
]
|
||||
};
|
||||
|
|
|
@ -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
16
lib.js
|
@ -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);
|
||||
|
|
17
myvc-pull.js
17
myvc-pull.js
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
14
myvc-push.js
14
myvc-push.js
|
@ -20,9 +20,12 @@ class Push {
|
|||
|
||||
get localOpts() {
|
||||
return {
|
||||
boolean: {
|
||||
alias: {
|
||||
force: 'f'
|
||||
}
|
||||
},
|
||||
boolean: [
|
||||
'force'
|
||||
]
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -261,16 +264,15 @@ 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}`);
|
||||
|
||||
await this.multiQuery(pushConn, newSql);
|
||||
nRoutines++;
|
||||
|
||||
if (change.isRoutine) {
|
||||
await conn.query(
|
||||
|
@ -284,7 +286,6 @@ class Push {
|
|||
}
|
||||
|
||||
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);
|
||||
|
|
|
@ -25,10 +25,14 @@ class Run {
|
|||
|
||||
get localOpts() {
|
||||
return {
|
||||
boolean: {
|
||||
alias: {
|
||||
ci: 'c',
|
||||
random: 'r'
|
||||
}
|
||||
},
|
||||
boolean: [
|
||||
'ci',
|
||||
'random'
|
||||
]
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -18,9 +18,12 @@ class Version {
|
|||
|
||||
get localOpts() {
|
||||
return {
|
||||
string: {
|
||||
alias: {
|
||||
name: 'n'
|
||||
},
|
||||
string: [
|
||||
'name'
|
||||
],
|
||||
default: {
|
||||
remote: 'production'
|
||||
}
|
||||
|
|
9
myvc.js
9
myvc.js
|
@ -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()
|
||||
}
|
||||
|
@ -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');
|
||||
}
|
||||
}
|
||||
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -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",
|
||||
|
|
Loading…
Reference in New Issue