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