masterrecord 0.2.12 → 0.2.14
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/Migrations/cli.js +33 -42
- package/package.json +1 -1
package/Migrations/cli.js
CHANGED
|
@@ -83,9 +83,8 @@ program.option('-V', 'output the version');
|
|
|
83
83
|
contextFileName = contextFileName.toLowerCase();
|
|
84
84
|
var migration = new Migration();
|
|
85
85
|
try{
|
|
86
|
-
var
|
|
87
|
-
var
|
|
88
|
-
var file = files && files[0];
|
|
86
|
+
var files = globSearch.sync(`**/*${contextFileName}_contextSnapShot.json`, { cwd: executedLocation, dot: true, windowsPathsNoEscape: true, nocase: true });
|
|
87
|
+
var file = files && files[0] ? path.resolve(executedLocation, files[0]) : null;
|
|
89
88
|
if(!file){
|
|
90
89
|
console.log(`Error - Cannot read or find Context snapshot '${contextFileName}_contextSnapShot.json' in '${executedLocation}'.`);
|
|
91
90
|
return;
|
|
@@ -98,8 +97,8 @@ program.option('-V', 'output the version');
|
|
|
98
97
|
return;
|
|
99
98
|
}
|
|
100
99
|
// Find latest migration file (so we can use its class which extends schema)
|
|
101
|
-
var
|
|
102
|
-
|
|
100
|
+
var migrationFiles = globSearch.sync(`**/*_migration.js`, { cwd: contextSnapshot.migrationFolder, dot: true, windowsPathsNoEscape: true });
|
|
101
|
+
migrationFiles = (migrationFiles || []).map(f => path.resolve(contextSnapshot.migrationFolder, f));
|
|
103
102
|
if(!(migrationFiles && migrationFiles.length)){
|
|
104
103
|
console.log("Error - Cannot read or find migration file");
|
|
105
104
|
return;
|
|
@@ -178,9 +177,8 @@ program.option('-V', 'output the version');
|
|
|
178
177
|
var migration = new Migration();
|
|
179
178
|
try{
|
|
180
179
|
// find context file from main folder location
|
|
181
|
-
var
|
|
182
|
-
var
|
|
183
|
-
var file = files && files[0];
|
|
180
|
+
var files = globSearch.sync(`**/*${contextFileName}_contextSnapShot.json`, { cwd: executedLocation, dot: true, windowsPathsNoEscape: true, nocase: true });
|
|
181
|
+
var file = files && files[0] ? path.resolve(executedLocation, files[0]) : null;
|
|
184
182
|
if(!file){
|
|
185
183
|
console.log(`Error - Cannot read or find Context snapshot '${contextFileName}_contextSnapShot.json' in '${executedLocation}'. Run 'masterrecord enable-migrations ${contextFileName}'.`);
|
|
186
184
|
return;
|
|
@@ -229,14 +227,13 @@ program.option('-V', 'output the version');
|
|
|
229
227
|
contextFileName = contextFileName.toLowerCase();
|
|
230
228
|
var migration = new Migration();
|
|
231
229
|
try{
|
|
232
|
-
// find context
|
|
233
|
-
var
|
|
234
|
-
var
|
|
235
|
-
var file = files[0];
|
|
230
|
+
// find context snapshot (cwd-based glob)
|
|
231
|
+
var files = globSearch.sync(`**/*${contextFileName}_contextSnapShot.json`, { cwd: executedLocation, dot: true, windowsPathsNoEscape: true, nocase: true });
|
|
232
|
+
var file = files && files[0] ? path.resolve(executedLocation, files[0]) : null;
|
|
236
233
|
if(file){
|
|
237
234
|
var contextSnapshot = require(file);
|
|
238
|
-
var
|
|
239
|
-
|
|
235
|
+
var migrationFiles = globSearch.sync(`**/*_migration.js`, { cwd: contextSnapshot.migrationFolder, dot: true, windowsPathsNoEscape: true });
|
|
236
|
+
migrationFiles = (migrationFiles || []).map(f => path.resolve(contextSnapshot.migrationFolder, f));
|
|
240
237
|
if( migrationFiles && migrationFiles.length){
|
|
241
238
|
// sort by timestamp prefix or file mtime as fallback
|
|
242
239
|
var mFiles = migrationFiles.slice().sort(function(a, b){
|
|
@@ -287,9 +284,8 @@ program.option('-V', 'output the version');
|
|
|
287
284
|
contextFileName = contextFileName.toLowerCase();
|
|
288
285
|
var migration = new Migration();
|
|
289
286
|
try{
|
|
290
|
-
var
|
|
291
|
-
var
|
|
292
|
-
var file = files && files[0];
|
|
287
|
+
var files = globSearch.sync(`**/*${contextFileName}_contextSnapShot.json`, { cwd: executedLocation, dot: true, windowsPathsNoEscape: true, nocase: true });
|
|
288
|
+
var file = files && files[0] ? path.resolve(executedLocation, files[0]) : null;
|
|
293
289
|
if(!file){
|
|
294
290
|
console.log(`Error - Cannot read or find Context snapshot '${contextFileName}_contextSnapShot.json' in '${executedLocation}'.`);
|
|
295
291
|
return;
|
|
@@ -301,8 +297,8 @@ program.option('-V', 'output the version');
|
|
|
301
297
|
console.log(`Error - Cannot read context snapshot at '${file}'.`);
|
|
302
298
|
return;
|
|
303
299
|
}
|
|
304
|
-
var
|
|
305
|
-
|
|
300
|
+
var migrationFiles = globSearch.sync(`**/*_migration.js`, { cwd: contextSnapshot.migrationFolder, dot: true, windowsPathsNoEscape: true });
|
|
301
|
+
migrationFiles = (migrationFiles || []).map(f => path.resolve(contextSnapshot.migrationFolder, f));
|
|
306
302
|
if(!(migrationFiles && migrationFiles.length)){
|
|
307
303
|
console.log("Error - Cannot read or find migration file");
|
|
308
304
|
return;
|
|
@@ -365,10 +361,9 @@ program.option('-V', 'output the version');
|
|
|
365
361
|
contextFileName = contextFileName.toLowerCase();
|
|
366
362
|
var migration = new Migration();
|
|
367
363
|
try{
|
|
368
|
-
// find context
|
|
369
|
-
var
|
|
370
|
-
var
|
|
371
|
-
var file = files[0];
|
|
364
|
+
// find context snapshot (cwd-based glob)
|
|
365
|
+
var files = globSearch.sync(`**/*${contextFileName}_contextSnapShot.json`, { cwd: executedLocation, dot: true, windowsPathsNoEscape: true, nocase: true });
|
|
366
|
+
var file = files && files[0] ? path.resolve(executedLocation, files[0]) : null;
|
|
372
367
|
if(!file){
|
|
373
368
|
console.log(`Error - Cannot read or find Context snapshot '${contextFileName}_contextSnapShot.json' in '${executedLocation}'.`);
|
|
374
369
|
return;
|
|
@@ -380,8 +375,8 @@ program.option('-V', 'output the version');
|
|
|
380
375
|
console.log(`Error - Cannot read context snapshot at '${file}'.`);
|
|
381
376
|
return;
|
|
382
377
|
}
|
|
383
|
-
var
|
|
384
|
-
|
|
378
|
+
var migrationFiles = globSearch.sync(`**/*_migration.js`, { cwd: contextSnapshot.migrationFolder, dot: true, windowsPathsNoEscape: true });
|
|
379
|
+
migrationFiles = (migrationFiles || []).map(f => path.resolve(contextSnapshot.migrationFolder, f));
|
|
385
380
|
if(!(migrationFiles && migrationFiles.length)){
|
|
386
381
|
console.log("Error - Cannot read or find migration file");
|
|
387
382
|
return;
|
|
@@ -437,9 +432,8 @@ program.option('-V', 'output the version');
|
|
|
437
432
|
.action(function(contextFileName){
|
|
438
433
|
var executedLocation = process.cwd();
|
|
439
434
|
contextFileName = contextFileName.toLowerCase();
|
|
440
|
-
var
|
|
441
|
-
var
|
|
442
|
-
var file = files[0];
|
|
435
|
+
var files = globSearch.sync(`**/*${contextFileName}_contextSnapShot.json`, { cwd: executedLocation, dot: true, windowsPathsNoEscape: true, nocase: true });
|
|
436
|
+
var file = files && files[0] ? path.resolve(executedLocation, files[0]) : null;
|
|
443
437
|
if(!file){
|
|
444
438
|
console.log(`Error - Cannot read or find Context snapshot '${contextFileName}_contextSnapShot.json' in '${executedLocation}'.`);
|
|
445
439
|
return;
|
|
@@ -451,13 +445,12 @@ program.option('-V', 'output the version');
|
|
|
451
445
|
console.log(`Error - Cannot read context snapshot at '${file}'.`);
|
|
452
446
|
return;
|
|
453
447
|
}
|
|
454
|
-
var
|
|
455
|
-
var migrationFiles = globSearch.sync(searchMigration, contextSnapshot.migrationFolder);
|
|
448
|
+
var migrationFiles = globSearch.sync(`**/*_migration.js`, { cwd: contextSnapshot.migrationFolder, dot: true, windowsPathsNoEscape: true });
|
|
456
449
|
if(!(migrationFiles && migrationFiles.length)){
|
|
457
450
|
console.log("No migration files found.");
|
|
458
451
|
return;
|
|
459
452
|
}
|
|
460
|
-
var sorted = migrationFiles.slice().sort((a,b) => __getMigrationTimestamp(a) - __getMigrationTimestamp(b));
|
|
453
|
+
var sorted = migrationFiles.slice().sort((a,b) => __getMigrationTimestamp(path.resolve(contextSnapshot.migrationFolder, a)) - __getMigrationTimestamp(path.resolve(contextSnapshot.migrationFolder, b)));
|
|
461
454
|
// Print relative names for readability
|
|
462
455
|
for(const f of sorted){
|
|
463
456
|
console.log(path.basename(f));
|
|
@@ -478,18 +471,17 @@ program.option('-V', 'output the version');
|
|
|
478
471
|
var targetName = path.basename(migrationFileName);
|
|
479
472
|
|
|
480
473
|
// Locate the target migration file anywhere under the current folder
|
|
481
|
-
var
|
|
482
|
-
var targetMatches = globSearch.sync(searchTarget, executedLocation);
|
|
474
|
+
var targetMatches = globSearch.sync(`**/${targetName}`, { cwd: executedLocation, dot: true, windowsPathsNoEscape: true });
|
|
483
475
|
if(!(targetMatches && targetMatches.length)){
|
|
484
476
|
console.log(`Error - Cannot read or find migration file '${targetName}' in '${executedLocation}'.`);
|
|
485
477
|
return;
|
|
486
478
|
}
|
|
487
|
-
var targetFilePath = targetMatches[0];
|
|
479
|
+
var targetFilePath = path.resolve(executedLocation, targetMatches[0]);
|
|
488
480
|
var migrationFolder = path.dirname(targetFilePath);
|
|
489
481
|
|
|
490
482
|
// Find the context snapshot within the same migrations folder
|
|
491
|
-
var snapshotMatches = globSearch.sync(
|
|
492
|
-
var snapshotFile = snapshotMatches && snapshotMatches[0];
|
|
483
|
+
var snapshotMatches = globSearch.sync(`**/*_contextSnapShot.json`, { cwd: migrationFolder, dot: true, windowsPathsNoEscape: true });
|
|
484
|
+
var snapshotFile = snapshotMatches && snapshotMatches[0] ? path.resolve(migrationFolder, snapshotMatches[0]) : null;
|
|
493
485
|
if(!snapshotFile){
|
|
494
486
|
console.log("Error - Cannot read or find Context snapshot in migration folder.");
|
|
495
487
|
return;
|
|
@@ -504,7 +496,7 @@ program.option('-V', 'output the version');
|
|
|
504
496
|
}
|
|
505
497
|
|
|
506
498
|
// Get all migration files in this folder
|
|
507
|
-
var allMigrationFiles = globSearch.sync(
|
|
499
|
+
var allMigrationFiles = globSearch.sync(`**/*_migration.js`, { cwd: migrationFolder, dot: true, windowsPathsNoEscape: true });
|
|
508
500
|
if(!(allMigrationFiles && allMigrationFiles.length)){
|
|
509
501
|
console.log("Error - Cannot read or find migration file");
|
|
510
502
|
return;
|
|
@@ -512,7 +504,7 @@ program.option('-V', 'output the version');
|
|
|
512
504
|
|
|
513
505
|
// Sort chronologically
|
|
514
506
|
var sorted = allMigrationFiles.slice().sort(function(a, b){
|
|
515
|
-
return __getMigrationTimestamp(a) - __getMigrationTimestamp(b);
|
|
507
|
+
return __getMigrationTimestamp(path.resolve(migrationFolder, a)) - __getMigrationTimestamp(path.resolve(migrationFolder, b));
|
|
516
508
|
});
|
|
517
509
|
|
|
518
510
|
// Find target index by basename match
|
|
@@ -542,7 +534,7 @@ program.option('-V', 'output the version');
|
|
|
542
534
|
|
|
543
535
|
// Roll back (down) all migrations newer than the target (i.e., strictly after targetIndex)
|
|
544
536
|
for (var i = sorted.length - 1; i > targetIndex; i--) {
|
|
545
|
-
var migFile = sorted[i];
|
|
537
|
+
var migFile = path.resolve(migrationFolder, sorted[i]);
|
|
546
538
|
var MigCtor = require(migFile);
|
|
547
539
|
var migInstance = new MigCtor(ContextCtor);
|
|
548
540
|
if(typeof migInstance.down === 'function'){
|
|
@@ -577,7 +569,7 @@ program.option('-V', 'output the version');
|
|
|
577
569
|
var executedLocation = process.cwd();
|
|
578
570
|
try{
|
|
579
571
|
// Find all context snapshots and run update per snapshot (avoids unrelated framework contexts)
|
|
580
|
-
var snapshotFiles = globSearch.sync(
|
|
572
|
+
var snapshotFiles = globSearch.sync(path.join(executedLocation, '**', '*_contextSnapShot.json'), executedLocation);
|
|
581
573
|
if(!(snapshotFiles && snapshotFiles.length)){
|
|
582
574
|
console.log('No context snapshots found. Run enable-migrations for each context first.');
|
|
583
575
|
return;
|
|
@@ -591,8 +583,7 @@ program.option('-V', 'output the version');
|
|
|
591
583
|
const ctxName = (cs && cs.contextLocation)
|
|
592
584
|
? path.basename(cs.contextLocation).replace(/\.js$/i, '').toLowerCase()
|
|
593
585
|
: nameFromPath;
|
|
594
|
-
const
|
|
595
|
-
const migs = globSearch.sync(searchMigration, cs.migrationFolder) || [];
|
|
586
|
+
const migs = globSearch.sync(path.join(cs.migrationFolder, '**', '*_migration.js'), cs.migrationFolder) || [];
|
|
596
587
|
if(!groups[ctxName]) groups[ctxName] = [];
|
|
597
588
|
groups[ctxName].push({ snapFile, cs, ctxName, migs });
|
|
598
589
|
}
|
package/package.json
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
"app-root-path": "^3.1.0",
|
|
10
10
|
"better-sqlite3": "^12.4.1"
|
|
11
11
|
},
|
|
12
|
-
"version": "0.2.
|
|
12
|
+
"version": "0.2.14",
|
|
13
13
|
"description": "An Object-relational mapping for the Master framework. Master Record connects classes to relational database tables to establish a database with almost zero-configuration ",
|
|
14
14
|
"homepage": "https://github.com/Tailor/MasterRecord#readme",
|
|
15
15
|
"repository": {
|