mysqlsyncr 1.0.82 → 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.js CHANGED
@@ -6,7 +6,6 @@ import path, { normalize, resolve, dirname, basename, extname, relative, join }
6
6
  import yargs from 'yargs';
7
7
  import { notStrictEqual, strictEqual } from 'assert';
8
8
  import { fileURLToPath } from 'url';
9
- import 'module';
10
9
  import fs, { readdir, mkdir } from 'fs/promises';
11
10
  import express from 'express';
12
11
  import http from 'http';
@@ -3188,7 +3187,14 @@ var findDifferences = function findDifferences(expected, current) {
3188
3187
  _tableName = _Object$entries$_i[0],
3189
3188
  contents = _Object$entries$_i[1];
3190
3189
  //check if craete table matches from json, if so, we dont need to compare indexes, triggers, or fields
3191
-
3190
+ var columns = contents.columns,
3191
+ indexes = contents.indexes,
3192
+ triggers = contents.triggers;
3193
+ contents.createSQL;
3194
+ contents.name;
3195
+ contents.engine;
3196
+ contents.charset;
3197
+ contents.collate;
3192
3198
  if (!current.tables[_tableName]) {
3193
3199
  console.log('missing_table', contents);
3194
3200
  differences.push({
@@ -3198,70 +3204,73 @@ var findDifferences = function findDifferences(expected, current) {
3198
3204
  });
3199
3205
  continue;
3200
3206
  }
3201
-
3202
- //verify triggers
3203
- logger('Verifying triggers for table', _tableName);
3204
- var _iterator = _createForOfIteratorHelper(triggers),
3205
- _step;
3206
3207
  try {
3207
- var _loop = function _loop() {
3208
- var trigger = _step.value;
3209
- var currentTrigger = current.tables[_tableName].triggers.find(function (t) {
3210
- return t.Name === trigger.Name;
3211
- });
3212
- if (!currentTrigger) {
3213
- logger('Missing trigger', trigger);
3214
- differences.push({
3215
- type: 'missing_trigger',
3216
- tableName: _tableName,
3217
- trigger: trigger
3208
+ //verify triggers
3209
+ logger('Verifying triggers for table', _tableName);
3210
+ var _iterator = _createForOfIteratorHelper(triggers),
3211
+ _step;
3212
+ try {
3213
+ var _loop = function _loop() {
3214
+ var trigger = _step.value;
3215
+ var currentTrigger = current.tables[_tableName].triggers.find(function (t) {
3216
+ return t.Name === trigger.Name;
3218
3217
  });
3219
- } else {
3220
- // Compare additional properties if needed
3221
- if (currentTrigger.Event !== trigger.Event || currentTrigger.Statement !== trigger.Statement) {
3222
- logger('Mismatched trigger', {
3223
- expected: trigger,
3224
- current: currentTrigger
3225
- });
3218
+ if (!currentTrigger) {
3219
+ logger('Missing trigger', trigger);
3226
3220
  differences.push({
3227
- type: 'mismatched_trigger',
3221
+ type: 'missing_trigger',
3228
3222
  tableName: _tableName,
3229
3223
  trigger: trigger
3230
3224
  });
3225
+ } else {
3226
+ // Compare additional properties if needed
3227
+ if (currentTrigger.Event !== trigger.Event || currentTrigger.Statement !== trigger.Statement) {
3228
+ logger('Mismatched trigger', {
3229
+ expected: trigger,
3230
+ current: currentTrigger
3231
+ });
3232
+ differences.push({
3233
+ type: 'mismatched_trigger',
3234
+ tableName: _tableName,
3235
+ trigger: trigger
3236
+ });
3237
+ }
3231
3238
  }
3239
+ };
3240
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
3241
+ _loop();
3232
3242
  }
3233
- };
3234
- for (_iterator.s(); !(_step = _iterator.n()).done;) {
3235
- _loop();
3243
+ } catch (err) {
3244
+ _iterator.e(err);
3245
+ } finally {
3246
+ _iterator.f();
3236
3247
  }
3237
- } catch (err) {
3238
- _iterator.e(err);
3239
- } finally {
3240
- _iterator.f();
3241
- }
3242
- var _iterator2 = _createForOfIteratorHelper(current.tables[_tableName].triggers),
3243
- _step2;
3244
- try {
3245
- var _loop2 = function _loop2() {
3246
- var trigger = _step2.value;
3247
- if (!triggers.some(function (t) {
3248
- return t.Name === trigger.Name;
3249
- })) {
3250
- logger('Extra trigger', trigger);
3251
- differences.push({
3252
- type: 'extra_trigger',
3253
- tableName: _tableName,
3254
- trigger: trigger
3255
- });
3248
+ var _iterator2 = _createForOfIteratorHelper(current.tables[_tableName].triggers),
3249
+ _step2;
3250
+ try {
3251
+ var _loop2 = function _loop2() {
3252
+ var trigger = _step2.value;
3253
+ if (!triggers.some(function (t) {
3254
+ return t.Name === trigger.Name;
3255
+ })) {
3256
+ logger('Extra trigger', trigger);
3257
+ differences.push({
3258
+ type: 'extra_trigger',
3259
+ tableName: _tableName,
3260
+ trigger: trigger
3261
+ });
3262
+ }
3263
+ };
3264
+ for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
3265
+ _loop2();
3256
3266
  }
3257
- };
3258
- for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
3259
- _loop2();
3267
+ } catch (err) {
3268
+ _iterator2.e(err);
3269
+ } finally {
3270
+ _iterator2.f();
3260
3271
  }
3261
- } catch (err) {
3262
- _iterator2.e(err);
3263
- } finally {
3264
- _iterator2.f();
3272
+ } catch (e) {
3273
+ console.error("Error verifying triggers for table ".concat(_tableName), e);
3265
3274
  }
3266
3275
  var createTableSql = current.tables[_tableName].createSQL;
3267
3276
  if (createTableSql === contents.createSQL) {
@@ -3272,14 +3281,6 @@ var findDifferences = function findDifferences(expected, current) {
3272
3281
  logger(createTableSql);
3273
3282
  logger(contents.createSQL);
3274
3283
  }
3275
- var columns = contents.columns,
3276
- indexes = contents.indexes,
3277
- triggers = contents.triggers;
3278
- contents.createSQL;
3279
- contents.name;
3280
- contents.engine;
3281
- contents.charset;
3282
- contents.collate;
3283
3284
  current.tables[_tableName].columns.map(function (f) {
3284
3285
  return f.Field;
3285
3286
  });
@@ -3563,7 +3564,7 @@ var findDifferences = function findDifferences(expected, current) {
3563
3564
  return differences;
3564
3565
  };
3565
3566
 
3566
- var applyDifferences = /*#__PURE__*/function () {
3567
+ var applyDifferences$1 = /*#__PURE__*/function () {
3567
3568
  var _ref = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(connection, database, differences) {
3568
3569
  var _iterator, _step, _loop, _ret;
3569
3570
  return _regeneratorRuntime().wrap(function _callee$(_context2) {
@@ -4058,12 +4059,12 @@ var compareAllDatabases = /*#__PURE__*/function () {
4058
4059
  expectedDatabases = expectedDatabases.filter(function (file) {
4059
4060
  return file !== 'dumpInfo.json';
4060
4061
  });
4061
- // console.log('Expected databases from input directory:', expectedDatabases);
4062
+ console.log('Expected databases from input directory:', expectedDatabases);
4062
4063
 
4063
4064
  // Check existing databases
4064
- _context.next = 13;
4065
+ _context.next = 14;
4065
4066
  return getDatabases(connection);
4066
- case 13:
4067
+ case 14:
4067
4068
  existingDatabases = _context.sent;
4068
4069
  // console.log('Existing databases:', existingDatabases);
4069
4070
  allDifferences = {};
@@ -4072,20 +4073,20 @@ var compareAllDatabases = /*#__PURE__*/function () {
4072
4073
 
4073
4074
  // Note missing databases and prepare to create them
4074
4075
  _iterator = _createForOfIteratorHelper(expectedDatabases);
4075
- _context.prev = 18;
4076
+ _context.prev = 19;
4076
4077
  _iterator.s();
4077
- case 20:
4078
+ case 21:
4078
4079
  if ((_step = _iterator.n()).done) {
4079
- _context.next = 27;
4080
+ _context.next = 28;
4080
4081
  break;
4081
4082
  }
4082
4083
  _database = _step.value;
4083
4084
  if (!(options && options.database && options.database !== _database)) {
4084
- _context.next = 24;
4085
+ _context.next = 25;
4085
4086
  break;
4086
4087
  }
4087
- return _context.abrupt("continue", 25);
4088
- case 24:
4088
+ return _context.abrupt("continue", 26);
4089
+ case 25:
4089
4090
  if (!existingDatabases.includes(_database)) {
4090
4091
  allDifferences[_database] = [{
4091
4092
  database: _database,
@@ -4094,58 +4095,58 @@ var compareAllDatabases = /*#__PURE__*/function () {
4094
4095
  }];
4095
4096
  missingDatabases.push(_database);
4096
4097
  }
4097
- case 25:
4098
- _context.next = 20;
4098
+ case 26:
4099
+ _context.next = 21;
4099
4100
  break;
4100
- case 27:
4101
- _context.next = 32;
4101
+ case 28:
4102
+ _context.next = 33;
4102
4103
  break;
4103
- case 29:
4104
- _context.prev = 29;
4105
- _context.t0 = _context["catch"](18);
4104
+ case 30:
4105
+ _context.prev = 30;
4106
+ _context.t0 = _context["catch"](19);
4106
4107
  _iterator.e(_context.t0);
4107
- case 32:
4108
- _context.prev = 32;
4108
+ case 33:
4109
+ _context.prev = 33;
4109
4110
  _iterator.f();
4110
- return _context.finish(32);
4111
- case 35:
4111
+ return _context.finish(33);
4112
+ case 36:
4112
4113
  if (!(missingDatabases.length > 0 && update)) {
4113
- _context.next = 58;
4114
+ _context.next = 59;
4114
4115
  break;
4115
4116
  }
4116
4117
  console.log('Creating missing databases:');
4117
4118
  _iterator2 = _createForOfIteratorHelper(missingDatabases);
4118
- _context.prev = 38;
4119
+ _context.prev = 39;
4119
4120
  _iterator2.s();
4120
- case 40:
4121
+ case 41:
4121
4122
  if ((_step2 = _iterator2.n()).done) {
4122
- _context.next = 48;
4123
+ _context.next = 49;
4123
4124
  break;
4124
4125
  }
4125
4126
  database = _step2.value;
4126
4127
  console.log("Creating database ".concat(database, "..."));
4127
- _context.next = 45;
4128
+ _context.next = 46;
4128
4129
  return connection.query("CREATE DATABASE `".concat(database, "`;"));
4129
- case 45:
4130
- console.log("Database ".concat(database, " created."));
4131
4130
  case 46:
4132
- _context.next = 40;
4131
+ console.log("Database ".concat(database, " created."));
4132
+ case 47:
4133
+ _context.next = 41;
4133
4134
  break;
4134
- case 48:
4135
- _context.next = 53;
4135
+ case 49:
4136
+ _context.next = 54;
4136
4137
  break;
4137
- case 50:
4138
- _context.prev = 50;
4139
- _context.t1 = _context["catch"](38);
4138
+ case 51:
4139
+ _context.prev = 51;
4140
+ _context.t1 = _context["catch"](39);
4140
4141
  _iterator2.e(_context.t1);
4141
- case 53:
4142
- _context.prev = 53;
4142
+ case 54:
4143
+ _context.prev = 54;
4143
4144
  _iterator2.f();
4144
- return _context.finish(53);
4145
- case 56:
4146
- _context.next = 59;
4145
+ return _context.finish(54);
4146
+ case 57:
4147
+ _context.next = 60;
4147
4148
  break;
4148
- case 58:
4149
+ case 59:
4149
4150
  if (missingDatabases.length > 0 && !update) {
4150
4151
  console.error('Missing databases found but update is not enabled. Please enable update to create missing databases.');
4151
4152
  console.error('Please run the command again with the --update flag to create missing databases.');
@@ -4154,87 +4155,87 @@ var compareAllDatabases = /*#__PURE__*/function () {
4154
4155
  } else {
4155
4156
  console.log('All expected databases exist.');
4156
4157
  }
4157
- case 59:
4158
+ case 60:
4158
4159
  _iterator3 = _createForOfIteratorHelper(expectedDatabases);
4159
- _context.prev = 60;
4160
+ _context.prev = 61;
4160
4161
  _iterator3.s();
4161
- case 62:
4162
+ case 63:
4162
4163
  if ((_step3 = _iterator3.n()).done) {
4163
- _context.next = 100;
4164
+ _context.next = 101;
4164
4165
  break;
4165
4166
  }
4166
4167
  _database2 = _step3.value;
4167
4168
  if (!(options && options.database && options.database !== _database2)) {
4168
- _context.next = 66;
4169
+ _context.next = 67;
4169
4170
  break;
4170
4171
  }
4171
- return _context.abrupt("continue", 98);
4172
- case 66:
4172
+ return _context.abrupt("continue", 99);
4173
+ case 67:
4173
4174
  if (!missingDatabases.includes(_database2)) {
4174
- _context.next = 69;
4175
+ _context.next = 70;
4175
4176
  break;
4176
4177
  }
4177
4178
  console.log('Skipping database', _database2, 'because it is missing');
4178
- return _context.abrupt("continue", 98);
4179
- case 69:
4179
+ return _context.abrupt("continue", 99);
4180
+ case 70:
4180
4181
  filePath = path.join(inputDir, _database2, "".concat(_database2, ".json"));
4181
- _context.prev = 70;
4182
- _context.next = 73;
4182
+ _context.prev = 71;
4183
+ _context.next = 74;
4183
4184
  return fs.readFile(filePath, 'utf-8');
4184
- case 73:
4185
+ case 74:
4185
4186
  fileContent = _context.sent;
4186
4187
  expectedStructure = JSON.parse(fileContent);
4187
4188
  console.log('Getting database structure for', _database2);
4188
- _context.next = 78;
4189
+ _context.next = 79;
4189
4190
  return getDatabaseStructure(connection, _database2, command, options);
4190
- case 78:
4191
+ case 79:
4191
4192
  currentStructure = _context.sent;
4192
4193
  console.log('Database structure for', _database2, 'obtained');
4193
4194
  differences = findDifferences(expectedStructure, currentStructure);
4194
4195
  console.log('Differences for', _database2, 'obtained');
4195
4196
  if (update) {
4196
- _context.next = 87;
4197
+ _context.next = 88;
4197
4198
  break;
4198
4199
  }
4199
4200
  console.log('Logging differences for', _database2);
4200
4201
  logDifferences(differences, _database2, true);
4201
- _context.next = 92;
4202
+ _context.next = 93;
4202
4203
  break;
4203
- case 87:
4204
+ case 88:
4204
4205
  console.log('Logging differences for', _database2);
4205
4206
  logDifferences(differences, _database2, false);
4206
4207
  console.log('Applying differences for', _database2);
4207
- _context.next = 92;
4208
- return applyDifferences(connection, _database2, differences);
4209
- case 92:
4208
+ _context.next = 93;
4209
+ return applyDifferences$1(connection, _database2, differences);
4210
+ case 93:
4210
4211
  allDifferences[_database2] = differences;
4211
- _context.next = 98;
4212
+ _context.next = 99;
4212
4213
  break;
4213
- case 95:
4214
- _context.prev = 95;
4215
- _context.t2 = _context["catch"](70);
4214
+ case 96:
4215
+ _context.prev = 96;
4216
+ _context.t2 = _context["catch"](71);
4216
4217
  console.error("Error processing database ".concat(_database2, ":"), _context.t2.message);
4217
- case 98:
4218
- _context.next = 62;
4218
+ case 99:
4219
+ _context.next = 63;
4219
4220
  break;
4220
- case 100:
4221
- _context.next = 105;
4221
+ case 101:
4222
+ _context.next = 106;
4222
4223
  break;
4223
- case 102:
4224
- _context.prev = 102;
4225
- _context.t3 = _context["catch"](60);
4224
+ case 103:
4225
+ _context.prev = 103;
4226
+ _context.t3 = _context["catch"](61);
4226
4227
  _iterator3.e(_context.t3);
4227
- case 105:
4228
- _context.prev = 105;
4228
+ case 106:
4229
+ _context.prev = 106;
4229
4230
  _iterator3.f();
4230
- return _context.finish(105);
4231
- case 108:
4232
- return _context.abrupt("return", allDifferences);
4231
+ return _context.finish(106);
4233
4232
  case 109:
4233
+ return _context.abrupt("return", allDifferences);
4234
+ case 110:
4234
4235
  case "end":
4235
4236
  return _context.stop();
4236
4237
  }
4237
- }, _callee, null, [[18, 29, 32, 35], [38, 50, 53, 56], [60, 102, 105, 108], [70, 95]]);
4238
+ }, _callee, null, [[19, 30, 33, 36], [39, 51, 54, 57], [61, 103, 106, 109], [71, 96]]);
4238
4239
  }));
4239
4240
  return function compareAllDatabases(_x, _x2) {
4240
4241
  return _ref.apply(this, arguments);
@@ -4476,7 +4477,7 @@ var startApiServer = function startApiServer(port, argv) {
4476
4477
  _context6.prev = 4;
4477
4478
  console.log('Applying the database structure based on JSON dumps');
4478
4479
  _context6.next = 8;
4479
- return applyDifferences(checker.connection, database, diffs);
4480
+ return applyDifferences$1(checker.connection, database, diffs);
4480
4481
  case 8:
4481
4482
  res.json({
4482
4483
  message: 'Apply completed successfully'
@@ -5204,43 +5205,146 @@ var DBStructureChecker = /*#__PURE__*/function () {
5204
5205
  }]);
5205
5206
  }();
5206
5207
  var compare = /*#__PURE__*/function () {
5207
- var _ref = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee4(config, output) {
5208
- return _regeneratorRuntime().wrap(function _callee4$(_context4) {
5209
- while (1) switch (_context4.prev = _context4.next) {
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
+ case 0:
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) {
5210
5280
  case 0:
5211
- return _context4.abrupt("return", new Promise(function (resolve, reject) {
5281
+ return _context7.abrupt("return", new Promise(function (resolve, reject) {
5212
5282
  try {
5213
- var checker = new DBStructureChecker(config);
5214
- checker.connection.on('connect', /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee3() {
5215
- var diffs;
5216
- return _regeneratorRuntime().wrap(function _callee3$(_context3) {
5217
- while (1) switch (_context3.prev = _context3.next) {
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) {
5218
5294
  case 0:
5219
- _context3.next = 2;
5220
- return compareAllDatabases(checker.connection, output, false, 'compare', {
5221
- output: output
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'
5222
5311
  });
5223
- case 2:
5224
- diffs = _context3.sent;
5225
- resolve(diffs);
5226
- case 4:
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
5320
+ });
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:
5227
5328
  case "end":
5228
- return _context3.stop();
5329
+ return _context6.stop();
5229
5330
  }
5230
- }, _callee3);
5331
+ }, _callee6, null, [[4, 11, 14, 18]]);
5231
5332
  })));
5232
5333
  } catch (e) {
5233
- reject(e);
5334
+ reject({
5335
+ type: 'error',
5336
+ error: e.message
5337
+ });
5234
5338
  }
5235
5339
  }));
5236
5340
  case 1:
5237
5341
  case "end":
5238
- return _context4.stop();
5342
+ return _context7.stop();
5239
5343
  }
5240
- }, _callee4);
5344
+ }, _callee7);
5241
5345
  }));
5242
- return function compare(_x, _x2) {
5243
- return _ref.apply(this, arguments);
5346
+ return function apply(_x5, _x6, _x7) {
5347
+ return _ref4.apply(this, arguments);
5244
5348
  };
5245
5349
  }();
5246
5350
 
@@ -5256,15 +5360,15 @@ var isMain = function () {
5256
5360
  }
5257
5361
  }();
5258
5362
  if (isMain) {
5259
- _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee6() {
5260
- var _cli, command, config, argv, PORT, checker;
5261
- return _regeneratorRuntime().wrap(function _callee6$(_context6) {
5262
- while (1) switch (_context6.prev = _context6.next) {
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) {
5263
5367
  case 0:
5264
5368
  _cli = cli(), command = _cli.command, config = _cli.config, argv = _cli.argv;
5265
5369
  console.log("MySQLsyncr started via command line");
5266
5370
  if (!(command === 'ui')) {
5267
- _context6.next = 12;
5371
+ _context9.next = 12;
5268
5372
  break;
5269
5373
  }
5270
5374
  PORT = argv.uiPort;
@@ -5272,58 +5376,58 @@ if (isMain) {
5272
5376
  console.log('Server started on port', PORT);
5273
5377
  console.log('Open http://localhost:' + PORT + ' in your browser to use the UI');
5274
5378
  if (!(argv.openUI && argv.openUI === true || argv.openUI === 'true')) {
5275
- _context6.next = 10;
5379
+ _context9.next = 10;
5276
5380
  break;
5277
5381
  }
5278
- _context6.next = 10;
5382
+ _context9.next = 10;
5279
5383
  return open("http://localhost:".concat(PORT));
5280
5384
  case 10:
5281
- _context6.next = 14;
5385
+ _context9.next = 14;
5282
5386
  break;
5283
5387
  case 12:
5284
5388
  // Handle other commands (dump, compare, update) as before
5285
- checker = new DBStructureChecker(config, argv.database);
5286
- checker.connection.on('connect', /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee5() {
5389
+ _checker3 = new DBStructureChecker(config, argv.database);
5390
+ _checker3.connection.on('connect', /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee8() {
5287
5391
  var diffs, totalDiffs, _totalDiffs, previousDiffs, runCount, maxRuns, _diffs;
5288
- return _regeneratorRuntime().wrap(function _callee5$(_context5) {
5289
- while (1) switch (_context5.prev = _context5.next) {
5392
+ return _regeneratorRuntime().wrap(function _callee8$(_context8) {
5393
+ while (1) switch (_context8.prev = _context8.next) {
5290
5394
  case 0:
5291
5395
  console.log('Connected to the database');
5292
- checker.targetDatabase = argv.database;
5293
- checker.command = command;
5294
- checker.options = argv;
5295
- _context5.prev = 4;
5396
+ _checker3.targetDatabase = argv.database;
5397
+ _checker3.command = command;
5398
+ _checker3.options = argv;
5399
+ _context8.prev = 4;
5296
5400
  if (!(command === 'dump')) {
5297
- _context5.next = 11;
5401
+ _context8.next = 11;
5298
5402
  break;
5299
5403
  }
5300
5404
  console.log('Dumping the database structure to files');
5301
- _context5.next = 9;
5302
- return dumpAllDatabases(checker.connection, command, argv);
5405
+ _context8.next = 9;
5406
+ return dumpAllDatabases(_checker3.connection, command, argv);
5303
5407
  case 9:
5304
- _context5.next = 42;
5408
+ _context8.next = 42;
5305
5409
  break;
5306
5410
  case 11:
5307
5411
  if (!(command === 'compare')) {
5308
- _context5.next = 21;
5412
+ _context8.next = 21;
5309
5413
  break;
5310
5414
  }
5311
5415
  console.log('Comparing the database structure with JSON dumps (dry run)');
5312
- _context5.next = 15;
5313
- return compareAllDatabases(checker.connection, argv.output, false, command, argv);
5416
+ _context8.next = 15;
5417
+ return compareAllDatabases(_checker3.connection, argv.output, false, command, argv);
5314
5418
  case 15:
5315
- diffs = _context5.sent;
5419
+ diffs = _context8.sent;
5316
5420
  // Dry run
5317
5421
  totalDiffs = Object.values(diffs).reduce(function (acc, arr) {
5318
5422
  return acc + arr.length;
5319
5423
  }, 0);
5320
5424
  console.log('Total differences count:', totalDiffs);
5321
5425
  fs$3.writeFileSync(path.join(argv.output, 'diffs.json'), JSON.stringify(diffs, null, 4));
5322
- _context5.next = 42;
5426
+ _context8.next = 42;
5323
5427
  break;
5324
5428
  case 21:
5325
5429
  if (!(command === 'update')) {
5326
- _context5.next = 42;
5430
+ _context8.next = 42;
5327
5431
  break;
5328
5432
  }
5329
5433
  console.log('Updating the database structure based on JSON dumps');
@@ -5333,14 +5437,14 @@ if (isMain) {
5333
5437
  maxRuns = 6;
5334
5438
  case 27:
5335
5439
  if (!(runCount < maxRuns && _totalDiffs > 0 && (_totalDiffs < previousDiffs || previousDiffs === Infinity))) {
5336
- _context5.next = 42;
5440
+ _context8.next = 42;
5337
5441
  break;
5338
5442
  }
5339
5443
  console.log('Running update command. Run count:', runCount);
5340
- _context5.next = 31;
5341
- return compareAllDatabases(checker.connection, argv.output, true, command, argv);
5444
+ _context8.next = 31;
5445
+ return compareAllDatabases(_checker3.connection, argv.output, true, command, argv);
5342
5446
  case 31:
5343
- _diffs = _context5.sent;
5447
+ _diffs = _context8.sent;
5344
5448
  // Apply updates
5345
5449
  previousDiffs = _totalDiffs; // Update previous differences
5346
5450
  _totalDiffs = Object.values(_diffs).reduce(function (acc, arr) {
@@ -5349,42 +5453,42 @@ if (isMain) {
5349
5453
  console.log('Total differences count:', _totalDiffs);
5350
5454
  runCount++;
5351
5455
  if (!(_totalDiffs > 0 && runCount < maxRuns)) {
5352
- _context5.next = 40;
5456
+ _context8.next = 40;
5353
5457
  break;
5354
5458
  }
5355
5459
  console.log('Total differences count is still greater than 0. Waiting 1 second before next run. Run count:', runCount);
5356
- _context5.next = 40;
5460
+ _context8.next = 40;
5357
5461
  return new Promise(function (resolve) {
5358
5462
  return setTimeout(resolve, 1000);
5359
5463
  });
5360
5464
  case 40:
5361
- _context5.next = 27;
5465
+ _context8.next = 27;
5362
5466
  break;
5363
5467
  case 42:
5364
- _context5.next = 47;
5468
+ _context8.next = 47;
5365
5469
  break;
5366
5470
  case 44:
5367
- _context5.prev = 44;
5368
- _context5.t0 = _context5["catch"](4);
5369
- console.error(_context5.t0.message);
5471
+ _context8.prev = 44;
5472
+ _context8.t0 = _context8["catch"](4);
5473
+ console.error(_context8.t0.message);
5370
5474
  case 47:
5371
- _context5.prev = 47;
5372
- _context5.next = 50;
5373
- return checker.closeConnection();
5475
+ _context8.prev = 47;
5476
+ _context8.next = 50;
5477
+ return _checker3.closeConnection();
5374
5478
  case 50:
5375
- return _context5.finish(47);
5479
+ return _context8.finish(47);
5376
5480
  case 51:
5377
5481
  case "end":
5378
- return _context5.stop();
5482
+ return _context8.stop();
5379
5483
  }
5380
- }, _callee5, null, [[4, 44, 47, 51]]);
5484
+ }, _callee8, null, [[4, 44, 47, 51]]);
5381
5485
  })));
5382
5486
  case 14:
5383
5487
  case "end":
5384
- return _context6.stop();
5488
+ return _context9.stop();
5385
5489
  }
5386
- }, _callee6);
5490
+ }, _callee9);
5387
5491
  }))();
5388
5492
  }
5389
5493
 
5390
- export { DBStructureChecker, compare, dumpAllDatabases, startApiServer };
5494
+ export { DBStructureChecker, apply, compare, dumpAllDatabases, startApiServer };