mysqlsyncr 1.0.88 → 1.0.90

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/dist/index.cjs CHANGED
@@ -5235,13 +5235,15 @@ var compare = /*#__PURE__*/function () {
5235
5235
  type: 'success',
5236
5236
  diffs: diffs
5237
5237
  });
5238
- case 4:
5238
+ _context3.next = 6;
5239
+ return checker.closeConnection();
5240
+ case 6:
5239
5241
  case "end":
5240
5242
  return _context3.stop();
5241
5243
  }
5242
5244
  }, _callee3);
5243
5245
  })));
5244
- _context4.next = 8;
5246
+ _context4.next = 10;
5245
5247
  break;
5246
5248
  case 5:
5247
5249
  _context4.prev = 5;
@@ -5250,21 +5252,13 @@ var compare = /*#__PURE__*/function () {
5250
5252
  type: 'error',
5251
5253
  error: _context4.t0.message
5252
5254
  });
5253
- case 8:
5254
- _context4.prev = 8;
5255
- if (!checker) {
5256
- _context4.next = 12;
5257
- break;
5258
- }
5259
- _context4.next = 12;
5255
+ _context4.next = 10;
5260
5256
  return checker.closeConnection();
5261
- case 12:
5262
- return _context4.finish(8);
5263
- case 13:
5257
+ case 10:
5264
5258
  case "end":
5265
5259
  return _context4.stop();
5266
5260
  }
5267
- }, _callee4, null, [[0, 5, 8, 13]]);
5261
+ }, _callee4, null, [[0, 5]]);
5268
5262
  }));
5269
5263
  return function (_x3, _x4) {
5270
5264
  return _ref2.apply(this, arguments);
@@ -5281,24 +5275,39 @@ var compare = /*#__PURE__*/function () {
5281
5275
  };
5282
5276
  }();
