@verdnatura/myt 1.5.13 → 1.5.15
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 -0
- package/myt-push.js +30 -17
- package/myt-run.js +15 -0
- package/myt.js +2 -2
- package/package.json +1 -1
package/assets/myt.default.yml
CHANGED
package/myt-push.js
CHANGED
|
@@ -267,8 +267,7 @@ class Push extends Command {
|
|
|
267
267
|
const gitExists = await fs.pathExists(`${opts.workspace}/.git`);
|
|
268
268
|
|
|
269
269
|
let nRoutines = 0;
|
|
270
|
-
|
|
271
|
-
changes = this.parseChanges(changes);
|
|
270
|
+
const changes = await this.changedRoutines(version.gitCommit);
|
|
272
271
|
|
|
273
272
|
const routines = [];
|
|
274
273
|
for (const change of changes)
|
|
@@ -322,16 +321,26 @@ class Push extends Command {
|
|
|
322
321
|
const oldSum = engine.getShaSum(type, schema, name);
|
|
323
322
|
const isEqual = newSql == oldSql;
|
|
324
323
|
|
|
324
|
+
let statusMsg;
|
|
325
|
+
if (exists && !oldSql)
|
|
326
|
+
statusMsg = '[+]'.green;
|
|
327
|
+
else if (!exists)
|
|
328
|
+
statusMsg = '[-]'.red;
|
|
329
|
+
else
|
|
330
|
+
statusMsg = '[·]'.yellow;
|
|
331
|
+
|
|
325
332
|
let actionMsg;
|
|
326
|
-
if (
|
|
333
|
+
if (isEqual)
|
|
327
334
|
actionMsg = '[I]'.blue;
|
|
328
|
-
else if (exists)
|
|
329
|
-
actionMsg = '[+]'.green;
|
|
330
335
|
else
|
|
331
|
-
actionMsg = '[
|
|
336
|
+
actionMsg = '[A]'.green;
|
|
332
337
|
|
|
333
338
|
const typeMsg = `[${change.type.abbr}]`[change.type.color];
|
|
334
|
-
console.log('',
|
|
339
|
+
console.log('',
|
|
340
|
+
(statusMsg + actionMsg).bold,
|
|
341
|
+
typeMsg.bold,
|
|
342
|
+
change.fullName
|
|
343
|
+
);
|
|
335
344
|
|
|
336
345
|
if (!isEqual) {
|
|
337
346
|
const scapedSchema = SqlString.escapeId(schema, true);
|
|
@@ -397,14 +406,6 @@ class Push extends Command {
|
|
|
397
406
|
await pushConn.end();
|
|
398
407
|
}
|
|
399
408
|
|
|
400
|
-
parseChanges(changes) {
|
|
401
|
-
const routines = [];
|
|
402
|
-
if (changes)
|
|
403
|
-
for (const change of changes)
|
|
404
|
-
routines.push(new Routine(change));
|
|
405
|
-
return routines;
|
|
406
|
-
}
|
|
407
|
-
|
|
408
409
|
async updateVersion(column, value) {
|
|
409
410
|
column = SqlString.escapeId(column, true);
|
|
410
411
|
await this.conn.query(
|
|
@@ -478,9 +479,21 @@ class Push extends Command {
|
|
|
478
479
|
await pushChanges(await repoExt.getUnstaged(repo));
|
|
479
480
|
await pushChanges(await repoExt.getStaged(repo));
|
|
480
481
|
|
|
481
|
-
|
|
482
|
+
const routines = [];
|
|
483
|
+
for (const change of changes)
|
|
484
|
+
routines.push(new Routine(change));
|
|
485
|
+
|
|
486
|
+
return routines.sort((a, b) => {
|
|
482
487
|
if (b.mark != a.mark)
|
|
483
|
-
return b.mark == '-' ? 1 :
|
|
488
|
+
return b.mark == '-' ? -1 : 1;
|
|
489
|
+
|
|
490
|
+
if (b.type.name !== a.type.name) {
|
|
491
|
+
if (b.type.name == 'VIEW')
|
|
492
|
+
return -1;
|
|
493
|
+
if (a.type.name == 'VIEW')
|
|
494
|
+
return 1;
|
|
495
|
+
}
|
|
496
|
+
|
|
484
497
|
return a.path.localeCompare(b.path);
|
|
485
498
|
});
|
|
486
499
|
}
|
package/myt-run.js
CHANGED
|
@@ -6,6 +6,7 @@ const fs = require('fs-extra');
|
|
|
6
6
|
const path = require('path');
|
|
7
7
|
const Server = require('./lib/server');
|
|
8
8
|
const connExt = require('./lib/conn');
|
|
9
|
+
const SqlString = require('sqlstring');
|
|
9
10
|
|
|
10
11
|
/**
|
|
11
12
|
* Builds the database image and runs a container. It only rebuilds the
|
|
@@ -152,6 +153,20 @@ class Run extends Command {
|
|
|
152
153
|
await connExt.queryFromFile(conn, `${triggersPath}/${triggerFile}`);
|
|
153
154
|
}
|
|
154
155
|
|
|
156
|
+
// Mock date functions
|
|
157
|
+
|
|
158
|
+
console.log('Mocking date functions.');
|
|
159
|
+
const mockDateScript = path.join(dumpDir, 'mockDate.sql');
|
|
160
|
+
|
|
161
|
+
if (opts.mockDate) {
|
|
162
|
+
if (!await fs.pathExists(mockDateScript))
|
|
163
|
+
throw new Error(`Date mock enabled but mock script does not exist: ${mockDateScript}`);
|
|
164
|
+
|
|
165
|
+
let sql = await fs.readFile(mockDateScript, 'utf8');
|
|
166
|
+
sql = sql.replace(/@mockDate/g, SqlString.escape(opts.mockDate));
|
|
167
|
+
await connExt.multiQuery(conn, sql);
|
|
168
|
+
}
|
|
169
|
+
|
|
155
170
|
return server;
|
|
156
171
|
}
|
|
157
172
|
}
|
package/myt.js
CHANGED