@verdnatura/myt 1.6.3 → 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/myt-run.js +80 -72
- package/package.json +1 -1
package/myt-run.js
CHANGED
|
@@ -118,92 +118,100 @@ class Run extends Command {
|
|
|
118
118
|
detach: true
|
|
119
119
|
});
|
|
120
120
|
const ct = await docker.run(opts.code, null, runOptions);
|
|
121
|
-
const server = new Server(ct, dbConfig);
|
|
122
121
|
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
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
|
+
}
|
|
139
142
|
}
|
|
140
|
-
}
|
|
141
143
|
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
144
|
+
this.emit('waitingDb');
|
|
145
|
+
await server.wait();
|
|
146
|
+
const conn = await myt.createConnection();
|
|
145
147
|
|
|
146
|
-
|
|
148
|
+
// Mock date functions
|
|
147
149
|
|
|
148
|
-
|
|
149
|
-
|
|
150
|
+
this.emit('mockingDate');
|
|
151
|
+
const mockDateScript = path.join(dumpDir, 'mockDate.sql');
|
|
150
152
|
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
let sql = await fs.readFile(mockDateScript, 'utf8');
|
|
156
|
-
sql = sql.replace(/@mockDate/g, SqlString.escape(opts.mockDate));
|
|
157
|
-
await connExt.multiQuery(conn, sql);
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
// Apply changes
|
|
161
|
-
|
|
162
|
-
const hasTriggers = await fs.exists(`${dumpDataDir}/triggers.sql`);
|
|
163
|
-
|
|
164
|
-
Object.assign(opts, {
|
|
165
|
-
triggers: !hasTriggers,
|
|
166
|
-
commit: true,
|
|
167
|
-
dbConfig
|
|
168
|
-
});
|
|
169
|
-
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}`);
|
|
170
156
|
|
|
171
|
-
|
|
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
|
+
}
|
|
172
161
|
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
await
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
);
|
|
187
|
-
|
|
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
|
+
}
|
|
188
190
|
|
|
189
|
-
|
|
191
|
+
// Create triggers
|
|
190
192
|
|
|
191
|
-
|
|
192
|
-
|
|
193
|
+
if (!hasTriggers) {
|
|
194
|
+
this.emit('creatingTriggers');
|
|
193
195
|
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
196
|
+
for (const schema of opts.schemas) {
|
|
197
|
+
const triggersPath = `${opts.routinesDir}/${schema}/triggers`;
|
|
198
|
+
if (!await fs.pathExists(triggersPath))
|
|
199
|
+
continue;
|
|
198
200
|
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
201
|
+
const triggersDir = await fs.readdir(triggersPath);
|
|
202
|
+
for (const triggerFile of triggersDir)
|
|
203
|
+
await connExt.queryFromFile(conn, `${triggersPath}/${triggerFile}`);
|
|
204
|
+
}
|
|
202
205
|
}
|
|
203
|
-
}
|
|
204
206
|
|
|
205
|
-
|
|
206
|
-
|
|
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
|
+
}
|
|
207
215
|
}
|
|
208
216
|
}
|
|
209
217
|
|