@verdnatura/myt 1.5.9 → 1.5.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/assets/myt.default.yml +1 -1
- package/exporters/event.ejs +13 -16
- package/exporters/function.ejs +10 -13
- package/exporters/procedure.ejs +8 -11
- package/exporters/trigger.ejs +3 -6
- package/exporters/view.ejs +6 -6
- package/lib/exporter-engine.js +4 -3
- package/lib/exporter.js +32 -7
- package/myt-clean.js +9 -2
- package/myt-create.js +1 -1
- package/myt-pull.js +1 -1
- package/myt-push.js +1 -1
- package/myt-run.js +12 -7
- package/package.json +2 -2
- package/server/Dockerfile.dump +3 -3
- package/server/Dockerfile.server +4 -4
package/assets/myt.default.yml
CHANGED
package/exporters/event.ejs
CHANGED
|
@@ -1,21 +1,18 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
if (
|
|
5
|
-
|
|
6
|
-
if (locals.starts) { %>
|
|
7
|
-
STARTS <%- starts %><%
|
|
1
|
+
<%- begin %> <%- typeAndName %><%
|
|
2
|
+
if (params.type == 'RECURRING') { %>
|
|
3
|
+
ON SCHEDULE EVERY <%- params.intervalValue %> <%- params.intervalField %><%
|
|
4
|
+
if (params.starts) { %>
|
|
5
|
+
STARTS <%- params.starts %><%
|
|
8
6
|
}
|
|
9
|
-
if (
|
|
10
|
-
ENDS <%- ends %><%
|
|
7
|
+
if (params.ends) { %>
|
|
8
|
+
ENDS <%- params.ends %><%
|
|
11
9
|
}
|
|
12
10
|
} else { %>
|
|
13
|
-
ON SCHEDULE AT <%- executeAt %><%
|
|
11
|
+
ON SCHEDULE AT <%- params.executeAt %><%
|
|
14
12
|
} %>
|
|
15
|
-
ON COMPLETION <%- onCompletion %>
|
|
16
|
-
<%- status %><%
|
|
17
|
-
if (
|
|
18
|
-
COMMENT <%- comment %><%
|
|
13
|
+
ON COMPLETION <%- params.onCompletion %>
|
|
14
|
+
<%- params.status %><%
|
|
15
|
+
if (params.comment) { %>
|
|
16
|
+
COMMENT <%- params.comment %><%
|
|
19
17
|
} %>
|
|
20
|
-
DO <%- body
|
|
21
|
-
DELIMITER ;
|
|
18
|
+
DO <%- params.body %><%- end %>
|
package/exporters/function.ejs
CHANGED
|
@@ -1,20 +1,17 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
RETURNS <%- returns %><%
|
|
5
|
-
if (locals.isDeterministic == 'NO') { %>
|
|
1
|
+
<%- begin %> <%- typeAndName %>(<%- params.paramList %>)
|
|
2
|
+
RETURNS <%- params.returns %><%
|
|
3
|
+
if (params.isDeterministic == 'NO') { %>
|
|
6
4
|
NOT DETERMINISTIC<%
|
|
7
5
|
} else { %>
|
|
8
6
|
DETERMINISTIC<%
|
|
9
7
|
}
|
|
10
|
-
if (
|
|
11
|
-
<%- dataAccess %><%
|
|
8
|
+
if (params.dataAccess) { %>
|
|
9
|
+
<%- params.dataAccess %><%
|
|
12
10
|
}
|
|
13
|
-
if (
|
|
14
|
-
SQL SECURITY <%- securityType %><%
|
|
11
|
+
if (params.securityType == 'INVOKER') { %>
|
|
12
|
+
SQL SECURITY <%- params.securityType %><%
|
|
15
13
|
}
|
|
16
|
-
if (
|
|
17
|
-
COMMENT <%- comment %><%
|
|
14
|
+
if (params.comment) { %>
|
|
15
|
+
COMMENT <%- params.comment %><%
|
|
18
16
|
} %>
|
|
19
|
-
<%- body
|
|
20
|
-
DELIMITER ;
|
|
17
|
+
<%- params.body %><%- end %>
|
package/exporters/procedure.ejs
CHANGED
|
@@ -1,14 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
if (locals.dataAccess) { %>
|
|
5
|
-
<%- dataAccess %><%
|
|
1
|
+
<%- begin %> <%- typeAndName %>(<%- params.paramList %>)<%
|
|
2
|
+
if (params.dataAccess) { %>
|
|
3
|
+
<%- params.dataAccess %><%
|
|
6
4
|
}
|
|
7
|
-
if (
|
|
8
|
-
SQL SECURITY <%- securityType %><%
|
|
5
|
+
if (params.securityType == 'INVOKER') { %>
|
|
6
|
+
SQL SECURITY <%- params.securityType %><%
|
|
9
7
|
}
|
|
10
|
-
if (
|
|
11
|
-
COMMENT <%- comment %><%
|
|
8
|
+
if (params.comment) { %>
|
|
9
|
+
COMMENT <%- params.comment %><%
|
|
12
10
|
} %>
|
|
13
|
-
<%- body
|
|
14
|
-
DELIMITER ;
|
|
11
|
+
<%- params.body %><%- end %>
|
package/exporters/trigger.ejs
CHANGED
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
CREATE DEFINER=<%- definer %> TRIGGER <%- schema %>.<%- name %>
|
|
4
|
-
<%- actionTiming %> <%- actionType %> ON `<%- table %>`
|
|
1
|
+
<%- begin %> <%- typeAndName %>
|
|
2
|
+
<%- params.actionTiming %> <%- params.actionType %> ON `<%- params.table %>`
|
|
5
3
|
FOR EACH ROW
|
|
6
|
-
<%- body
|
|
7
|
-
DELIMITER ;
|
|
4
|
+
<%- params.body %><%- end %>
|
package/exporters/view.ejs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
SQL SECURITY <%- securityType %>
|
|
3
|
-
|
|
4
|
-
AS <%- definition %><%
|
|
5
|
-
if (
|
|
6
|
-
WITH <%- checkOption %> CHECK OPTION<%
|
|
1
|
+
<%- createOrReplace %>
|
|
2
|
+
SQL SECURITY <%- params.securityType %>
|
|
3
|
+
<%- typeAndName %>
|
|
4
|
+
AS <%- params.definition %><%
|
|
5
|
+
if (params.checkOption != 'NONE') { %>
|
|
6
|
+
WITH <%- params.checkOption %> CHECK OPTION<%
|
|
7
7
|
} %>
|
package/lib/exporter-engine.js
CHANGED
|
@@ -3,9 +3,10 @@ const fs = require('fs-extra');
|
|
|
3
3
|
const Exporter = require('./exporter');
|
|
4
4
|
|
|
5
5
|
module.exports = class ExporterEngine {
|
|
6
|
-
constructor(conn,
|
|
6
|
+
constructor(conn, opts) {
|
|
7
7
|
this.conn = conn;
|
|
8
|
-
this.
|
|
8
|
+
this.opts = opts;
|
|
9
|
+
this.pullFile = `${opts.mytDir}/.pullinfo.json`;
|
|
9
10
|
this.exporters = [];
|
|
10
11
|
this.exporterMap = {};
|
|
11
12
|
}
|
|
@@ -35,7 +36,7 @@ module.exports = class ExporterEngine {
|
|
|
35
36
|
];
|
|
36
37
|
|
|
37
38
|
for (const type of types) {
|
|
38
|
-
const exporter = new Exporter(type);
|
|
39
|
+
const exporter = new Exporter(type, this.opts.replace);
|
|
39
40
|
await exporter.init();
|
|
40
41
|
|
|
41
42
|
this.exporters.push(exporter);
|
package/lib/exporter.js
CHANGED
|
@@ -3,8 +3,11 @@ const fs = require('fs-extra');
|
|
|
3
3
|
const SqlString = require('sqlstring');
|
|
4
4
|
|
|
5
5
|
module.exports = class Exporter {
|
|
6
|
-
constructor(objectType) {
|
|
7
|
-
this
|
|
6
|
+
constructor(objectType, replace) {
|
|
7
|
+
Object.assign(this, {
|
|
8
|
+
objectType,
|
|
9
|
+
replace
|
|
10
|
+
});
|
|
8
11
|
}
|
|
9
12
|
|
|
10
13
|
async init() {
|
|
@@ -38,7 +41,8 @@ module.exports = class Exporter {
|
|
|
38
41
|
|
|
39
42
|
format(params) {
|
|
40
43
|
const {attrs} = this;
|
|
41
|
-
params = Object.assign({}, attrs.defaults, params)
|
|
44
|
+
params = Object.assign({}, attrs.defaults, params)
|
|
45
|
+
const data = {params};
|
|
42
46
|
|
|
43
47
|
if (attrs.formatter)
|
|
44
48
|
attrs.formatter(params);
|
|
@@ -50,12 +54,33 @@ module.exports = class Exporter {
|
|
|
50
54
|
}
|
|
51
55
|
|
|
52
56
|
const split = params.definer.split('@');
|
|
53
|
-
|
|
54
|
-
params.name = SqlString.escapeId(params.name, true);
|
|
55
|
-
params.definer =
|
|
57
|
+
data.definer =
|
|
56
58
|
SqlString.escapeId(split[0], true) + '@' +
|
|
57
59
|
SqlString.escapeId(split[1], true);
|
|
58
60
|
|
|
59
|
-
|
|
61
|
+
data.name =
|
|
62
|
+
SqlString.escapeId(params.schema, true) + '.' +
|
|
63
|
+
SqlString.escapeId(params.name, true);
|
|
64
|
+
|
|
65
|
+
const objectType = this.objectType.toUpperCase();
|
|
66
|
+
const delimiter = '$$';
|
|
67
|
+
const replace = `CREATE OR REPLACE`;
|
|
68
|
+
|
|
69
|
+
let create;
|
|
70
|
+
if (this.replace) {
|
|
71
|
+
create = `DELIMITER ${delimiter}\n${replace}`
|
|
72
|
+
} else {
|
|
73
|
+
create =
|
|
74
|
+
`DROP ${objectType} IF EXISTS ${data.name};\n`
|
|
75
|
+
+`DELIMITER ${delimiter}\n`
|
|
76
|
+
+`CREATE`;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
data.createOrReplace = `${replace} DEFINER=${data.definer}`
|
|
80
|
+
data.begin = `${create} DEFINER=${data.definer}`;
|
|
81
|
+
data.typeAndName = `${objectType} ${data.name}`;
|
|
82
|
+
data.end = `${delimiter}\nDELIMITER ;`;
|
|
83
|
+
|
|
84
|
+
return this.template(data);
|
|
60
85
|
}
|
|
61
86
|
}
|
package/myt-clean.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
const Myt = require('./myt');
|
|
2
2
|
const Command = require('./lib/command');
|
|
3
3
|
const fs = require('fs-extra');
|
|
4
|
+
const path = require('path');
|
|
4
5
|
|
|
5
6
|
/**
|
|
6
7
|
* Cleans old applied versions.
|
|
@@ -35,9 +36,15 @@ class Clean extends Command {
|
|
|
35
36
|
&& oldVersions.length > opts.maxOldVersions) {
|
|
36
37
|
oldVersions.splice(-opts.maxOldVersions);
|
|
37
38
|
|
|
39
|
+
const archiveDir = path.join(opts.versionsDir, '.archive');
|
|
40
|
+
if (!await fs.pathExists(archiveDir))
|
|
41
|
+
await fs.mkdir(archiveDir);
|
|
42
|
+
|
|
38
43
|
for (const oldVersion of oldVersions)
|
|
39
|
-
await fs.
|
|
40
|
-
|
|
44
|
+
await fs.move(
|
|
45
|
+
path.join(opts.versionsDir, oldVersion),
|
|
46
|
+
path.join(archiveDir, oldVersion)
|
|
47
|
+
);
|
|
41
48
|
|
|
42
49
|
console.log(`Old versions deleted: ${oldVersions.length}`);
|
|
43
50
|
} else
|
package/myt-create.js
CHANGED
package/myt-pull.js
CHANGED
package/myt-push.js
CHANGED
package/myt-run.js
CHANGED
|
@@ -42,25 +42,30 @@ class Run extends Command {
|
|
|
42
42
|
|
|
43
43
|
// Build base image
|
|
44
44
|
|
|
45
|
-
let
|
|
46
|
-
|
|
47
|
-
serverDockerfile = path.join(serverDir, 'Dockerfile.base');
|
|
45
|
+
let basePath = dumpDir;
|
|
46
|
+
let baseDockerfile = path.join(dumpDir, 'Dockerfile');
|
|
48
47
|
|
|
49
|
-
await
|
|
48
|
+
if (!await fs.pathExists(baseDockerfile)) {
|
|
49
|
+
basePath = serverDir;
|
|
50
|
+
baseDockerfile = path.join(serverDir, 'Dockerfile.base');
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
await docker.build(basePath, {
|
|
50
54
|
tag: 'myt/base',
|
|
51
|
-
file:
|
|
55
|
+
file: baseDockerfile
|
|
52
56
|
}, opts.debug);
|
|
53
57
|
|
|
54
58
|
// Build server image
|
|
55
59
|
|
|
56
|
-
await docker.build(
|
|
60
|
+
await docker.build(serverDir, {
|
|
57
61
|
tag: 'myt/server',
|
|
58
62
|
file: path.join(serverDir, 'Dockerfile.server')
|
|
59
63
|
}, opts.debug);
|
|
60
64
|
|
|
61
65
|
// Build dump image
|
|
62
66
|
|
|
63
|
-
|
|
67
|
+
const dumpContext = path.join(opts.mytDir, 'dump');
|
|
68
|
+
await docker.build(dumpContext, {
|
|
64
69
|
tag: opts.code,
|
|
65
70
|
file: path.join(serverDir, 'Dockerfile.dump')
|
|
66
71
|
}, opts.debug);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@verdnatura/myt",
|
|
3
|
-
"version": "1.5.
|
|
3
|
+
"version": "1.5.11",
|
|
4
4
|
"author": "Verdnatura Levante SL",
|
|
5
5
|
"description": "MySQL version control",
|
|
6
6
|
"license": "GPL-3.0",
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
"dependencies": {
|
|
15
15
|
"@sqltools/formatter": "^1.2.5",
|
|
16
16
|
"colors": "^1.4.0",
|
|
17
|
-
"ejs": "^3.1.
|
|
17
|
+
"ejs": "^3.1.8",
|
|
18
18
|
"fs-extra": "^8.1.0",
|
|
19
19
|
"getopts": "^2.3.0",
|
|
20
20
|
"ini": "^1.3.8",
|
package/server/Dockerfile.dump
CHANGED
package/server/Dockerfile.server
CHANGED
|
@@ -8,11 +8,11 @@ RUN mkdir /mysql-data \
|
|
|
8
8
|
|
|
9
9
|
WORKDIR /workspace
|
|
10
10
|
|
|
11
|
-
COPY
|
|
11
|
+
COPY docker.cnf /etc/mysql/conf.d/
|
|
12
12
|
COPY \
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
13
|
+
docker-init.sh \
|
|
14
|
+
docker-import.sh \
|
|
15
|
+
docker-start.sh \
|
|
16
16
|
/usr/local/bin/
|
|
17
17
|
|
|
18
18
|
USER mysql
|