5283
5277
  var apply = /*#__PURE__*/function () {
5284
- var _ref4 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee7(config, database, diffs) {
5285
- return _regeneratorRuntime().wrap(function _callee7$(_context7) {
5286
- while (1) switch (_context7.prev = _context7.next) {
5278
+ var _ref4 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee8(config, database, diffs) {
5279
+ return _regeneratorRuntime().wrap(function _callee8$(_context8) {
5280
+ while (1) switch (_context8.prev = _context8.next) {
5287
5281
  case 0:
5288
- return _context7.abrupt("return", new Promise(function (resolve, reject) {
5282
+ return _context8.abrupt("return", new Promise(function (resolve, reject) {
5289
5283
  var checker;
5290
5284
  try {
5291
5285
  checker = new DBStructureChecker(config, database);
5292
- checker.connection.on('error', function (err) {
5293
- console.error('Database connection error in route apply:', err);
5294
- reject({
5295
- type: 'error',
5296
- error: err.message
5297
- });
5298
- });
5299
- checker.connection.on('connect', /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee6() {
5300
- return _regeneratorRuntime().wrap(function _callee6$(_context6) {
5301
- while (1) switch (_context6.prev = _context6.next) {
5286
+ checker.connection.on('error', /*#__PURE__*/function () {
5287
+ var _ref5 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee6(err) {
5288
+ return _regeneratorRuntime().wrap(function _callee6$(_context6) {
5289
+ while (1) switch (_context6.prev = _context6.next) {
5290
+ case 0:
5291
+ console.error('Database connection error in route apply:', err);
5292
+ reject({
5293
+ type: 'error',
5294
+ error: err.message
5295
+ });
5296
+ _context6.next = 4;
5297
+ return checker.closeConnection();
5298
+ case 4:
5299
+ case "end":
5300
+ return _context6.stop();
5301
+ }
5302
+ }, _callee6);
5303
+ }));
5304
+ return function (_x8) {
5305
+ return _ref5.apply(this, arguments);
5306
+ };
5307
+ }());
5308
+ checker.connection.on('connect', /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee7() {
5309
+ return _regeneratorRuntime().wrap(function _callee7$(_context7) {
5310
+ while (1) switch (_context7.prev = _context7.next) {
5302
5311
  case 0:
5303
5312
  console.log('Connected to the database');
5304
5313
  checker.targetDatabase = database;
@@ -5308,39 +5317,34 @@ var apply = /*#__PURE__*/function () {
5308
5317
  database: database,
5309
5318
  diffs: diffs
5310
5319
  };
5311
- _context6.prev = 4;
5320
+ _context7.prev = 4;
5312
5321
  console.log('Applying the database structure based on JSON dumps');
5313
- _context6.next = 8;
5322
+ _context7.next = 8;
5314
5323
  return applyDifferences(checker.connection, database, diffs);
5315
5324
  case 8:
5316
5325
  resolve({
5317
5326
  type: 'success',
5318
5327
  message: 'Apply completed successfully'
5319
5328
  });
5320
- _context6.next = 14;
5321
- break;
5329
+ _context7.next = 11;
5330
+ return checker.closeConnection();
5322
5331
  case 11:
5323
- _context6.prev = 11;
5324
- _context6.t0 = _context6["catch"](4);
5332
+ _context7.next = 18;
5333
+ break;
5334
+ case 13:
5335
+ _context7.prev = 13;
5336
+ _context7.t0 = _context7["catch"](4);
5325
5337
  reject({
5326
5338
  type: 'error',
5327
- error: _context6.t0.message
5339
+ error: _context7.t0.message
5328
5340
  });
5329
- case 14:
5330
- _context6.prev = 14;
5331
- if (!checker) {
5332
- _context6.next = 18;
5333
- break;
5334
- }
5335
- _context6.next = 18;
5341
+ _context7.next = 18;
5336
5342
  return checker.closeConnection();
5337
5343
  case 18:
5338
- return _context6.finish(14);
5339
- case 19:
5340
5344
  case "end":
5341
- return _context6.stop();
5345
+ return _context7.stop();
5342
5346
  }
5343
- }, _callee6, null, [[4, 11, 14, 19]]);
5347
+ }, _callee7, null, [[4, 13]]);
5344
5348
  })));
5345
5349
  } catch (e) {
5346
5350
  reject({
@@ -5351,9 +5355,9 @@ var apply = /*#__PURE__*/function () {
5351
5355
  }));
5352
5356
  case 1:
5353
5357
  case "end":
5354
- return _context7.stop();
5358
+ return _context8.stop();
5355
5359
  }
5356
- }, _callee7);
5360
+ }, _callee8);
5357
5361
  }));
5358
5362
  return function apply(_x5, _x6, _x7) {
5359
5363
  return _ref4.apply(this, arguments);
@@ -5372,15 +5376,15 @@ var isMain = function () {
5372
5376
  }
5373
5377
  }();
5374
5378
  if (isMain) {
5375
- _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee9() {
5379
+ _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee10() {
5376
5380
  var _cli, command, config, argv, PORT, checker;
5377
- return _regeneratorRuntime().wrap(function _callee9$(_context9) {
5378
- while (1) switch (_context9.prev = _context9.next) {
5381
+ return _regeneratorRuntime().wrap(function _callee10$(_context10) {
5382
+ while (1) switch (_context10.prev = _context10.next) {
5379
5383
  case 0:
5380
5384
  _cli = cli(), command = _cli.command, config = _cli.config, argv = _cli.argv;
5381
5385
  console.log("MySQLsyncr started via command line");
5382
5386
  if (!(command === 'ui')) {
5383
- _context9.next = 12;
5387
+ _context10.next = 12;
5384
5388
  break;
5385
5389
  }
5386
5390
  PORT = argv.uiPort;
@@ -5388,58 +5392,58 @@ if (isMain) {
5388
5392
  console.log('Server started on port', PORT);
5389
5393
  console.log('Open http://localhost:' + PORT + ' in your browser to use the UI');
5390
5394
  if (!(argv.openUI && argv.openUI === true || argv.openUI === 'true')) {
5391
- _context9.next = 10;
5395
+ _context10.next = 10;
5392
5396
  break;
5393
5397
  }
5394
- _context9.next = 10;
5398
+ _context10.next = 10;
5395
5399
  return open("http://localhost:".concat(PORT));
5396
5400
  case 10:
5397
- _context9.next = 14;
5401
+ _context10.next = 14;
5398
5402
  break;
5399
5403
  case 12:
5400
5404
  // Handle other commands (dump, compare, update) as before
5401
5405
  checker = new DBStructureChecker(config, argv.database);
5402
- checker.connection.on('connect', /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee8() {
5406
+ checker.connection.on('connect', /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee9() {
5403
5407
  var diffs, totalDiffs, _totalDiffs, previousDiffs, runCount, maxRuns, _diffs;
5404
- return _regeneratorRuntime().wrap(function _callee8$(_context8) {
5405
- while (1) switch (_context8.prev = _context8.next) {
5408
+ return _regeneratorRuntime().wrap(function _callee9$(_context9) {
5409
+ while (1) switch (_context9.prev = _context9.next) {
5406
5410
  case 0:
5407
5411
  console.log('Connected to the database');
5408
5412
  checker.targetDatabase = argv.database;
5409
5413
  checker.command = command;
5410
5414
  checker.options = argv;
5411
- _context8.prev = 4;
5415
+ _context9.prev = 4;
5412
5416
  if (!(command === 'dump')) {
5413
- _context8.next = 11;
5417
+ _context9.next = 11;
5414
5418
  break;
5415
5419
  }
5416
5420
  console.log('Dumping the database structure to files');
5417
- _context8.next = 9;
5421
+ _context9.next = 9;
5418
5422
  return dumpAllDatabases(checker.connection, command, argv);
5419
5423
  case 9:
5420
- _context8.next = 42;
5424
+ _context9.next = 42;
5421
5425
  break;
5422
5426
  case 11:
5423
5427
  if (!(command === 'compare')) {
5424
- _context8.next = 21;
5428
+ _context9.next = 21;
5425
5429
  break;
5426
5430
  }
5427
5431
  console.log('Comparing the database structure with JSON dumps (dry run)');
5428
- _context8.next = 15;
5432
+ _context9.next = 15;
5429
5433
  return compareAllDatabases(checker.connection, argv.output, false, command, argv);
5430
5434
  case 15:
5431
- diffs = _context8.sent;
5435
+ diffs = _context9.sent;
5432
5436
  // Dry run
5433
5437
  totalDiffs = Object.values(diffs).reduce(function (acc, arr) {
5434
5438
  return acc + arr.length;
5435
5439
  }, 0);
5436
5440
  console.log('Total differences count:', totalDiffs);
5437
5441
  fs.writeFileSync(path.join(argv.output, 'diffs.json'), JSON.stringify(diffs, null, 4));
5438
- _context8.next = 42;
5442
+ _context9.next = 42;
5439
5443
  break;
5440
5444
  case 21:
5441
5445
  if (!(command === 'update')) {
5442
- _context8.next = 42;
5446
+ _context9.next = 42;
5443
5447
  break;
5444
5448
  }
5445
5449
  console.log('Updating the database structure based on JSON dumps');
@@ -5449,14 +5453,14 @@ if (isMain) {
5449
5453
  maxRuns = 6;
5450
5454
  case 27:
5451
5455
  if (!(runCount < maxRuns && _totalDiffs > 0 && (_totalDiffs < previousDiffs || previousDiffs === Infinity))) {
5452
- _context8.next = 42;
5456
+ _context9.next = 42;
5453
5457
  break;
5454
5458
  }
5455
5459
  console.log('Running update command. Run count:', runCount);
5456
- _context8.next = 31;
5460
+ _context9.next = 31;
5457
5461
  return compareAllDatabases(checker.connection, argv.output, true, command, argv);
5458
5462
  case 31:
5459
- _diffs = _context8.sent;
5463
+ _diffs = _context9.sent;
5460
5464
  // Apply updates
5461
5465
  previousDiffs = _totalDiffs; // Update previous differences
5462
5466
  _totalDiffs = Object.values(_diffs).reduce(function (acc, arr) {
@@ -5465,41 +5469,41 @@ if (isMain) {
5465
5469
  console.log('Total differences count:', _totalDiffs);
5466
5470
  runCount++;
5467
5471
  if (!(_totalDiffs > 0 && runCount < maxRuns)) {
5468
- _context8.next = 40;
5472
+ _context9.next = 40;
5469
5473
  break;
5470
5474
  }
5471
5475
  console.log('Total differences count is still greater than 0. Waiting 1 second before next run. Run count:', runCount);
5472
- _context8.next = 40;
5476
+ _context9.next = 40;
5473
5477
  return new Promise(function (resolve) {
5474
5478
  return setTimeout(resolve, 1000);
5475
5479
  });
5476
5480
  case 40:
5477
- _context8.next = 27;
5481
+ _context9.next = 27;
5478
5482
  break;
5479
5483
  case 42:
5480
- _context8.next = 47;
5484
+ _context9.next = 47;
5481
5485
  break;
5482
5486
  case 44:
5483
- _context8.prev = 44;
5484
- _context8.t0 = _context8["catch"](4);
5485
- console.error(_context8.t0.message);
5487
+ _context9.prev = 44;
5488
+ _context9.t0 = _context9["catch"](4);
5489
+ console.error(_context9.t0.message);
5486
5490
  case 47:
5487
- _context8.prev = 47;
5488
- _context8.next = 50;
5491
+ _context9.prev = 47;
5492
+ _context9.next = 50;
5489
5493
  return checker.closeConnection();
5490
5494
  case 50:
5491
- return _context8.finish(47);
5495
+ return _context9.finish(47);
5492
5496
  case 51:
5493
5497
  case "end":
5494
- return _context8.stop();
5498
+ return _context9.stop();
5495
5499
  }
5496
- }, _callee8, null, [[4, 44, 47, 51]]);
5500
+ }, _callee9, null, [[4, 44, 47, 51]]);
5497
5501
  })));
5498
5502
  case 14:
5499
5503
  case "end":
5500
- return _context9.stop();
5504
+ return _context10.stop();
5501
5505
  }
5502
- }, _callee9);
5506
+ }, _callee10);
5503
5507
  }))();
5504
5508
  }
5505
5509
 
package/dist/index.js CHANGED
@@ -5232,13 +5232,15 @@ var compare = /*#__PURE__*/function () {
5232
5232
  type: 'success',
5233
5233
  diffs: diffs
5234
5234
  });
5235
- case 4:
5235
+ _context3.next = 6;
5236
+ return checker.closeConnection();
5237
+ case 6:
5236
5238
  case "end":
5237
5239
  return _context3.stop();
5238
5240
  }
5239
5241
  }, _callee3);
5240
5242
  })));
5241
- _context4.next = 8;
5243
+ _context4.next = 10;
5242
5244
  break;
5243
5245
  case 5:
5244
5246
  _context4.prev = 5;
@@ -5247,21 +5249,13 @@ var compare = /*#__PURE__*/function () {
5247
5249
  type: 'error',
5248
5250
  error: _context4.t0.message
5249
5251
  });
5250
- case 8:
5251
- _context4.prev = 8;
5252
- if (!checker) {
5253
- _context4.next = 12;
5254
- break;
5255
- }
5256
- _context4.next = 12;
5252
+ _context4.next = 10;
5257
5253
  return checker.closeConnection();
5258
- case 12:
5259
- return _context4.finish(8);
5260
- case 13:
5254
+ case 10:
5261
5255
  case "end":
5262
5256
  return _context4.stop();
5263
5257
  }
5264
- }, _callee4, null, [[0, 5, 8, 13]]);
5258
+ }, _callee4, null, [[0, 5]]);
5265
5259
  }));
