@verdnatura/myt 1.6.2 → 1.6.4
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/README.md +1 -1
- package/myt-run.js +82 -73
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -279,7 +279,7 @@ Builds and starts local database server container. It only rebuilds the image
|
|
|
279
279
|
when dump have been modified.
|
|
280
280
|
|
|
281
281
|
```text
|
|
282
|
-
$ myt run [-c|--ci] [-r|--random] [-n|--network <string>]
|
|
282
|
+
$ myt run [-c|--ci] [-r|--random] [-t|--tmpfs] [-n|--network <string>]
|
|
283
283
|
```
|
|
284
284
|
|
|
285
285
|
### start
|
package/myt-run.js
CHANGED
|
@@ -33,7 +33,8 @@ class Run extends Command {
|
|
|
33
33
|
},
|
|
34
34
|
boolean: [
|
|
35
35
|
'ci',
|
|
36
|
-
'random'
|
|
36
|
+
'random',
|
|
37
|
+
'tmpfs'
|
|
37
38
|
]
|
|
38
39
|
};
|
|
39
40
|
|
|
@@ -117,92 +118,100 @@ class Run extends Command {
|
|
|
117
118
|
detach: true
|
|
118
119
|
});
|
|
119
120
|
const ct = await docker.run(opts.code, null, runOptions);
|
|
120
|
-
const server = new Server(ct, dbConfig);
|
|
121
121
|
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
122
|
+
try {
|
|
123
|
+
const server = new Server(ct, dbConfig);
|
|
124
|
+
|
|
125
|
+
if (isRandom) {
|
|
126
|
+
try {
|
|
127
|
+
const netSettings = await ct.inspect({
|
|
128
|
+
format: '{{json .NetworkSettings}}'
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
if (opts.ci || opts.network) {
|
|
132
|
+
dbConfig.host = opts.network
|
|
133
|
+
? netSettings.Networks[opts.network].IPAddress
|
|
134
|
+
: netSettings.Gateway;
|
|
135
|
+
dbConfig.port = 3306;
|
|
136
|
+
} else
|
|
137
|
+
dbConfig.port = netSettings.Ports['3306/tcp'][0].HostPort;
|
|
138
|
+
} catch (err) {
|
|
139
|
+
await server.rm();
|
|
140
|
+
throw err;
|
|
141
|
+
}
|
|
138
142
|
}
|
|
139
|
-
}
|
|
140
143
|
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
+
this.emit('waitingDb');
|
|
145
|
+
await server.wait();
|
|
146
|
+
const conn = await myt.createConnection();
|
|
144
147
|
|
|
145
|
-
|
|
148
|
+
// Mock date functions
|
|
146
149
|
|
|
147
|
-
|
|
148
|
-
|
|
150
|
+
this.emit('mockingDate');
|
|
151
|
+
const mockDateScript = path.join(dumpDir, 'mockDate.sql');
|
|
149
152
|
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
let sql = await fs.readFile(mockDateScript, 'utf8');
|
|
155
|
-
sql = sql.replace(/@mockDate/g, SqlString.escape(opts.mockDate));
|
|
156
|
-
await connExt.multiQuery(conn, sql);
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
// Apply changes
|
|
160
|
-
|
|
161
|
-
const hasTriggers = await fs.exists(`${dumpDataDir}/triggers.sql`);
|
|
162
|
-
|
|
163
|
-
Object.assign(opts, {
|
|
164
|
-
triggers: !hasTriggers,
|
|
165
|
-
commit: true,
|
|
166
|
-
dbConfig
|
|
167
|
-
});
|
|
168
|
-
await myt.run(Push, opts);
|
|
153
|
+
if (opts.mockDate) {
|
|
154
|
+
if (!await fs.pathExists(mockDateScript))
|
|
155
|
+
throw new Error(`Date mock enabled but mock script does not exist: ${mockDateScript}`);
|
|
169
156
|
|
|
170
|
-
|
|
157
|
+
let sql = await fs.readFile(mockDateScript, 'utf8');
|
|
158
|
+
sql = sql.replace(/@mockDate/g, SqlString.escape(opts.mockDate));
|
|
159
|
+
await connExt.multiQuery(conn, sql);
|
|
160
|
+
}
|
|
171
161
|
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
await
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
);
|
|
186
|
-
|
|
162
|
+
// Apply changes
|
|
163
|
+
|
|
164
|
+
const hasTriggers = await fs.exists(`${dumpDataDir}/triggers.sql`);
|
|
165
|
+
|
|
166
|
+
Object.assign(opts, {
|
|
167
|
+
triggers: !hasTriggers,
|
|
168
|
+
commit: true,
|
|
169
|
+
dbConfig
|
|
170
|
+
});
|
|
171
|
+
await myt.run(Push, opts);
|
|
172
|
+
|
|
173
|
+
// Apply fixtures
|
|
174
|
+
|
|
175
|
+
this.emit('applyingFixtures');
|
|
176
|
+
const fixturesFiles = [
|
|
177
|
+
'fixtures.before',
|
|
178
|
+
'.fixtures',
|
|
179
|
+
'fixtures.after',
|
|
180
|
+
'fixtures.local'
|
|
181
|
+
]
|
|
182
|
+
for (const file of fixturesFiles) {
|
|
183
|
+
if (!await fs.exists(`${dumpDir}/${file}.sql`)) continue;
|
|
184
|
+
await ct.exec(null, 'docker-import.sh',
|
|
185
|
+
[`/workspace/dump/${file}`],
|
|
186
|
+
'spawn',
|
|
187
|
+
true
|
|
188
|
+
);
|
|
189
|
+
}
|
|
187
190
|
|
|
188
|
-
|
|
191
|
+
// Create triggers
|
|
189
192
|
|
|
190
|
-
|
|
191
|
-
|
|
193
|
+
if (!hasTriggers) {
|
|
194
|
+
this.emit('creatingTriggers');
|
|
192
195
|
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
196
|
+
for (const schema of opts.schemas) {
|
|
197
|
+
const triggersPath = `${opts.routinesDir}/${schema}/triggers`;
|
|
198
|
+
if (!await fs.pathExists(triggersPath))
|
|
199
|
+
continue;
|
|
197
200
|
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
+
const triggersDir = await fs.readdir(triggersPath);
|
|
202
|
+
for (const triggerFile of triggersDir)
|
|
203
|
+
await connExt.queryFromFile(conn, `${triggersPath}/${triggerFile}`);
|
|
204
|
+
}
|
|
201
205
|
}
|
|
202
|
-
}
|
|
203
206
|
|
|
204
|
-
|
|
205
|
-
|
|
207
|
+
await conn.end();
|
|
208
|
+
return server;
|
|
209
|
+
} catch (err) {
|
|
210
|
+
try {
|
|
211
|
+
await ct.rm({force: true});
|
|
212
|
+
} catch (e) {}
|
|
213
|
+
throw err;
|
|
214
|
+
}
|
|
206
215
|
}
|
|
207
216
|
}
|
|
208
217
|
|