masterrecord 0.2.29 → 0.2.30

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 CHANGED
@@ -59,7 +59,9 @@ program.option('-V', 'output the version');
59
59
  // find context file from main folder location
60
60
  var contextInstance = migration.findContext(executedLocation, contextFileName);
61
61
  if(!contextInstance){
62
- console.log(`Error - Cannot read or find Context file '${contextFileName}.js' in '${executedLocation}'.`);
62
+ console.error(`\n❌ Error - Cannot read or find Context file '${contextFileName}.js'`);
63
+ console.error(`\nSearched in: ${executedLocation}`);
64
+ console.error(`\nMake sure your Context file exists and is named correctly.`);
63
65
  return;
64
66
  }
65
67
  var snap = {
@@ -70,7 +72,7 @@ program.option('-V', 'output the version');
70
72
  }
71
73
 
72
74
  migration.createSnapShot(snap);
73
- console.log("Migration enabled")
75
+ console.log("Migration enabled successfully")
74
76
 
75
77
  });
76
78
 
@@ -114,8 +116,14 @@ program.option('-V', 'output the version');
114
116
  let ContextCtor;
115
117
  try{
116
118
  ContextCtor = require(contextAbs);
117
- }catch(_){
118
- console.log(`Error - Cannot load Context file at '${contextAbs}'.`);
119
+ }catch(err){
120
+ console.error(`\n❌ Error - Cannot load Context file at '${contextAbs}'`);
121
+ console.error(`\nDetails:`);
122
+ console.error(err.message);
123
+ if(err.stack){
124
+ console.error(`\nStack trace:`);
125
+ console.error(err.stack);
126
+ }
119
127
  return;
120
128
  }
121
129
 
@@ -123,13 +131,23 @@ program.option('-V', 'output the version');
123
131
  var MigrationCtor = require(mFile);
124
132
  var mig = new MigrationCtor(ContextCtor);
125
133
  if(typeof mig.createdatabase === 'function'){
126
- try{ mig.createdatabase(); }catch(_){ /* best-effort */ }
127
- console.log('database ensured');
134
+ try{
135
+ mig.createdatabase();
136
+ console.log('✓ Database ensured');
137
+ }catch(err){
138
+ console.error(`\n❌ Error creating database:`);
139
+ console.error(err.message);
140
+ }
128
141
  } else if(typeof mig.createDatabase === 'function'){
129
- try{ mig.createDatabase(); }catch(_){ }
130
- console.log('database ensured');
142
+ try{
143
+ mig.createDatabase();
144
+ console.log('✓ Database ensured');
145
+ }catch(err){
146
+ console.error(`\n❌ Error creating database:`);
147
+ console.error(err.message);
148
+ }
131
149
  } else {
132
- console.log('Error - Migration class missing createDatabase method');
150
+ console.error('Error - Migration class missing createDatabase method');
133
151
  }
134
152
  }catch(e){
135
153
  console.log('Error - Cannot read or find file ', e);
@@ -202,15 +220,31 @@ program.option('-V', 'output the version');
202
220
  let ContextCtor;
203
221
  try{
204
222
  ContextCtor = require(contextAbs);
205
- }catch(_){
206
- console.log(`Error - Cannot load Context file at '${contextAbs}'.`);
223
+ }catch(err){
224
+ console.error(`\n❌ Error - Cannot load Context file at '${contextAbs}'`);
225
+ console.error(`\nDetails:`);
226
+ console.error(err.message);
227
+ if(err.stack){
228
+ console.error(`\nStack trace:`);
229
+ console.error(err.stack);
230
+ }
207
231
  return;
208
232
  }
209
233
  let contextInstance;
210
234
  try{
211
235
  contextInstance = new ContextCtor();
212
- }catch(_){
213
- console.log(`Error - Failed to construct Context from '${contextAbs}'.`);
236
+ }catch(err){
237
+ console.error(`\n❌ Error - Failed to construct Context from '${contextAbs}'`);
238
+ console.error(`\nThis usually happens when:`);
239
+ console.error(` • Environment configuration is missing or invalid`);
240
+ console.error(` • Database connection settings are incorrect`);
241
+ console.error(` • Required dependencies are not installed`);
242
+ console.error(`\nDetails:`);
243
+ console.error(err.message);
244
+ if(err.stack){
245
+ console.error(`\nStack trace:`);
246
+ console.error(err.stack);
247
+ }
214
248
  return;
215
249
  }
216
250
  var cleanEntities = migration.cleanEntities(contextInstance.__entities);
@@ -231,7 +265,7 @@ program.option('-V', 'output the version');
231
265
  fs.writeFile(outputFile, newEntity, 'utf8', function (err) {
232
266
  if (err) return console.log("--- Error running cammand, re-run command add-migration ---- ", err);
233
267
  });
234
- console.log(`${name} migration file created`);
268
+ console.log(`✓ Migration '${name}' created successfully at ${outputFile}`);
235
269
  }catch (e){
236
270
  console.log("Error - Cannot read or find file ", e);
237
271
  }
