@verdnatura/myt 1.5.19 → 1.5.21
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/.dockerignore +2 -2
- package/LICENSE +17 -17
- package/README.md +284 -278
- package/assets/db.ini +5 -5
- package/assets/myt.default.yml +28 -11
- package/assets/structure.sql +24 -24
- package/cli.js +4 -4
- package/exporters/event.ejs +18 -18
- package/exporters/event.js +31 -31
- package/exporters/event.sql +19 -19
- package/exporters/function.ejs +17 -17
- package/exporters/function.js +27 -27
- package/exporters/function.sql +16 -16
- package/exporters/procedure.ejs +11 -11
- package/exporters/procedure.js +23 -23
- package/exporters/procedure.sql +14 -14
- package/exporters/trigger.ejs +4 -4
- package/exporters/trigger.js +10 -10
- package/exporters/trigger.sql +13 -13
- package/exporters/view.ejs +7 -7
- package/exporters/view.js +29 -29
- package/exporters/view.sql +12 -12
- package/helpers/local-fixtures.js +79 -0
- package/lib/command.js +19 -13
- package/lib/conn.js +141 -141
- package/lib/docker.js +133 -133
- package/lib/dumper.js +104 -83
- package/lib/exporter-engine.js +112 -112
- package/lib/exporter.js +86 -86
- package/lib/repo.js +29 -29
- package/lib/server.js +71 -71
- package/lib/util.js +7 -7
- package/myt-clean.js +58 -58
- package/myt-create.js +74 -74
- package/myt-dump.js +134 -75
- package/myt-fixtures.js +28 -29
- package/myt-init.js +36 -36
- package/myt-pull.js +183 -183
- package/myt-push.js +575 -568
- package/myt-run.js +190 -177
- package/myt-start.js +54 -54
- package/myt-version.js +218 -218
- package/myt.js +378 -361
- package/package.json +41 -41
- package/server/Dockerfile.base +1 -1
- package/server/Dockerfile.client +14 -14
- package/server/Dockerfile.dump +13 -16
- package/server/Dockerfile.server +25 -25
- package/server/docker-dump.sh +4 -4
- package/server/docker-fixtures.sh +5 -4
- package/server/docker-import.sh +10 -6
- package/server/docker-init.sh +23 -20
- package/server/docker-start.sh +10 -10
- package/server/docker.cnf +9 -9
- package/template/dump/Dockerfile.base +1 -1
- package/template/dump/dump.after.sql +1 -0
- package/template/dump/dump.before.sql +1 -0
- package/template/dump/fixtures.after.sql +1 -0
- package/template/dump/fixtures.before.sql +1 -0
- package/template/myt.config.yml +11 -11
- package/template/package.json +13 -13
- package/template/remotes/docker.ini +4 -4
- package/template/remotes/local.ini +5 -5
- package/template/routines/README.md +1 -1
- package/template/versions/00001-firstVersion/00-firstScript.sql +1 -1
- package/template/versions/README.md +1 -1
- package/template/dump/afterDump.sql +0 -1
- package/template/dump/beforeDump.sql +0 -1
- package/template/dump/fixtures.sql +0 -1
package/myt-run.js
CHANGED
|
@@ -1,177 +1,190 @@
|
|
|
1
|
-
const Myt = require('./myt');
|
|
2
|
-
const Command = require('./lib/command');
|
|
3
|
-
const Push = require('./myt-push');
|
|
4
|
-
const docker = require('./lib/docker');
|
|
5
|
-
const fs = require('fs-extra');
|
|
6
|
-
const path = require('path');
|
|
7
|
-
const Server = require('./lib/server');
|
|
8
|
-
const connExt = require('./lib/conn');
|
|
9
|
-
const SqlString = require('sqlstring');
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* Builds the database image and runs a container. It only rebuilds the
|
|
13
|
-
* image when fixtures have been modified or when the day on which the
|
|
14
|
-
* image was built is different to today. Some workarounds have been used
|
|
15
|
-
* to avoid a bug with OverlayFS driver on MacOS.
|
|
16
|
-
*/
|
|
17
|
-
class Run extends Command {
|
|
18
|
-
static usage = {
|
|
19
|
-
description: 'Build and start local database server container',
|
|
20
|
-
params: {
|
|
21
|
-
ci: 'Workaround for continuous integration system',
|
|
22
|
-
random: 'Whether to use a random container name or port'
|
|
23
|
-
}
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
static opts = {
|
|
27
|
-
alias: {
|
|
28
|
-
ci: 'c',
|
|
29
|
-
random: 'r'
|
|
30
|
-
},
|
|
31
|
-
boolean: [
|
|
32
|
-
'ci',
|
|
33
|
-
'random'
|
|
34
|
-
]
|
|
35
|
-
};
|
|
36
|
-
|
|
37
|
-
async run(myt, opts) {
|
|
38
|
-
const dumpDir = opts.dumpDir;
|
|
39
|
-
const
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
let
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
const
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
const
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
1
|
+
const Myt = require('./myt');
|
|
2
|
+
const Command = require('./lib/command');
|
|
3
|
+
const Push = require('./myt-push');
|
|
4
|
+
const docker = require('./lib/docker');
|
|
5
|
+
const fs = require('fs-extra');
|
|
6
|
+
const path = require('path');
|
|
7
|
+
const Server = require('./lib/server');
|
|
8
|
+
const connExt = require('./lib/conn');
|
|
9
|
+
const SqlString = require('sqlstring');
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Builds the database image and runs a container. It only rebuilds the
|
|
13
|
+
* image when fixtures have been modified or when the day on which the
|
|
14
|
+
* image was built is different to today. Some workarounds have been used
|
|
15
|
+
* to avoid a bug with OverlayFS driver on MacOS.
|
|
16
|
+
*/
|
|
17
|
+
class Run extends Command {
|
|
18
|
+
static usage = {
|
|
19
|
+
description: 'Build and start local database server container',
|
|
20
|
+
params: {
|
|
21
|
+
ci: 'Workaround for continuous integration system',
|
|
22
|
+
random: 'Whether to use a random container name or port'
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
static opts = {
|
|
27
|
+
alias: {
|
|
28
|
+
ci: 'c',
|
|
29
|
+
random: 'r'
|
|
30
|
+
},
|
|
31
|
+
boolean: [
|
|
32
|
+
'ci',
|
|
33
|
+
'random'
|
|
34
|
+
]
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
async run(myt, opts) {
|
|
38
|
+
const dumpDir = opts.dumpDir;
|
|
39
|
+
const dumpDataDir = path.join(dumpDir, '.dump');
|
|
40
|
+
const serverDir = path.join(__dirname, 'server');
|
|
41
|
+
|
|
42
|
+
if (!await fs.pathExists(`${dumpDataDir}/structure.sql`))
|
|
43
|
+
throw new Error('To run local database you have to create a dump first');
|
|
44
|
+
|
|
45
|
+
// Build base image
|
|
46
|
+
|
|
47
|
+
let basePath = dumpDir;
|
|
48
|
+
let baseDockerfile = path.join(dumpDir, 'Dockerfile');
|
|
49
|
+
|
|
50
|
+
if (!await fs.pathExists(baseDockerfile)) {
|
|
51
|
+
basePath = serverDir;
|
|
52
|
+
baseDockerfile = path.join(serverDir, 'Dockerfile.base');
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
await docker.build(basePath, {
|
|
56
|
+
tag: 'myt/base',
|
|
57
|
+
file: baseDockerfile
|
|
58
|
+
}, opts.debug);
|
|
59
|
+
|
|
60
|
+
// Build server image
|
|
61
|
+
|
|
62
|
+
await docker.build(serverDir, {
|
|
63
|
+
tag: 'myt/server',
|
|
64
|
+
file: path.join(serverDir, 'Dockerfile.server')
|
|
65
|
+
}, opts.debug);
|
|
66
|
+
|
|
67
|
+
// Build dump image
|
|
68
|
+
|
|
69
|
+
const dumpContext = path.join(opts.mytDir, 'dump');
|
|
70
|
+
await docker.build(dumpContext, {
|
|
71
|
+
tag: opts.code,
|
|
72
|
+
file: path.join(serverDir, 'Dockerfile.dump')
|
|
73
|
+
}, opts.debug);
|
|
74
|
+
|
|
75
|
+
// Run container
|
|
76
|
+
|
|
77
|
+
const isRandom = opts.random;
|
|
78
|
+
const dbConfig = Object.assign({}, opts.dbConfig);
|
|
79
|
+
|
|
80
|
+
let runOptions;
|
|
81
|
+
|
|
82
|
+
if (isRandom)
|
|
83
|
+
runOptions = {publish: '3306'};
|
|
84
|
+
else {
|
|
85
|
+
runOptions = {
|
|
86
|
+
name: opts.code,
|
|
87
|
+
publish: `3306:${dbConfig.port}`
|
|
88
|
+
};
|
|
89
|
+
try {
|
|
90
|
+
const server = new Server(new docker.Container(opts.code));
|
|
91
|
+
await server.rm();
|
|
92
|
+
} catch (e) {}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
const runChown = process.platform != 'linux';
|
|
96
|
+
|
|
97
|
+
Object.assign(runOptions, null, {
|
|
98
|
+
env: `RUN_CHOWN=${runChown}`,
|
|
99
|
+
detach: true,
|
|
100
|
+
volume: `${this.opts.mytDir}:/workspace`
|
|
101
|
+
});
|
|
102
|
+
const ct = await docker.run(opts.code, null, runOptions);
|
|
103
|
+
const server = new Server(ct, dbConfig);
|
|
104
|
+
|
|
105
|
+
if (isRandom) {
|
|
106
|
+
try {
|
|
107
|
+
const netSettings = await ct.inspect({
|
|
108
|
+
format: '{{json .NetworkSettings}}'
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
if (opts.ci)
|
|
112
|
+
dbConfig.host = netSettings.Gateway;
|
|
113
|
+
|
|
114
|
+
dbConfig.port = netSettings.Ports['3306/tcp'][0].HostPort;
|
|
115
|
+
} catch (err) {
|
|
116
|
+
await server.rm();
|
|
117
|
+
throw err;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
await server.wait();
|
|
122
|
+
const conn = await myt.createConnection();
|
|
123
|
+
|
|
124
|
+
// Mock date functions
|
|
125
|
+
|
|
126
|
+
console.log('Mocking date functions.');
|
|
127
|
+
const mockDateScript = path.join(dumpDir, 'mockDate.sql');
|
|
128
|
+
|
|
129
|
+
if (opts.mockDate) {
|
|
130
|
+
if (!await fs.pathExists(mockDateScript))
|
|
131
|
+
throw new Error(`Date mock enabled but mock script does not exist: ${mockDateScript}`);
|
|
132
|
+
|
|
133
|
+
let sql = await fs.readFile(mockDateScript, 'utf8');
|
|
134
|
+
sql = sql.replace(/@mockDate/g, SqlString.escape(opts.mockDate));
|
|
135
|
+
await connExt.multiQuery(conn, sql);
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
// Apply changes
|
|
139
|
+
|
|
140
|
+
const hasTriggers = await fs.exists(`${dumpDataDir}/triggers.sql`);
|
|
141
|
+
|
|
142
|
+
Object.assign(opts, {
|
|
143
|
+
triggers: hasTriggers,
|
|
144
|
+
commit: true,
|
|
145
|
+
dbConfig
|
|
146
|
+
});
|
|
147
|
+
await myt.runCommand(Push, opts);
|
|
148
|
+
|
|
149
|
+
// Apply fixtures
|
|
150
|
+
|
|
151
|
+
console.log('Applying fixtures.');
|
|
152
|
+
const fixturesFiles = [
|
|
153
|
+
'fixtures.before',
|
|
154
|
+
'.fixtures',
|
|
155
|
+
'fixtures.after',
|
|
156
|
+
'fixtures.local'
|
|
157
|
+
]
|
|
158
|
+
for (const file of fixturesFiles) {
|
|
159
|
+
if (!await fs.exists(`${dumpDir}/${file}.sql`)) continue;
|
|
160
|
+
await ct.exec(null, 'docker-import.sh',
|
|
161
|
+
[`/workspace/dump/${file}`],
|
|
162
|
+
'spawn',
|
|
163
|
+
true
|
|
164
|
+
);
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
// Create triggers
|
|
168
|
+
|
|
169
|
+
if (!hasTriggers) {
|
|
170
|
+
console.log('Creating triggers.');
|
|
171
|
+
|
|
172
|
+
for (const schema of opts.schemas) {
|
|
173
|
+
const triggersPath = `${opts.routinesDir}/${schema}/triggers`;
|
|
174
|
+
if (!await fs.pathExists(triggersPath))
|
|
175
|
+
continue;
|
|
176
|
+
|
|
177
|
+
const triggersDir = await fs.readdir(triggersPath);
|
|
178
|
+
for (const triggerFile of triggersDir)
|
|
179
|
+
await connExt.queryFromFile(conn, `${triggersPath}/${triggerFile}`);
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
return server;
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
module.exports = Run;
|
|
188
|
+
|
|
189
|
+
if (require.main === module)
|
|
190
|
+
new Myt().run(Run);
|
package/myt-start.js
CHANGED
|
@@ -1,54 +1,54 @@
|
|
|
1
|
-
const Myt = require('./myt');
|
|
2
|
-
const Command = require('./lib/command');
|
|
3
|
-
const Container = require('./lib/docker').Container;
|
|
4
|
-
const Server = require('./lib/server');
|
|
5
|
-
const Run = require('./myt-run');
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Does the minium effort to start the database container, if it doesn't
|
|
9
|
-
* exists calls the run command, if it is started does nothing. Keep in
|
|
10
|
-
* mind that when you do not rebuild the docker you may be using an outdated
|
|
11
|
-
* version of it.
|
|
12
|
-
*/
|
|
13
|
-
class Start extends Command {
|
|
14
|
-
static usage = {
|
|
15
|
-
description: 'Start local database server container'
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
async run(myt, opts) {
|
|
19
|
-
const ct = new Container(opts.code);
|
|
20
|
-
let status;
|
|
21
|
-
let exists;
|
|
22
|
-
let server;
|
|
23
|
-
|
|
24
|
-
try {
|
|
25
|
-
status = await ct.inspect({
|
|
26
|
-
format: '{{json .State.Status}}'
|
|
27
|
-
});
|
|
28
|
-
exists = true;
|
|
29
|
-
} catch (err) {
|
|
30
|
-
server = await myt.runCommand(Run, opts);
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
if (exists) {
|
|
34
|
-
switch (status) {
|
|
35
|
-
case 'running':
|
|
36
|
-
break;
|
|
37
|
-
case 'exited':
|
|
38
|
-
await ct.start();
|
|
39
|
-
server = new Server(ct, opts.dbConfig);
|
|
40
|
-
await server.wait();
|
|
41
|
-
break;
|
|
42
|
-
default:
|
|
43
|
-
throw new Error(`Unknown docker status: ${status}`);
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
return server;
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
module.exports = Start;
|
|
52
|
-
|
|
53
|
-
if (require.main === module)
|
|
54
|
-
new Myt().run(Start);
|
|
1
|
+
const Myt = require('./myt');
|
|
2
|
+
const Command = require('./lib/command');
|
|
3
|
+
const Container = require('./lib/docker').Container;
|
|
4
|
+
const Server = require('./lib/server');
|
|
5
|
+
const Run = require('./myt-run');
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Does the minium effort to start the database container, if it doesn't
|
|
9
|
+
* exists calls the run command, if it is started does nothing. Keep in
|
|
10
|
+
* mind that when you do not rebuild the docker you may be using an outdated
|
|
11
|
+
* version of it.
|
|
12
|
+
*/
|
|
13
|
+
class Start extends Command {
|
|
14
|
+
static usage = {
|
|
15
|
+
description: 'Start local database server container'
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
async run(myt, opts) {
|
|
19
|
+
const ct = new Container(opts.code);
|
|
20
|
+
let status;
|
|
21
|
+
let exists;
|
|
22
|
+
let server;
|
|
23
|
+
|
|
24
|
+
try {
|
|
25
|
+
status = await ct.inspect({
|
|
26
|
+
format: '{{json .State.Status}}'
|
|
27
|
+
});
|
|
28
|
+
exists = true;
|
|
29
|
+
} catch (err) {
|
|
30
|
+
server = await myt.runCommand(Run, opts);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
if (exists) {
|
|
34
|
+
switch (status) {
|
|
35
|
+
case 'running':
|
|
36
|
+
break;
|
|
37
|
+
case 'exited':
|
|
38
|
+
await ct.start();
|
|
39
|
+
server = new Server(ct, opts.dbConfig);
|
|
40
|
+
await server.wait();
|
|
41
|
+
break;
|
|
42
|
+
default:
|
|
43
|
+
throw new Error(`Unknown docker status: ${status}`);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
return server;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
module.exports = Start;
|
|
52
|
+
|
|
53
|
+
if (require.main === module)
|
|
54
|
+
new Myt().run(Start);
|