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