@@ -281,7 +315,7 @@ program.option('-V', 'output the version');
281
315
  }
282
316
 
283
317
  migration.createSnapShot(snap);
284
- console.log("database updated");
318
+ console.log(" Database updated successfully");
285
319
  }
286
320
  else{
287
321
  console.log("Error - Cannot read or find migration file");
@@ -338,15 +372,31 @@ program.option('-V', 'output the version');
338
372
  let ContextCtor;
339
373
  try{
340
374
  ContextCtor = require(contextAbs);
341
- }catch(_){
342
- console.log(`Error - Cannot load Context file at '${contextAbs}'.`);
375
+ }catch(err){
376
+ console.error(`\n❌ Error - Cannot load Context file at '${contextAbs}'`);
377
+ console.error(`\nDetails:`);
378
+ console.error(err.message);
379
+ if(err.stack){
380
+ console.error(`\nStack trace:`);
381
+ console.error(err.stack);
382
+ }
343
383
  return;
344
384
  }
345
385
  var contextInstance;
346
386
  try{
347
387
  contextInstance = new ContextCtor();
348
- }catch(_){
349
- console.log(`Error - Failed to construct Context from '${contextSnapshot.contextLocation}'.`);
388
+ }catch(err){
389
+ console.error(`\n❌ Error - Failed to construct Context from '${contextAbs}'`);
390
+ console.error(`\nThis usually happens when:`);
391
+ console.error(` • Environment configuration is missing or invalid`);
392
+ console.error(` • Database connection settings are incorrect`);
393
+ console.error(` • Required dependencies are not installed`);
394
+ console.error(`\nDetails:`);
395
+ console.error(err.message);
396
+ if(err.stack){
397
+ console.error(`\nStack trace:`);
398
+ console.error(err.stack);
399
+ }
350
400
  return;
351
401
  }
352
402
  var cleanEntities = migration.cleanEntities(contextInstance.__entities);
@@ -369,7 +419,7 @@ program.option('-V', 'output the version');
369
419
  contextFileName: contextFileName
370
420
  }
371
421
  migration.createSnapShot(snap);
372
- console.log("database updated");
422
+ console.log(" Database rolled back successfully");
373
423
 
374
424
  }catch (e){
375
425
  console.log("Error - Cannot read or find file ", e);
@@ -415,16 +465,32 @@ program.option('-V', 'output the version');
415
465
  });
416
466
  let ContextCtor;
417
467
  try{
418
- ContextCtor = require(contextSnapshot.contextLocation);
419
- }catch(_){
420
- console.log(`Error - Cannot load Context file at '${contextSnapshot.contextLocation}'.`);
468
+ ContextCtor = require(contextAbs);
469
+ }catch(err){
470
+ console.error(`\n❌ Error - Cannot load Context file at '${contextAbs}'`);
471
+ console.error(`\nDetails:`);
472
+ console.error(err.message);
473
+ if(err.stack){
474
+ console.error(`\nStack trace:`);
475
+ console.error(err.stack);
476
+ }
421
477
  return;
422
478
  }
423
479
  var contextInstance;
424
480
  try{
425
481
  contextInstance = new ContextCtor();
426
- }catch(_){
427
- console.log(`Error - Failed to construct Context from '${contextSnapshot.contextLocation}'.`);
482
+ }catch(err){
483
+ console.error(`\n❌ Error - Failed to construct Context from '${contextAbs}'`);
484
+ console.error(`\nThis usually happens when:`);
485
+ console.error(` • Environment configuration is missing or invalid`);
486
+ console.error(` • Database connection settings are incorrect`);
487
+ console.error(` • Required dependencies are not installed`);
488
+ console.error(`\nDetails:`);
489
+ console.error(err.message);
490
+ if(err.stack){
491
+ console.error(`\nStack trace:`);
492
+ console.error(err.stack);
493
+ }
428
494
  return;
429
495
  }
430
496
  var cleanEntities = migration.cleanEntities(contextInstance.__entities);
@@ -444,7 +510,7 @@ program.option('-V', 'output the version');
444
510
  }
445
511
 
446
512
  migration.createSnapShot(snap);
447
- console.log("database updated");
513
+ console.log(" Database restarted and updated successfully");
448
514
 
449
515
  }