5266
5260
  return function (_x3, _x4) {
5267
5261
  return _ref2.apply(this, arguments);
@@ -5278,24 +5272,39 @@ var compare = /*#__PURE__*/function () {
5278
5272
  };
5279
5273
  }();
5280
5274
  var apply = /*#__PURE__*/function () {
5281
- var _ref4 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee7(config, database, diffs) {
5282
- return _regeneratorRuntime().wrap(function _callee7$(_context7) {
5283
- while (1) switch (_context7.prev = _context7.next) {
5275
+ var _ref4 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee8(config, database, diffs) {
5276
+ return _regeneratorRuntime().wrap(function _callee8$(_context8) {
5277
+ while (1) switch (_context8.prev = _context8.next) {
5284
5278
  case 0:
5285
- return _context7.abrupt("return", new Promise(function (resolve, reject) {
5279
+ return _context8.abrupt("return", new Promise(function (resolve, reject) {
5286
5280
  var checker;
5287
5281
  try {
5288
5282
  checker = new DBStructureChecker(config, database);
5289
- checker.connection.on('error', function (err) {
5290
- console.error('Database connection error in route apply:', err);
5291
- reject({
5292
- type: 'error',
5293
- error: err.message
5294
- });
5295
- });
5296
- checker.connection.on('connect', /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee6() {
5297
- return _regeneratorRuntime().wrap(function _callee6$(_context6) {
5298
- while (1) switch (_context6.prev = _context6.next) {
5283
+ checker.connection.on('error', /*#__PURE__*/function () {
5284
+ var _ref5 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee6(err) {
5285
+ return _regeneratorRuntime().wrap(function _callee6$(_context6) {
5286
+ while (1) switch (_context6.prev = _context6.next) {
5287
+ case 0:
5288
+ console.error('Database connection error in route apply:', err);
5289
+ reject({
5290
+ type: 'error',
5291
+ error: err.message
5292
+ });
5293
+ _context6.next = 4;
5294
+ return checker.closeConnection();
5295
+ case 4:
5296
+ case "end":
5297
+ return _context6.stop();
5298
+ }
5299
+ }, _callee6);
5300
+ }));
5301
+ return function (_x8) {
5302
+ return _ref5.apply(this, arguments);
5303
+ };
5304
+ }());
5305
+ checker.connection.on('connect', /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee7() {
5306
+ return _regeneratorRuntime().wrap(function _callee7$(_context7) {
5307
+ while (1) switch (_context7.prev = _context7.next) {
5299
5308
  case 0:
5300
5309
  console.log('Connected to the database');
5301
5310
  checker.targetDatabase = database;
@@ -5305,39 +5314,34 @@ var apply = /*#__PURE__*/function () {
5305
5314
  database: database,
5306
5315
  diffs: diffs
5307
5316
  };
5308
- _context6.prev = 4;
5317
+ _context7.prev = 4;
5309
5318
  console.log('Applying the database structure based on JSON dumps');
5310
- _context6.next = 8;
5319
+ _context7.next = 8;
5311
5320
  return applyDifferences(checker.connection, database, diffs);
5312
5321
  case 8:
5313
5322
  resolve({
5314
5323
  type: 'success',
5315
5324
  message: 'Apply completed successfully'
5316
5325
  });
5317
- _context6.next = 14;
5318
- break;
5326
+ _context7.next = 11;
5327
+ return checker.closeConnection();
5319
5328
  case 11:
5320
- _context6.prev = 11;
5321
- _context6.t0 = _context6["catch"](4);
5329
+ _context7.next = 18;
5330
+ break;
5331
+ case 13:
5332
+ _context7.prev = 13;
5333
+ _context7.t0 = _context7["catch"](4);
5322
5334
  reject({
5323
5335
  type: 'error',
5324
- error: _context6.t0.message
5336
+ error: _context7.t0.message
5325
5337
  });
5326
- case 14:
5327
- _context6.prev = 14;
5328
- if (!checker) {
5329
- _context6.next = 18;
5330
- break;
5331
- }
5332
- _context6.next = 18;
5338
+ _context7.next = 18;
5333
5339
  return checker.closeConnection();
5334
5340
  case 18:
5335
- return _context6.finish(14);
5336
- case 19:
5337
5341
  case "end":
5338
- return _context6.stop();
5342
+ return _context7.stop();
5339
5343
  }
5340
- }, _callee6, null, [[4, 11, 14, 19]]);
5344
+ }, _callee7, null, [[4, 13]]);
5341
5345
  })));
5342
5346
  } catch (e) {
5343
5347
  reject({
@@ -5348,9 +5352,9 @@ var apply = /*#__PURE__*/function () {
5348
5352
  }));
5349
5353
  case 1:
5350
5354
  case "end":
5351
- return _context7.stop();
5355
+ return _context8.stop();
5352
5356
  }
5353
- }, _callee7);
5357
+ }, _callee8);
5354
5358
  }));
5355
5359
  return function apply(_x5, _x6, _x7) {
5356
5360
  return _ref4.apply(this, arguments);
@@ -5369,15 +5373,15 @@ var isMain = function () {
5369
5373
  }
5370
5374
  }();
5371
5375
  if (isMain) {
5372
- _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee9() {
5376
+ _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee10() {
5373
5377
  var _cli, command, config, argv, PORT, checker;
5374
- return _regeneratorRuntime().wrap(function _callee9$(_context9) {
5375
- while (1) switch (_context9.prev = _context9.next) {
5378
+ return _regeneratorRuntime().wrap(function _callee10$(_context10) {
5379
+ while (1) switch (_context10.prev = _context10.next) {
5376
5380
  case 0:
5377
5381
  _cli = cli(), command = _cli.command, config = _cli.config, argv = _cli.argv;
5378
5382
  console.log("MySQLsyncr started via command line");
5379
5383
  if (!(command === 'ui')) {
5380
- _context9.next = 12;
5384
+ _context10.next = 12;
5381
5385
  break;
5382
5386
  }
5383
5387
  PORT = argv.uiPort;
@@ -5385,58 +5389,58 @@ if (isMain) {
5385
5389
  console.log('Server started on port', PORT);
5386
5390
  console.log('Open http://localhost:' + PORT + ' in your browser to use the UI');
5387
5391
  if (!(argv.openUI && argv.openUI === true || argv.openUI === 'true')) {
5388
- _context9.next = 10;
5392
+ _context10.next = 10;
5389
5393
  break;
5390
5394
  }
5391
- _context9.next = 10;
5395
+ _context10.next = 10;
5392
5396
  return open("http://localhost:".concat(PORT));
5393
5397
  case 10:
5394
- _context9.next = 14;
5398
+ _context10.next = 14;
5395
5399
  break;
5396
5400
  case 12:
5397
5401
  // Handle other commands (dump, compare, update) as before
5398
5402
  checker = new DBStructureChecker(config, argv.database);
5399
- checker.connection.on('connect', /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee8() {
5403
+ checker.connection.on('connect', /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee9() {
5400
5404
  var diffs, totalDiffs, _totalDiffs, previousDiffs, runCount, maxRuns, _diffs;
5401
- return _regeneratorRuntime().wrap(function _callee8$(_context8) {
5402
- while (1) switch (_context8.prev = _context8.next) {
5405
+ return _regeneratorRuntime().wrap(function _callee9$(_context9) {
5406
+ while (1) switch (_context9.prev = _context9.next) {
5403
5407
  case 0:
5404
5408
  console.log('Connected to the database');
5405
5409
  checker.targetDatabase = argv.database;
5406
5410
  checker.command = command;
5407
5411
  checker.options = argv;
5408
- _context8.prev = 4;
5412
+ _context9.prev = 4;
5409
5413
  if (!(command === 'dump')) {
5410
- _context8.next = 11;
5414
+ _context9.next = 11;
5411
5415
  break;
5412
5416
  }
5413
5417
  console.log('Dumping the database structure to files');
5414
- _context8.next = 9;
5418
+ _context9.next = 9;
5415
5419
  return dumpAllDatabases(checker.connection, command, argv);
5416
5420
  case 9:
5417
- _context8.next = 42;
5421
+ _context9.next = 42;
5418
5422
  break;
5419
5423
  case 11:
5420
5424
  if (!(command === 'compare')) {
5421
- _context8.next = 21;
5425
+ _context9.next = 21;
5422
5426
  break;
5423
5427
  }
5424
5428
  console.log('Comparing the database structure with JSON dumps (dry run)');
5425
- _context8.next = 15;
5429
+ _context9.next = 15;
5426
5430
  return compareAllDatabases(checker.connection, argv.output, false, command, argv);
5427
5431
  case 15:
5428
- diffs = _context8.sent;
5432
+ diffs = _context9.sent;
5429
5433
  // Dry run
5430
5434
  totalDiffs = Object.values(diffs).reduce(function (acc, arr) {
5431
5435
  return acc + arr.length;
5432
5436
  }, 0);
5433
5437
  console.log('Total differences count:', totalDiffs);
5434
5438
  fs$3.writeFileSync(path.join(argv.output, 'diffs.json'), JSON.stringify(diffs, null, 4));
5435
- _context8.next = 42;
5439
+ _context9.next = 42;
5436
5440
  break;
5437
5441
  case 21:
5438
5442
  if (!(command === 'update')) {
5439
- _context8.next = 42;
5443
+ _context9.next = 42;
5440
5444
  break;
5441
5445
  }
5442
5446
  console.log('Updating the database structure based on JSON dumps');
@@ -5446,14 +5450,14 @@ if (isMain) {
5446
5450
  maxRuns = 6;
5447
5451
  case 27:
5448
5452
  if (!(runCount < maxRuns && _totalDiffs > 0 && (_totalDiffs < previousDiffs || previousDiffs === Infinity))) {
5449
- _context8.next = 42;
5453
+ _context9.next = 42;
5450
5454
  break;
5451
5455
  }
5452
5456
  console.log('Running update command. Run count:', runCount);
5453
- _context8.next = 31;
5457
+ _context9.next = 31;
5454
5458
  return compareAllDatabases(checker.connection, argv.output, true, command, argv);
5455
5459
  case 31:
5456
- _diffs = _context8.sent;
5460
+ _diffs = _context9.sent;
5457
5461
  // Apply updates
5458
5462
  previousDiffs = _totalDiffs; // Update previous differences
5459
5463
  _totalDiffs = Object.values(_diffs).reduce(function (acc, arr) {
@@ -5462,41 +5466,41 @@ if (isMain) {
5462
5466
  console.log('Total differences count:', _totalDiffs);
5463
5467
  runCount++;
5464
5468
  if (!(_totalDiffs > 0 && runCount < maxRuns)) {
5465
- _context8.next = 40;
5469
+ _context9.next = 40;
5466
5470
  break;
5467
5471
  }
5468
5472
  console.log('Total differences count is still greater than 0. Waiting 1 second before next run. Run count:', runCount);
5469
- _context8.next = 40;
5473
+ _context9.next = 40;
5470
5474
  return new Promise(function (resolve) {
5471
5475
  return setTimeout(resolve, 1000);
5472
5476
  });
5473
5477
  case 40:
5474
- _context8.next = 27;
5478
+ _context9.next = 27;
5475
5479
  break;
5476
5480
  case 42:
5477
- _context8.next = 47;
5481
+ _context9.next = 47;
5478
5482
  break;
5479
5483
  case 44:
5480
- _context8.prev = 44;
5481
- _context8.t0 = _context8["catch"](4);
5482
- console.error(_context8.t0.message);
5484
+ _context9.prev = 44;
5485
+ _context9.t0 = _context9["catch"](4);
5486
+ console.error(_context9.t0.message);
5483
5487
  case 47:
5484
- _context8.prev = 47;
5485
- _context8.next = 50;
5488
+ _context9.prev = 47;
5489
+ _context9.next = 50;
5486
5490
  return checker.closeConnection();
5487
5491
  case 50:
5488
- return _context8.finish(47);
5492
+ return _context9.finish(47);
5489
5493
  case 51:
5490
5494
  case "end":
5491
- return _context8.stop();
5495
+ return _context9.stop();
5492
5496
  }
5493
- }, _callee8, null, [[4, 44, 47, 51]]);
5497
+ }, _callee9, null, [[4, 44, 47, 51]]);
5494
5498
  })));
5495
5499
  case 14:
5496
5500
  case "end":
5497
- return _context9.stop();
5501
+ return _context10.stop();
5498
5502
  }
5499
- }, _callee9);
5503
+ }, _callee10);
5500
5504
  }))();
5501
5505
  }
5502
5506
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mysqlsyncr",
3
- "version": "1.0.88",
3
+ "version": "1.0.90",
4
4
  "description": "",
5
5
  "main": "dist/index.cjs.js",
6
6
  "module": "dist/index.esm.js",
package/src/index.js CHANGED
@@ -53,15 +53,12 @@ const compare = async (config, output) => {
53
53
  checker.connection.on('connect', async () => {
54
54
  const diffs = await compareAllDatabases(checker.connection, output, false, 'compare', { output: output });
55
55
  resolve({ type: 'success', diffs });
56
-
56
+ await checker.closeConnection();
57
57
  });
58
58
  } catch (e) {
59
59
  reject({ type: 'error', error: e.message });
60
- } finally {
61
- if (checker) {
62
- await checker.closeConnection();
63
- }
64
- }
60
+ await checker.closeConnection();
61
+ }
65
62
  });
66
63
  }
67
64
 
@@ -71,9 +68,10 @@ const apply = async (config, database, diffs) => {
71
68
  try {
72
69
  checker = new DBStructureChecker(config, database);
73
70
 
74
- checker.connection.on('error', (err) => {
71
+ checker.connection.on('error', async (err) => {
75
72
  console.error('Database connection error in route apply:', err);
76
73
  reject({ type: 'error', error: err.message });
74
+ await checker.closeConnection();
77
75
  });
78
76
 
79
77
  checker.connection.on('connect', async () => {
@@ -85,12 +83,10 @@ const apply = async (config, database, diffs) => {
85
83
  console.log('Applying the database structure based on JSON dumps');
86
84
  await applyDifferences(checker.connection, database, diffs);
87
85
  resolve({ type: 'success', message: 'Apply completed successfully' });
86
+ await checker.closeConnection();
88
87
  } catch (err) {
89
88
  reject({ type: 'error', error: err.message });
90
- } finally {
91
- if (checker) {
92
- await checker.closeConnection();
93
- }
89
+ await checker.closeConnection();
94
90
  }
95
91
  });
96
92
  } catch (e) {