masterrecord 0.2.23 → 0.2.25

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.
Files changed (2) hide show
  1. package/Migrations/cli.js +34 -22
  2. package/package.json +1 -1
package/Migrations/cli.js CHANGED
@@ -96,9 +96,12 @@ program.option('-V', 'output the version');
96
96
  console.log(`Error - Cannot read context snapshot at '${file}'.`);
97
97
  return;
98
98
  }
99
+ const snapDir = path.dirname(file);
100
+ const contextAbs = path.resolve(snapDir, contextSnapshot.contextLocation || '');
101
+ const migBase = path.resolve(snapDir, contextSnapshot.migrationFolder || '.');
99
102
  // Find latest migration file (so we can use its class which extends schema)
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
+ var migrationFiles = globSearch.sync(`**/*_migration.js`, { cwd: migBase, dot: true, windowsPathsNoEscape: true });
104
+ migrationFiles = (migrationFiles || []).map(f => path.resolve(migBase, f));
102
105
  if(!(migrationFiles && migrationFiles.length)){
103
106
  console.log("Error - Cannot read or find migration file");
104
107
  return;
@@ -110,9 +113,9 @@ program.option('-V', 'output the version');
110
113
 
111
114
  let ContextCtor;
112
115
  try{
113
- ContextCtor = require(contextSnapshot.contextLocation);
116
+ ContextCtor = require(contextAbs);
114
117
  }catch(_){
115
- console.log(`Error - Cannot load Context file at '${contextSnapshot.contextLocation}'.`);
118
+ console.log(`Error - Cannot load Context file at '${contextAbs}'.`);
116
119
  return;
117
120
  }
118
121
 
@@ -248,8 +251,11 @@ program.option('-V', 'output the version');
248
251
  var file = files && files[0] ? path.resolve(executedLocation, files[0]) : null;
249
252
  if(file){
250
253
  var contextSnapshot = require(file);
251
- var migrationFiles = globSearch.sync(`**/*_migration.js`, { cwd: contextSnapshot.migrationFolder, dot: true, windowsPathsNoEscape: true });
252
- migrationFiles = (migrationFiles || []).map(f => path.resolve(contextSnapshot.migrationFolder, f));
254
+ const snapDir = path.dirname(file);
255
+ const contextAbs = path.resolve(snapDir, contextSnapshot.contextLocation || '');
256
+ const migBase = path.resolve(snapDir, contextSnapshot.migrationFolder || '.');
257
+ var migrationFiles = globSearch.sync(`**/*_migration.js`, { cwd: migBase, dot: true, windowsPathsNoEscape: true });
258
+ migrationFiles = (migrationFiles || []).map(f => path.resolve(migBase, f));
253
259
  if( migrationFiles && migrationFiles.length){
254
260
  // sort by timestamp prefix or file mtime as fallback
255
261
  var mFiles = migrationFiles.slice().sort(function(a, b){
@@ -257,17 +263,17 @@ program.option('-V', 'output the version');
257
263
  });
258
264
  var mFile = mFiles[mFiles.length -1];
259
265
 
260
- var migrationProjectFile = require(mFile);
261
- var context = require(contextSnapshot.contextLocation);
262
- var contextInstance = new context();
263
- var newMigrationProjectInstance = new migrationProjectFile(context);
266
+ var migrationProjectFile = require(mFile);
267
+ var ContextCtor = require(contextAbs);
268
+ var contextInstance = new ContextCtor();
269
+ var newMigrationProjectInstance = new migrationProjectFile(ContextCtor);
264
270
 
265
271
  var cleanEntities = migration.cleanEntities(contextInstance.__entities);
266
272
  var tableObj = migration.buildUpObject(contextSnapshot.schema, cleanEntities);
267
273
  newMigrationProjectInstance.up(tableObj);
268
274
 
269
275
  var snap = {
270
- file : contextSnapshot.contextLocation,
276
+ file : contextAbs,
271
277
  executedLocation : executedLocation,
272
278
  context : contextInstance,
273
279
  contextEntities : cleanEntities,
@@ -313,8 +319,11 @@ program.option('-V', 'output the version');
313
319
  console.log(`Error - Cannot read context snapshot at '${file}'.`);
314
320
  return;
315
321
  }
316
- var migrationFiles = globSearch.sync(`**/*_migration.js`, { cwd: contextSnapshot.migrationFolder, dot: true, windowsPathsNoEscape: true });
317
- migrationFiles = (migrationFiles || []).map(f => path.resolve(contextSnapshot.migrationFolder, f));
322
+ const snapDir = path.dirname(file);
323
+ const contextAbs = path.resolve(snapDir, contextSnapshot.contextLocation || '');
324
+ const migBase = path.resolve(snapDir, contextSnapshot.migrationFolder || '.');
325
+ var migrationFiles = globSearch.sync(`**/*_migration.js`, { cwd: migBase, dot: true, windowsPathsNoEscape: true });
326
+ migrationFiles = (migrationFiles || []).map(f => path.resolve(migBase, f));
318
327
  if(!(migrationFiles && migrationFiles.length)){
319
328
  console.log("Error - Cannot read or find migration file");
320
329
  return;
@@ -328,9 +337,9 @@ program.option('-V', 'output the version');
328
337
  // Prepare context and table object
329
338
  let ContextCtor;
330
339
  try{
331
- ContextCtor = require(contextSnapshot.contextLocation);
340
+ ContextCtor = require(contextAbs);
332
341
  }catch(_){
333
- console.log(`Error - Cannot load Context file at '${contextSnapshot.contextLocation}'.`);
342
+ console.log(`Error - Cannot load Context file at '${contextAbs}'.`);
334
343
  return;
335
344
  }
336
345
  var contextInstance;
@@ -353,7 +362,7 @@ program.option('-V', 'output the version');
353
362
 
354
363
  // Update snapshot
355
364
  var snap = {
356
- file : contextSnapshot.contextLocation,
365
+ file : contextAbs,
357
366
  executedLocation : executedLocation,
358
367
  context : contextInstance,
359
368
  contextEntities : cleanEntities,
@@ -384,15 +393,18 @@ program.option('-V', 'output the version');
384
393
  console.log(`Error - Cannot read or find Context snapshot '${contextFileName}_contextSnapShot.json' in '${executedLocation}'.`);
385
394
  return;
386
395
  }
387
- var contextSnapshot;
396
+ var contextSnapshot;
388
397
  try{
389
398
  contextSnapshot = require(file);
390
399
  }catch(_){
391
400
  console.log(`Error - Cannot read context snapshot at '${file}'.`);
392
401
  return;
393
402
  }
394
- var migrationFiles = globSearch.sync(`**/*_migration.js`, { cwd: contextSnapshot.migrationFolder, dot: true, windowsPathsNoEscape: true });
395
- migrationFiles = (migrationFiles || []).map(f => path.resolve(contextSnapshot.migrationFolder, f));
403
+ const snapDir = path.dirname(file);
404
+ const contextAbs = path.resolve(snapDir, contextSnapshot.contextLocation || '');
405
+ const migBase = path.resolve(snapDir, contextSnapshot.migrationFolder || '.');
406
+ var migrationFiles = globSearch.sync(`**/*_migration.js`, { cwd: migBase, dot: true, windowsPathsNoEscape: true });
407
+ migrationFiles = (migrationFiles || []).map(f => path.resolve(migBase, f));
396
408
  if(!(migrationFiles && migrationFiles.length)){
397
409
  console.log("Error - Cannot read or find migration file");
398
410
  return;
@@ -533,9 +545,9 @@ program.option('-V', 'output the version');
533
545
  // Prepare context and table object
534
546
  let ContextCtor;
535
547
  try{
536
- ContextCtor = require(contextSnapshot.contextLocation);
548
+ ContextCtor = require(contextAbs);
537
549
  }catch(_){
538
- console.log(`Error - Cannot load Context file at '${contextSnapshot.contextLocation}'.`);
550
+ console.log(`Error - Cannot load Context file at '${contextAbs}'.`);
539
551
  return;
540
552
  }
541
553
  var contextInstance;
@@ -562,7 +574,7 @@ program.option('-V', 'output the version');
562
574
 
563
575
  // Update snapshot
564
576
  var snap = {
565
- file : contextSnapshot.contextLocation,
577
+ file : contextAbs,
566
578
  executedLocation : executedLocation,
567
579
  context : contextInstance,
568
580
  contextEntities : cleanEntities,
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.23",
12
+ "version": "0.2.25",
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": {