450
516
  catch (e){
@@ -546,15 +612,31 @@ program.option('-V', 'output the version');
546
612
  let ContextCtor;
547
613
  try{
548
614
  ContextCtor = require(contextAbs);
549
- }catch(_){
550
- console.log(`Error - Cannot load Context file at '${contextAbs}'.`);
615
+ }catch(err){
616
+ console.error(`\n❌ Error - Cannot load Context file at '${contextAbs}'`);
617
+ console.error(`\nDetails:`);
618
+ console.error(err.message);
619
+ if(err.stack){
620
+ console.error(`\nStack trace:`);
621
+ console.error(err.stack);
622
+ }
551
623
  return;
552
624
  }
553
625
  var contextInstance;
554
626
  try{
555
627
  contextInstance = new ContextCtor();
556
- }catch(_){
557
- console.log(`Error - Failed to construct Context from '${contextSnapshot.contextLocation}'.`);
628
+ }catch(err){
629
+ console.error(`\n❌ Error - Failed to construct Context from '${contextAbs}'`);
630
+ console.error(`\nThis usually happens when:`);
631
+ console.error(` • Environment configuration is missing or invalid`);
632
+ console.error(` • Database connection settings are incorrect`);
633
+ console.error(` • Required dependencies are not installed`);
634
+ console.error(`\nDetails:`);
635
+ console.error(err.message);
636
+ if(err.stack){
637
+ console.error(`\nStack trace:`);
638
+ console.error(err.stack);
639
+ }
558
640
  return;
559
641
  }
560
642
  var cleanEntities = migration.cleanEntities(contextInstance.__entities);
@@ -581,7 +663,7 @@ program.option('-V', 'output the version');
581
663
  contextFileName: path.basename(snapshotFile).replace('_contextSnapShot.json','')
582
664
  }
583
665
  migration.createSnapShot(snap);
584
- console.log("database updated");
666
+ console.log(" Database rolled back to target migration successfully");
585
667
 
