@verdnatura/myt 1.5.9 → 1.5.12

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.
@@ -1,6 +1,6 @@
1
1
  versionSchema: myt
2
2
  versionDigits: 5
3
- maxOldVersions: 30
3
+ maxOldVersions: 20
4
4
  sumViews: true
5
5
  schemas:
6
6
  - myt
@@ -1,21 +1,18 @@
1
- DROP EVENT IF EXISTS <%- schema %>.<%- name %>;
2
- DELIMITER $$
3
- CREATE DEFINER=<%- definer %> EVENT <%- schema %>.<%- name %><%
4
- if (locals.type == 'RECURRING') { %>
5
- ON SCHEDULE EVERY <%- intervalValue %> <%- intervalField %><%
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 (locals.ends) { %>
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 (locals.comment) { %>
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 %>
@@ -1,20 +1,17 @@
1
- DROP FUNCTION IF EXISTS <%- schema %>.<%- name %>;
2
- DELIMITER $$
3
- CREATE DEFINER=<%- definer %> FUNCTION <%- schema %>.<%- name %>(<%- locals.paramList %>)
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 (locals.dataAccess) { %>
11
- <%- dataAccess %><%
8
+ if (params.dataAccess) { %>
9
+ <%- params.dataAccess %><%
12
10
  }
13
- if (locals.securityType == 'INVOKER') { %>
14
- SQL SECURITY <%- securityType %><%
11
+ if (params.securityType == 'INVOKER') { %>
12
+ SQL SECURITY <%- params.securityType %><%
15
13
  }
16
- if (locals.comment) { %>
17
- COMMENT <%- comment %><%
14
+ if (params.comment) { %>
15
+ COMMENT <%- params.comment %><%
18
16
  } %>
19
- <%- body %>$$
20
- DELIMITER ;
17
+ <%- params.body %><%- end %>
@@ -1,14 +1,11 @@
1
- DROP PROCEDURE IF EXISTS <%- schema %>.<%- name %>;
2
- DELIMITER $$
3
- CREATE DEFINER=<%- definer %> PROCEDURE <%- schema %>.<%- name %>(<%- locals.paramList %>)<%
4
- if (locals.dataAccess) { %>
5
- <%- dataAccess %><%
1
+ <%- begin %> <%- typeAndName %>(<%- params.paramList %>)<%
2
+ if (params.dataAccess) { %>
3
+ <%- params.dataAccess %><%
6
4
  }
7
- if (locals.securityType == 'INVOKER') { %>
8
- SQL SECURITY <%- securityType %><%
5
+ if (params.securityType == 'INVOKER') { %>
6
+ SQL SECURITY <%- params.securityType %><%
9
7
  }
10
- if (locals.comment) { %>
11
- COMMENT <%- comment %><%
8
+ if (params.comment) { %>
9
+ COMMENT <%- params.comment %><%
12
10
  } %>
13
- <%- body %>$$
14
- DELIMITER ;
11
+ <%- params.body %><%- end %>
@@ -1,7 +1,4 @@
1
- DROP TRIGGER IF EXISTS <%- schema %>.<%- name %>;
2
- DELIMITER $$
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 %>
@@ -1,7 +1,7 @@
1
- CREATE OR REPLACE DEFINER=<%- definer %>
2
- SQL SECURITY <%- securityType %>
3
- VIEW <%- schema %>.<%- name %>
4
- AS <%- definition %><%
5
- if (locals.checkOption != 'NONE') { %>
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
  } %>
@@ -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, mytDir) {
6
+ constructor(conn, opts) {
7
7
  this.conn = conn;
8
- this.pullFile = `${mytDir}/.pullinfo.json`;
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.objectType = objectType;
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
- params.schema = SqlString.escapeId(params.schema, true);
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
- return this.template(params);
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.remove(`${opts.versionsDir}/${oldVersion}`,
40
- {recursive: true});
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
@@ -53,7 +53,7 @@ class Create extends Command {
53
53
  break;
54
54
  }
55
55
 
56
- const exporter = new Exporter(opts.type);
56
+ const exporter = new Exporter(opts.type, opts.replace);
57
57
  await exporter.init();
58
58
  const sql = exporter.format(params);
59
59
 
package/myt-pull.js CHANGED
@@ -85,7 +85,7 @@ class Pull extends Command {
85
85
 
86
86
  console.log(`Incorporating routine changes.`);
87
87
 
88
- const engine = new ExporterEngine(conn, opts.mytDir);
88
+ const engine = new ExporterEngine(conn, opts);
89
89
  await engine.init();
90
90
  const shaSums = engine.shaSums;
91
91
 
package/myt-push.js CHANGED
@@ -146,12 +146,16 @@ class Push extends Command {
146
146
  return /\.undo\.sql$/.test(script);
147
147
  }
148
148
 
149
+ const skipFiles = new Set([
150
+ 'README.md',
151
+ '.archive'
152
+ ]);
153
+
149
154
  if (await fs.pathExists(versionsDir)) {
150
155
  const versionDirs = await fs.readdir(versionsDir);
151
156
 
152
157
  for (const versionDir of versionDirs) {
153
- if (versionDir == 'README.md')
154
- continue;
158
+ if (skipFiles.has(versionDir)) continue;
155
159
 
156
160
  const dirVersion = myt.parseVersionDir(versionDir);
157
161
  if (!dirVersion) {
@@ -288,7 +292,7 @@ class Push extends Command {
288
292
  );
289
293
  }
290
294
 
291
- const engine = new ExporterEngine(conn, opts.mytDir);
295
+ const engine = new ExporterEngine(conn, opts);
292
296
  await engine.init();
293
297
 
294
298
  async function finalize() {
package/myt-run.js CHANGED
@@ -42,25 +42,30 @@ class Run extends Command {
42
42
 
43
43
  // Build base image
44
44
 
45
- let serverDockerfile = path.join(dumpDir, 'Dockerfile');
46
- if (!await fs.pathExists(serverDockerfile))
47
- serverDockerfile = path.join(serverDir, 'Dockerfile.base');
45
+ let basePath = dumpDir;
46
+ let baseDockerfile = path.join(dumpDir, 'Dockerfile');
48
47
 
49
- await docker.build(__dirname, {
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: serverDockerfile
55
+ file: baseDockerfile
52
56
  }, opts.debug);
53
57
 
54
58
  // Build server image
55
59
 
56
- await docker.build(__dirname, {
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
- await docker.build(opts.mytDir, {
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.9",
3
+ "version": "1.5.12",
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.6",
17
+ "ejs": "^3.1.8",
18
18
  "fs-extra": "^8.1.0",
19
19
  "getopts": "^2.3.0",
20
20
  "ini": "^1.3.8",
@@ -3,9 +3,9 @@ FROM myt/server
3
3
  USER root
4
4
 
5
5
  COPY \
6
- dump/.dump.sql \
7
- dump/beforeDump.sql \
8
- dump/afterDump.sql \
6
+ .dump.sql \
7
+ beforeDump.sql \
8
+ afterDump.sql \
9
9
  dump/
10
10
 
11
11
  RUN gosu mysql docker-init.sh
@@ -8,11 +8,11 @@ RUN mkdir /mysql-data \
8
8
 
9
9
  WORKDIR /workspace
10
10
 
11
- COPY server/docker.cnf /etc/mysql/conf.d/
11
+ COPY docker.cnf /etc/mysql/conf.d/
12
12
  COPY \
13
- server/docker-init.sh \
14
- server/docker-import.sh \
15
- server/docker-start.sh \
13
+ docker-init.sh \
14
+ docker-import.sh \
15
+ docker-start.sh \
16
16
  /usr/local/bin/
17
17
 
18
18
  USER mysql