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