586
668
  }catch (e){
587
669
  console.log("Error - Cannot read or find file ", e);
@@ -612,13 +694,19 @@ program.option('-V', 'output the version');
612
694
  const migBase = path.resolve(snapDir, cs.migrationFolder || '.');
613
695
  // Load context
614
696
  let ContextCtor;
615
- try{ ContextCtor = require(contextAbs); }catch(_){
616
- console.log(`Skipping: cannot load Context at '${contextAbs}'.`);
697
+ try{
698
+ ContextCtor = require(contextAbs);
699
+ }catch(err){
700
+ console.error(`⚠️ Skipping ${path.basename(contextAbs)}: cannot load Context file`);
701
+ console.error(` Details: ${err.message}`);
617
702
  continue;
618
703
  }
619
704
  let contextInstance;
620
- try{ contextInstance = new ContextCtor(); }catch(_){
621
- console.log(`Skipping: failed to construct Context from '${contextAbs}'.`);
705
+ try{
706
+ contextInstance = new ContextCtor();
707
+ }catch(err){
708
+ console.error(`⚠️ Skipping ${path.basename(contextAbs)}: failed to construct Context`);
709
+ console.error(` Details: ${err.message}`);
622
710
  continue;
623
711
  }
624
712
  var migration = new Migration();
@@ -704,13 +792,19 @@ program.option('-V', 'output the version');
704
792
  var mFile = mFiles[mFiles.length - 1];
705
793
 
706
794
  var ContextCtor;
707
- try{ ContextCtor = require(entry.contextAbs); }catch(_){
708
- console.log(`Skipping ${entry.ctxName}: cannot load Context at '${entry.contextAbs}'.`);
795
+ try{
796
+ ContextCtor = require(entry.contextAbs);
797
+ }catch(err){
798
+ console.error(`⚠️ Skipping ${entry.ctxName}: cannot load Context file`);
799
+ console.error(` Details: ${err.message}`);
709
800
  continue;
710
801
  }
711
802
  var contextInstance;
712
- try{ contextInstance = new ContextCtor(); }catch(_){
713
- console.log(`Skipping ${entry.ctxName}: failed to construct Context.`);
803
+ try{
804
+ contextInstance = new ContextCtor();
805
+ }catch(err){
806
+ console.error(`⚠️ Skipping ${entry.ctxName}: failed to construct Context`);
807
+ console.error(` Details: ${err.message}`);
714
808
  continue;
715
809
  }
716
810
  var migrationProjectFile = require(mFile);
@@ -726,7 +820,7 @@ program.option('-V', 'output the version');
726
820
  contextFileName: entry.ctxName
727
821
  }
728
822
  migration.createSnapShot(snap);
729
- console.log(`database updated for ${entry.ctxName}`);
823
+ console.log(`✓ Database updated successfully for ${entry.ctxName}`);
730
824
  }catch(errCtx){
731
825
  console.log('Error updating context: ', errCtx);
732
826
  }
@@ -774,7 +868,7 @@ program.option('-V', 'output the version');
774
868
  contextFileName: key
775
869
  };
776
870
  migration.createSnapShot(snap);
777
- console.log(`migrations enabled for ${ctxName}`);
871
+ console.log(`✓ Migrations enabled for ${ctxName}`);
778
872
  enabled++;
779
873
  }catch(err){
780
874
  console.log('Skipping candidate due to error: ', err);
@@ -1,5 +1,5 @@
1
1
 
2
- // version 0.0.14
2
+ // version 0.0.15
3
3
  var entityTrackerModel = require('masterrecord/Entity/entityTrackerModel');
4
4
  var tools = require('masterrecord/Tools');
5
5
  var queryScript = require('masterrecord/QueryLanguage/queryScript');
@@ -249,13 +249,40 @@ class queryMethods{
249
249
  entityValue.__state = "delete";
250
250
  entityValue.__entity = this.__entity;
251
251
  entityValue.__context = this.__context;
252
+
253
+ // If the entity has an __ID, try to find and update it in tracked entities
254
+ if(entityValue.__ID){
255
+ var tracked = this.__context.__findTracked(entityValue.__ID);
256
+ if(tracked){
257
+ // Update the tracked entity's state
258
+ tracked.__state = "delete";
259
+ return;
260
+ }
261
+ }
262
+
263
+ // If not already tracked, track it now
264
+ this.__context.__track(entityValue);
252
265
  }
253
266
 
254
267
  removeRange(entityValues){
255
268
  for (const property in entityValues) {
256
- entityValues[property].__state = "delete";
257
- entityValues[property].__entity = this.__entity;
258
- entityValues[property].__context = this.__context;
269
+ var entityValue = entityValues[property];
270
+ entityValue.__state = "delete";
271
+ entityValue.__entity = this.__entity;
272
+ entityValue.__context = this.__context;
273
+
274
+ // If the entity has an __ID, try to find and update it in tracked entities
275
+ if(entityValue.__ID){
276
+ var tracked = this.__context.__findTracked(entityValue.__ID);
277
+ if(tracked){
278
+ // Update the tracked entity's state
279
+ tracked.__state = "delete";
280
+ continue;
281
+ }
282
+ }
283
+
284
+ // If not already tracked, track it now
285
+ this.__context.__track(entityValue);
259
286
  }
260
287
  }
261
288
 
package/package.json CHANGED
@@ -1,28 +1,38 @@
1
1
  {
2
2
  "name": "masterrecord",
3
- "dependencies": {
4
- "commander": "^14.0.1",
5
- "glob" : "^11.0.3",
6
- "deep-object-diff" : "^1.1.9",
7
- "pg" : "^8.16.3",
8
- "sync-mysql2" : "^1.0.7",
9
- "app-root-path": "^3.1.0",
10
- "better-sqlite3": "^12.4.1"
11
- },
12
- "version": "0.2.29",
3
+ "version": "0.2.30",
13
4
  "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
- "homepage": "https://github.com/Tailor/MasterRecord#readme",
15
- "repository": {
16
- "type": "git",
17
- "url": "git+https://github.com/Tailor/Masterrecord.git"
18
- },
19
5
  "main": "MasterRecord.js",
6
+ "bin": {
7
+ "masterrecord": "./Migrations/cli.js"
8
+ },
20
9
  "scripts": {
21
- "test": "echo \"Error: no test specified\" && exit 1"
10
+ "test": "echo \"Error: no test specified\" && exit 1",
11
+ "preinstall": "node -e \"try { require.resolve('masterrecord'); } catch(e) { if (!process.env.npm_config_global) { console.log('\\n\\u001b[36m📦 MasterRecord Installation\\u001b[0m'); console.log('\\u001b[33mℹ For best experience, install globally first:\\u001b[0m'); console.log(' npm install -g masterrecord\\n'); } }\""
22
12
  },
23
13
  "author": "Alexandr Rich",
24
14
  "license": "MIT",
25
- "bin": {
26
- "masterrecord": "./Migrations/cli.js"
15
+ "homepage": "https://github.com/Tailor/MasterRecord#readme",
16
+ "repository": {
17
+ "type": "git",
18
+ "url": "git+https://github.com/Tailor/Masterrecord.git"
19
+ },
20
+ "keywords": [
21
+ "orm",
22
+ "database",
23
+ "migrations",
24
+ "mysql",
25
+ "sqlite",
26
+ "postgres",
27
+ "masterrecord"
28
+ ],
29
+ "dependencies": {
30
+ "commander": "^14.0.1",
31
+ "glob": "^11.0.3",
32
+ "deep-object-diff": "^1.1.9",
33
+ "pg": "^8.16.3",
34
+ "sync-mysql2": "^1.0.7",
35
+ "app-root-path": "^3.1.0",
36
+ "better-sqlite3": "^12.4.1"
27
37
  }
28
38
  }