mysqlsyncr 1.0.56 → 1.0.58

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/getters.js DELETED
@@ -1,333 +0,0 @@
1
- "use strict";
2
-
3
- function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
4
- Object.defineProperty(exports, "__esModule", {
5
- value: true
6
- });
7
- exports.getDatabases = exports.getDatabaseStructure = void 0;
8
- var _parsers = require("./parsers.js");
9
- var _path = _interopRequireDefault(require("path"));
10
- var _promises = _interopRequireDefault(require("fs/promises"));
11
- var _loggers = require("./loggers.js");
12
- function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
13
- function _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: !0 } : { done: !1, value: r[_n++] }; }, e: function e(r) { throw r; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t["return"] || t["return"](); } finally { if (u) throw o; } } }; }
14
- function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
15
- function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
16
- function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return e; }; var t, e = {}, r = Object.prototype, n = r.hasOwnProperty, o = Object.defineProperty || function (t, e, r) { t[e] = r.value; }, i = "function" == typeof Symbol ? Symbol : {}, a = i.iterator || "@@iterator", c = i.asyncIterator || "@@asyncIterator", u = i.toStringTag || "@@toStringTag"; function define(t, e, r) { return Object.defineProperty(t, e, { value: r, enumerable: !0, configurable: !0, writable: !0 }), t[e]; } try { define({}, ""); } catch (t) { define = function define(t, e, r) { return t[e] = r; }; } function wrap(t, e, r, n) { var i = e && e.prototype instanceof Generator ? e : Generator, a = Object.create(i.prototype), c = new Context(n || []); return o(a, "_invoke", { value: makeInvokeMethod(t, r, c) }), a; } function tryCatch(t, e, r) { try { return { type: "normal", arg: t.call(e, r) }; } catch (t) { return { type: "throw", arg: t }; } } e.wrap = wrap; var h = "suspendedStart", l = "suspendedYield", f = "executing", s = "completed", y = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var p = {}; define(p, a, function () { return this; }); var d = Object.getPrototypeOf, v = d && d(d(values([]))); v && v !== r && n.call(v, a) && (p = v); var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p); function defineIteratorMethods(t) { ["next", "throw", "return"].forEach(function (e) { define(t, e, function (t) { return this._invoke(e, t); }); }); } function AsyncIterator(t, e) { function invoke(r, o, i, a) { var c = tryCatch(t[r], t, o); if ("throw" !== c.type) { var u = c.arg, h = u.value; return h && "object" == _typeof(h) && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) { invoke("next", t, i, a); }, function (t) { invoke("throw", t, i, a); }) : e.resolve(h).then(function (t) { u.value = t, i(u); }, function (t) { return invoke("throw", t, i, a); }); } a(c.arg); } var r; o(this, "_invoke", { value: function value(t, n) { function callInvokeWithMethodAndArg() { return new e(function (e, r) { invoke(t, n, e, r); }); } return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(e, r, n) { var o = h; return function (i, a) { if (o === f) throw Error("Generator is already running"); if (o === s) { if ("throw" === i) throw a; return { value: t, done: !0 }; } for (n.method = i, n.arg = a;;) { var c = n.delegate; if (c) { var u = maybeInvokeDelegate(c, n); if (u) { if (u === y) continue; return u; } } if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) { if (o === h) throw o = s, n.arg; n.dispatchException(n.arg); } else "return" === n.method && n.abrupt("return", n.arg); o = f; var p = tryCatch(e, r, n); if ("normal" === p.type) { if (o = n.done ? s : l, p.arg === y) continue; return { value: p.arg, done: n.done }; } "throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg); } }; } function maybeInvokeDelegate(e, r) { var n = r.method, o = e.iterator[n]; if (o === t) return r.delegate = null, "throw" === n && e.iterator["return"] && (r.method = "return", r.arg = t, maybeInvokeDelegate(e, r), "throw" === r.method) || "return" !== n && (r.method = "throw", r.arg = new TypeError("The iterator does not provide a '" + n + "' method")), y; var i = tryCatch(o, e.iterator, r.arg); if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y; var a = i.arg; return a ? a.done ? (r[e.resultName] = a.value, r.next = e.nextLoc, "return" !== r.method && (r.method = "next", r.arg = t), r.delegate = null, y) : a : (r.method = "throw", r.arg = new TypeError("iterator result is not an object"), r.delegate = null, y); } function pushTryEntry(t) { var e = { tryLoc: t[0] }; 1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e); } function resetTryEntry(t) { var e = t.completion || {}; e.type = "normal", delete e.arg, t.completion = e; } function Context(t) { this.tryEntries = [{ tryLoc: "root" }], t.forEach(pushTryEntry, this), this.reset(!0); } function values(e) { if (e || "" === e) { var r = e[a]; if (r) return r.call(e); if ("function" == typeof e.next) return e; if (!isNaN(e.length)) { var o = -1, i = function next() { for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next; return next.value = t, next.done = !0, next; }; return i.next = i; } } throw new TypeError(_typeof(e) + " is not iterable"); } return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), o(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) { var e = "function" == typeof t && t.constructor; return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name)); }, e.mark = function (t) { return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t; }, e.awrap = function (t) { return { __await: t }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () { return this; }), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) { void 0 === i && (i = Promise); var a = new AsyncIterator(wrap(t, r, n, o), i); return e.isGeneratorFunction(r) ? a : a.next().then(function (t) { return t.done ? t.value : a.next(); }); }, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () { return this; }), define(g, "toString", function () { return "[object Generator]"; }), e.keys = function (t) { var e = Object(t), r = []; for (var n in e) r.push(n); return r.reverse(), function next() { for (; r.length;) { var t = r.pop(); if (t in e) return next.value = t, next.done = !1, next; } return next.done = !0, next; }; }, e.values = values, Context.prototype = { constructor: Context, reset: function reset(e) { if (this.prev = 0, this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(resetTryEntry), !e) for (var r in this) "t" === r.charAt(0) && n.call(this, r) && !isNaN(+r.slice(1)) && (this[r] = t); }, stop: function stop() { this.done = !0; var t = this.tryEntries[0].completion; if ("throw" === t.type) throw t.arg; return this.rval; }, dispatchException: function dispatchException(e) { if (this.done) throw e; var r = this; function handle(n, o) { return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o; } for (var o = this.tryEntries.length - 1; o >= 0; --o) { var i = this.tryEntries[o], a = i.completion; if ("root" === i.tryLoc) return handle("end"); if (i.tryLoc <= this.prev) { var c = n.call(i, "catchLoc"), u = n.call(i, "finallyLoc"); if (c && u) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } else if (c) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); } else { if (!u) throw Error("try statement without catch or finally"); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } } } }, abrupt: function abrupt(t, e) { for (var r = this.tryEntries.length - 1; r >= 0; --r) { var o = this.tryEntries[r]; if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) { var i = o; break; } } i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null); var a = i ? i.completion : {}; return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a); }, complete: function complete(t, e) { if ("throw" === t.type) throw t.arg; return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && e && (this.next = e), y; }, finish: function finish(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y; } }, "catch": function _catch(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.tryLoc === t) { var n = r.completion; if ("throw" === n.type) { var o = n.arg; resetTryEntry(r); } return o; } } throw Error("illegal catch attempt"); }, delegateYield: function delegateYield(e, r, n) { return this.delegate = { iterator: values(e), resultName: r, nextLoc: n }, "next" === this.method && (this.arg = t), y; } }, e; }
17
- function asyncGeneratorStep(n, t, e, r, o, a, c) { try { var i = n[a](c), u = i.value; } catch (n) { return void e(n); } i.done ? t(u) : Promise.resolve(u).then(r, o); }
18
- function _asyncToGenerator(n) { return function () { var t = this, e = arguments; return new Promise(function (r, o) { var a = n.apply(t, e); function _next(n) { asyncGeneratorStep(a, r, o, _next, _throw, "next", n); } function _throw(n) { asyncGeneratorStep(a, r, o, _next, _throw, "throw", n); } _next(void 0); }); }; }
19
- var getDatabases = exports.getDatabases = /*#__PURE__*/function () {
20
- var _ref = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(connection) {
21
- var databases;
22
- return _regeneratorRuntime().wrap(function _callee$(_context) {
23
- while (1) switch (_context.prev = _context.next) {
24
- case 0:
25
- _context.next = 2;
26
- return connection.query('SHOW DATABASES');
27
- case 2:
28
- databases = _context.sent;
29
- return _context.abrupt("return", databases.map(function (db) {
30
- return db.Database;
31
- }).filter(function (db) {
32
- return !['information_schema', 'mysql', 'performance_schema', 'sys'].includes(db);
33
- }));
34
- case 4:
35
- case "end":
36
- return _context.stop();
37
- }
38
- }, _callee);
39
- }));
40
- return function getDatabases(_x) {
41
- return _ref.apply(this, arguments);
42
- };
43
- }();
44
- var getDatabaseStructure = exports.getDatabaseStructure = /*#__PURE__*/function () {
45
- var _ref2 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee2(connection, database, command, options) {
46
- var tables, procedures, views, dbDir, tableDir, tableRows, _iterator, _step, row, tableName, createTableRow, createTableSQL, parsedTable, _tableDir, filePath, routineRows, _iterator2, _step2, _row, createSQLrow, createSQL, _filePath, triggerRows, _iterator3, _step3, _row2, triggerName, _tableName, triggerDefinitionRow, triggerDefinition, _tableDir2, triggerFilePath, viewRows, _iterator4, _step4, _row3, viewName, viewDefinition, _filePath2;
47
- return _regeneratorRuntime().wrap(function _callee2$(_context2) {
48
- while (1) switch (_context2.prev = _context2.next) {
49
- case 0:
50
- if (!(connection.state === 'disconnected')) {
51
- _context2.next = 3;
52
- break;
53
- }
54
- _context2.next = 3;
55
- return connection.reconnect();
56
- case 3:
57
- _context2.next = 5;
58
- return connection.query("USE `".concat(database, "`"));
59
- case 5:
60
- // Switch to the target database
61
- tables = {};
62
- procedures = [];
63
- views = {};
64
- dbDir = _path["default"].join(options.output, database); // Use argv.output for the base path
65
- // Create the output directory for the database if it doesn't exist
66
- if (!(command === 'dump')) {
67
- _context2.next = 13;
68
- break;
69
- }
70
- tableDir = _path["default"].join(dbDir, 'tables'); // Subfolder for table SQL files
71
- _context2.next = 13;
72
- return _promises["default"].mkdir(tableDir, {
73
- recursive: true
74
- });
75
- case 13:
76
- _context2.next = 15;
77
- return connection.query('SHOW FULL TABLES WHERE Table_Type != "VIEW"');
78
- case 15:
79
- tableRows = _context2.sent;
80
- _iterator = _createForOfIteratorHelper(tableRows);
81
- _context2.prev = 17;
82
- _iterator.s();
83
- case 19:
84
- if ((_step = _iterator.n()).done) {
85
- _context2.next = 41;
86
- break;
87
- }
88
- row = _step.value;
89
- tableName = Object.values(row)[0]; // Get the first value in the row object
90
- if (tableName) {
91
- _context2.next = 25;
92
- break;
93
- }
94
- (0, _loggers.logger)("Undefined table name found in database ".concat(database), row);
95
- return _context2.abrupt("continue", 39);
96
- case 25:
97
- _context2.next = 27;
98
- return connection.query("SHOW CREATE TABLE `".concat(tableName, "`"));
99
- case 27:
100
- createTableRow = _context2.sent;
101
- createTableSQL = createTableRow[0]['Create Table'];
102
- parsedTable = (0, _parsers.parseCreateTableSQL)(createTableSQL); // Structure the table object
103
- tables[tableName] = {
104
- columns: parsedTable.columns,
105
- // Array of columns
106
- indexes: parsedTable.indexes,
107
- // Array of indexes
108
- constraints: parsedTable.constraints,
109
- // Array of constraints
110
- triggers: [],
111
- // Initialize triggers array
112
- createSQL: createTableSQL // Store the CREATE TABLE SQL if needed
113
- };
114
-
115
- // Save the CREATE TABLE statement to an individual SQL file for each table
116
- if (!(command === 'dump')) {
117
- _context2.next = 39;
118
- break;
119
- }
120
- _tableDir = _path["default"].join(dbDir, 'tables'); // Subfolder for table SQL files
121
- filePath = _path["default"].join(_tableDir, "".concat(tableName, ".sql")); // Use the table directory for file saving
122
- _context2.next = 36;
123
- return _promises["default"].mkdir(_path["default"].dirname(filePath), {
124
- recursive: true
125
- });
126
- case 36:
127
- _context2.next = 38;
128
- return _promises["default"].writeFile(filePath, "".concat(createTableSQL, "\n"), 'utf-8');
129
- case 38:
130
- (0, _loggers.logger)("Table structure saved to: ".concat(filePath));
131
- case 39:
132
- _context2.next = 19;
133
- break;
134
- case 41:
135
- _context2.next = 46;
136
- break;
137
- case 43:
138
- _context2.prev = 43;
139
- _context2.t0 = _context2["catch"](17);
140
- _iterator.e(_context2.t0);
141
- case 46:
142
- _context2.prev = 46;
143
- _iterator.f();
144
- return _context2.finish(46);
145
- case 49:
146
- _context2.next = 51;
147
- return connection.query("SHOW PROCEDURE STATUS WHERE Db = ?", [database]);
148
- case 51:
149
- routineRows = _context2.sent;
150
- _iterator2 = _createForOfIteratorHelper(routineRows);
151
- _context2.prev = 53;
152
- _iterator2.s();
153
- case 55:
154
- if ((_step2 = _iterator2.n()).done) {
155
- _context2.next = 71;
156
- break;
157
- }
158
- _row = _step2.value;
159
- _context2.next = 59;
160
- return connection.query("SHOW CREATE PROCEDURE `".concat(_row.Name, "`"));
161
- case 59:
162
- createSQLrow = _context2.sent;
163
- createSQL = createSQLrow[0]['Create Procedure'];
164
- procedures.push({
165
- Name: _row.Name,
166
- Definition: createSQL
167
- }); // Add procedure names to the array
168
- if (!(command === 'dump')) {
169
- _context2.next = 69;
170
- break;
171
- }
172
- _filePath = _path["default"].join(dbDir, 'procedures', "".concat(_row.Name, ".sql")); // Use the table directory for file saving
173
- _context2.next = 66;
174
- return _promises["default"].mkdir(_path["default"].dirname(_filePath), {
175
- recursive: true
176
- });
177
- case 66:
178
- _context2.next = 68;
179
- return _promises["default"].writeFile(_filePath, "".concat(createSQL, "\n"), 'utf-8');
180
- case 68:
181
- (0, _loggers.logger)("Procedure definition saved to: ".concat(_filePath));
182
- case 69:
183
- _context2.next = 55;
184
- break;
185
- case 71:
186
- _context2.next = 76;
187
- break;
188
- case 73:
189
- _context2.prev = 73;
190
- _context2.t1 = _context2["catch"](53);
191
- _iterator2.e(_context2.t1);
192
- case 76:
193
- _context2.prev = 76;
194
- _iterator2.f();
195
- return _context2.finish(76);
196
- case 79:
197
- _context2.next = 81;
198
- return connection.query("\n SELECT TRIGGER_NAME, EVENT_OBJECT_TABLE\n FROM INFORMATION_SCHEMA.TRIGGERS\n WHERE TRIGGER_SCHEMA = ?\n ", [database]);
199
- case 81:
200
- triggerRows = _context2.sent;
201
- _iterator3 = _createForOfIteratorHelper(triggerRows);
202
- _context2.prev = 83;
203
- _iterator3.s();
204
- case 85:
205
- if ((_step3 = _iterator3.n()).done) {
206
- _context2.next = 108;
207
- break;
208
- }
209
- _row2 = _step3.value;
210
- triggerName = _row2.TRIGGER_NAME;
211
- _tableName = _row2.EVENT_OBJECT_TABLE; // Ensure triggerDefinition is defined before using it
212
- _context2.next = 91;
213
- return connection.query("SHOW CREATE TRIGGER `".concat(triggerName, "`"));
214
- case 91:
215
- triggerDefinitionRow = _context2.sent;
216
- triggerDefinition = triggerDefinitionRow[0]['SQL Original Statement'];
217
- if (!triggerDefinition) {
218
- _context2.next = 105;
219
- break;
220
- }
221
- tables[_tableName].triggers.push({
222
- Name: triggerName,
223
- Definition: triggerDefinition
224
- });
225
- if (!(command === 'dump')) {
226
- _context2.next = 103;
227
- break;
228
- }
229
- _tableDir2 = _path["default"].join(dbDir, 'tables'); // Subfolder for table SQL files
230
- triggerFilePath = _path["default"].join(_tableDir2, 'triggers', "".concat(triggerName, ".sql"));
231
- _context2.next = 100;
232
- return _promises["default"].mkdir(_path["default"].dirname(triggerFilePath), {
233
- recursive: true
234
- });
235
- case 100:
236
- _context2.next = 102;
237
- return _promises["default"].writeFile(triggerFilePath, "".concat(triggerDefinition, "\n"), 'utf-8');
238
- case 102:
239
- (0, _loggers.logger)("Trigger definition saved to: ".concat(triggerFilePath));
240
- case 103:
241
- _context2.next = 106;
242
- break;
243
- case 105:
244
- console.warn("Trigger ".concat(triggerName, " has no action statement."));
245
- case 106:
246
- _context2.next = 85;
247
- break;
248
- case 108:
249
- _context2.next = 113;
250
- break;
251
- case 110:
252
- _context2.prev = 110;
253
- _context2.t2 = _context2["catch"](83);
254
- _iterator3.e(_context2.t2);
255
- case 113:
256
- _context2.prev = 113;
257
- _iterator3.f();
258
- return _context2.finish(113);
259
- case 116:
260
- _context2.next = 118;
261
- return connection.query("SHOW FULL TABLES IN `".concat(database, "` WHERE TABLE_TYPE LIKE 'VIEW'"));
262
- case 118:
263
- viewRows = _context2.sent;
264
- _iterator4 = _createForOfIteratorHelper(viewRows);
265
- _context2.prev = 120;
266
- _iterator4.s();
267
- case 122:
268
- if ((_step4 = _iterator4.n()).done) {
269
- _context2.next = 147;
270
- break;
271
- }
272
- _row3 = _step4.value;
273
- viewName = _row3["Tables_in_".concat(database.toLowerCase())];
274
- if (!viewName) viewName = _row3["Tables_in_".concat(database)];
275
- (0, _loggers.logger)("getting view Tables_in_".concat(database), viewName);
276
- _context2.prev = 127;
277
- _context2.next = 130;
278
- return connection.query("SHOW CREATE VIEW `".concat(viewName, "`"));
279
- case 130:
280
- viewDefinition = _context2.sent;
281
- views[viewName] = viewDefinition[0]['Create View'];
282
- if (!(command === 'dump')) {
283
- _context2.next = 139;
284
- break;
285
- }
286
- _filePath2 = _path["default"].join(dbDir, 'views', "".concat(viewName, ".sql")); // Use the table directory for file saving
287
- _context2.next = 136;
288
- return _promises["default"].mkdir(_path["default"].dirname(_filePath2), {
289
- recursive: true
290
- });
291
- case 136:
292
- _context2.next = 138;
293
- return _promises["default"].writeFile(_filePath2, "".concat(viewDefinition[0]['Create View'], "\n"), 'utf-8');
294
- case 138:
295
- (0, _loggers.logger)("View definition saved to: ".concat(_filePath2));
296
- case 139:
297
- _context2.next = 145;
298
- break;
299
- case 141:
300
- _context2.prev = 141;
301
- _context2.t3 = _context2["catch"](127);
302
- (0, _loggers.logger)("Error retrieving definition for view ".concat(viewName, ":"), _context2.t3.message);
303
- (0, _loggers.logger)(_row3);
304
- case 145:
305
- _context2.next = 122;
306
- break;
307
- case 147:
308
- _context2.next = 152;
309
- break;
310
- case 149:
311
- _context2.prev = 149;
312
- _context2.t4 = _context2["catch"](120);
313
- _iterator4.e(_context2.t4);
314
- case 152:
315
- _context2.prev = 152;
316
- _iterator4.f();
317
- return _context2.finish(152);
318
- case 155:
319
- return _context2.abrupt("return", {
320
- tables: tables,
321
- procedures: procedures,
322
- views: views
323
- });
324
- case 156:
325
- case "end":
326
- return _context2.stop();
327
- }
328
- }, _callee2, null, [[17, 43, 46, 49], [53, 73, 76, 79], [83, 110, 113, 116], [120, 149, 152, 155], [127, 141]]);
329
- }));
330
- return function getDatabaseStructure(_x2, _x3, _x4, _x5) {
331
- return _ref2.apply(this, arguments);
332
- };
333
- }();
package/dist/index.js DELETED
@@ -1,284 +0,0 @@
1
- #!/usr/bin/env node
2
- "use strict";
3
-
4
- Object.defineProperty(exports, "__esModule", {
5
- value: true
6
- });
7
- exports.compare = exports.DBStructureChecker = void 0;
8
- Object.defineProperty(exports, "dumpAllDatabases", {
9
- enumerable: true,
10
- get: function get() {
11
- return _dump.dumpAllDatabases;
12
- }
13
- });
14
- Object.defineProperty(exports, "startApiServer", {
15
- enumerable: true,
16
- get: function get() {
17
- return _socketServer.startApiServer;
18
- }
19
- });
20
- var _mysql = _interopRequireDefault(require("mysql2"));
21
- var _util = _interopRequireDefault(require("util"));
22
- var _fs = _interopRequireDefault(require("fs"));
23
- var _path = _interopRequireDefault(require("path"));
24
- var _cli2 = require("./cli.js");
25
- var _dump = require("./dump.js");
26
- var _compare = require("./compare.js");
27
- var _socketServer = require("./socketServer.js");
28
- var _open = _interopRequireDefault(require("open"));
29
- var _nodeUrl = require("node:url");
30
- function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
31
- function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
32
- function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return e; }; var t, e = {}, r = Object.prototype, n = r.hasOwnProperty, o = Object.defineProperty || function (t, e, r) { t[e] = r.value; }, i = "function" == typeof Symbol ? Symbol : {}, a = i.iterator || "@@iterator", c = i.asyncIterator || "@@asyncIterator", u = i.toStringTag || "@@toStringTag"; function define(t, e, r) { return Object.defineProperty(t, e, { value: r, enumerable: !0, configurable: !0, writable: !0 }), t[e]; } try { define({}, ""); } catch (t) { define = function define(t, e, r) { return t[e] = r; }; } function wrap(t, e, r, n) { var i = e && e.prototype instanceof Generator ? e : Generator, a = Object.create(i.prototype), c = new Context(n || []); return o(a, "_invoke", { value: makeInvokeMethod(t, r, c) }), a; } function tryCatch(t, e, r) { try { return { type: "normal", arg: t.call(e, r) }; } catch (t) { return { type: "throw", arg: t }; } } e.wrap = wrap; var h = "suspendedStart", l = "suspendedYield", f = "executing", s = "completed", y = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var p = {}; define(p, a, function () { return this; }); var d = Object.getPrototypeOf, v = d && d(d(values([]))); v && v !== r && n.call(v, a) && (p = v); var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p); function defineIteratorMethods(t) { ["next", "throw", "return"].forEach(function (e) { define(t, e, function (t) { return this._invoke(e, t); }); }); } function AsyncIterator(t, e) { function invoke(r, o, i, a) { var c = tryCatch(t[r], t, o); if ("throw" !== c.type) { var u = c.arg, h = u.value; return h && "object" == _typeof(h) && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) { invoke("next", t, i, a); }, function (t) { invoke("throw", t, i, a); }) : e.resolve(h).then(function (t) { u.value = t, i(u); }, function (t) { return invoke("throw", t, i, a); }); } a(c.arg); } var r; o(this, "_invoke", { value: function value(t, n) { function callInvokeWithMethodAndArg() { return new e(function (e, r) { invoke(t, n, e, r); }); } return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(e, r, n) { var o = h; return function (i, a) { if (o === f) throw Error("Generator is already running"); if (o === s) { if ("throw" === i) throw a; return { value: t, done: !0 }; } for (n.method = i, n.arg = a;;) { var c = n.delegate; if (c) { var u = maybeInvokeDelegate(c, n); if (u) { if (u === y) continue; return u; } } if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) { if (o === h) throw o = s, n.arg; n.dispatchException(n.arg); } else "return" === n.method && n.abrupt("return", n.arg); o = f; var p = tryCatch(e, r, n); if ("normal" === p.type) { if (o = n.done ? s : l, p.arg === y) continue; return { value: p.arg, done: n.done }; } "throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg); } }; } function maybeInvokeDelegate(e, r) { var n = r.method, o = e.iterator[n]; if (o === t) return r.delegate = null, "throw" === n && e.iterator["return"] && (r.method = "return", r.arg = t, maybeInvokeDelegate(e, r), "throw" === r.method) || "return" !== n && (r.method = "throw", r.arg = new TypeError("The iterator does not provide a '" + n + "' method")), y; var i = tryCatch(o, e.iterator, r.arg); if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y; var a = i.arg; return a ? a.done ? (r[e.resultName] = a.value, r.next = e.nextLoc, "return" !== r.method && (r.method = "next", r.arg = t), r.delegate = null, y) : a : (r.method = "throw", r.arg = new TypeError("iterator result is not an object"), r.delegate = null, y); } function pushTryEntry(t) { var e = { tryLoc: t[0] }; 1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e); } function resetTryEntry(t) { var e = t.completion || {}; e.type = "normal", delete e.arg, t.completion = e; } function Context(t) { this.tryEntries = [{ tryLoc: "root" }], t.forEach(pushTryEntry, this), this.reset(!0); } function values(e) { if (e || "" === e) { var r = e[a]; if (r) return r.call(e); if ("function" == typeof e.next) return e; if (!isNaN(e.length)) { var o = -1, i = function next() { for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next; return next.value = t, next.done = !0, next; }; return i.next = i; } } throw new TypeError(_typeof(e) + " is not iterable"); } return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), o(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) { var e = "function" == typeof t && t.constructor; return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name)); }, e.mark = function (t) { return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t; }, e.awrap = function (t) { return { __await: t }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () { return this; }), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) { void 0 === i && (i = Promise); var a = new AsyncIterator(wrap(t, r, n, o), i); return e.isGeneratorFunction(r) ? a : a.next().then(function (t) { return t.done ? t.value : a.next(); }); }, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () { return this; }), define(g, "toString", function () { return "[object Generator]"; }), e.keys = function (t) { var e = Object(t), r = []; for (var n in e) r.push(n); return r.reverse(), function next() { for (; r.length;) { var t = r.pop(); if (t in e) return next.value = t, next.done = !1, next; } return next.done = !0, next; }; }, e.values = values, Context.prototype = { constructor: Context, reset: function reset(e) { if (this.prev = 0, this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(resetTryEntry), !e) for (var r in this) "t" === r.charAt(0) && n.call(this, r) && !isNaN(+r.slice(1)) && (this[r] = t); }, stop: function stop() { this.done = !0; var t = this.tryEntries[0].completion; if ("throw" === t.type) throw t.arg; return this.rval; }, dispatchException: function dispatchException(e) { if (this.done) throw e; var r = this; function handle(n, o) { return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o; } for (var o = this.tryEntries.length - 1; o >= 0; --o) { var i = this.tryEntries[o], a = i.completion; if ("root" === i.tryLoc) return handle("end"); if (i.tryLoc <= this.prev) { var c = n.call(i, "catchLoc"), u = n.call(i, "finallyLoc"); if (c && u) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } else if (c) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); } else { if (!u) throw Error("try statement without catch or finally"); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } } } }, abrupt: function abrupt(t, e) { for (var r = this.tryEntries.length - 1; r >= 0; --r) { var o = this.tryEntries[r]; if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) { var i = o; break; } } i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null); var a = i ? i.completion : {}; return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a); }, complete: function complete(t, e) { if ("throw" === t.type) throw t.arg; return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && e && (this.next = e), y; }, finish: function finish(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y; } }, "catch": function _catch(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.tryLoc === t) { var n = r.completion; if ("throw" === n.type) { var o = n.arg; resetTryEntry(r); } return o; } } throw Error("illegal catch attempt"); }, delegateYield: function delegateYield(e, r, n) { return this.delegate = { iterator: values(e), resultName: r, nextLoc: n }, "next" === this.method && (this.arg = t), y; } }, e; }
33
- function asyncGeneratorStep(n, t, e, r, o, a, c) { try { var i = n[a](c), u = i.value; } catch (n) { return void e(n); } i.done ? t(u) : Promise.resolve(u).then(r, o); }
34
- function _asyncToGenerator(n) { return function () { var t = this, e = arguments; return new Promise(function (r, o) { var a = n.apply(t, e); function _next(n) { asyncGeneratorStep(a, r, o, _next, _throw, "next", n); } function _throw(n) { asyncGeneratorStep(a, r, o, _next, _throw, "throw", n); } _next(void 0); }); }; }
35
- function _classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); }
36
- function _defineProperties(e, r) { for (var t = 0; t < r.length; t++) { var o = r[t]; o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o); } }
37
- function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; }
38
- function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
39
- function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); } // Import the new socket server
40
- var DBStructureChecker = exports.DBStructureChecker = /*#__PURE__*/function () {
41
- function DBStructureChecker(config) {
42
- var targetDatabase = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
43
- _classCallCheck(this, DBStructureChecker);
44
- this.config = config;
45
- this.targetDatabase = targetDatabase;
46
- this.connection = _mysql["default"].createConnection(this.config);
47
- this.dumpAllDatabases = _dump.dumpAllDatabases;
48
- this.compareAllDatabases = _compare.compareAllDatabases;
49
- this.getDatabases = function () {
50
- _fs["default"].readFileSync(_path["default"].join(__dirname, 'databases.json'), 'utf8');
51
- };
52
- // this.connection.on('error', (err) => {
53
- // this.emit('error', err);
54
- // console.error('Database connection error:', err);
55
- // });
56
- this.connection.query = _util["default"].promisify(this.connection.query); // Promisify for async/await
57
- }
58
- return _createClass(DBStructureChecker, [{
59
- key: "reconnect",
60
- value: function () {
61
- var _reconnect = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
62
- return _regeneratorRuntime().wrap(function _callee$(_context) {
63
- while (1) switch (_context.prev = _context.next) {
64
- case 0:
65
- this.connection = _mysql["default"].createConnection(this.config);
66
- this.connection.query = _util["default"].promisify(this.connection.query); // Promisify for async/await
67
- _context.next = 4;
68
- return this.connection.connect();
69
- case 4:
70
- case "end":
71
- return _context.stop();
72
- }
73
- }, _callee, this);
74
- }));
75
- function reconnect() {
76
- return _reconnect.apply(this, arguments);
77
- }
78
- return reconnect;
79
- }()
80
- }, {
81
- key: "closeConnection",
82
- value: function () {
83
- var _closeConnection = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
84
- return _regeneratorRuntime().wrap(function _callee2$(_context2) {
85
- while (1) switch (_context2.prev = _context2.next) {
86
- case 0:
87
- if (!(this.connection.state !== 'disconnected')) {
88
- _context2.next = 3;
89
- break;
90
- }
91
- _context2.next = 3;
92
- return this.connection.end();
93
- case 3:
94
- case "end":
95
- return _context2.stop();
96
- }
97
- }, _callee2, this);
98
- }));
99
- function closeConnection() {
100
- return _closeConnection.apply(this, arguments);
101
- }
102
- return closeConnection;
103
- }()
104
- }]);
105
- }();
106
- var compare = exports.compare = /*#__PURE__*/function () {
107
- var _ref = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee4(config, output) {
108
- return _regeneratorRuntime().wrap(function _callee4$(_context4) {
109
- while (1) switch (_context4.prev = _context4.next) {
110
- case 0:
111
- return _context4.abrupt("return", new Promise(function (resolve, reject) {
112
- try {
113
- var checker = new DBStructureChecker(config);
114
- checker.connection.on('connect', /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee3() {
115
- var diffs;
116
- return _regeneratorRuntime().wrap(function _callee3$(_context3) {
117
- while (1) switch (_context3.prev = _context3.next) {
118
- case 0:
119
- _context3.next = 2;
120
- return (0, _compare.compareAllDatabases)(checker.connection, output, false, 'compare', {
121
- output: output
122
- });
123
- case 2:
124
- diffs = _context3.sent;
125
- resolve(diffs);
126
- case 4:
127
- case "end":
128
- return _context3.stop();
129
- }
130
- }, _callee3);
131
- })));
132
- } catch (e) {
133
- reject(e);
134
- }
135
- }));
136
- case 1:
137
- case "end":
138
- return _context4.stop();
139
- }
140
- }, _callee4);
141
- }));
142
- return function compare(_x, _x2) {
143
- return _ref.apply(this, arguments);
144
- };
145
- }();
146
- // Only run this if this is the main module
147
- var isMain = function () {
148
- try {
149
- return require.main === module;
150
- } catch (e) {
151
- return false;
152
- }
153
- }();
154
- if (isMain) {
155
- _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee6() {
156
- var _cli, command, config, argv, PORT, checker;
157
- return _regeneratorRuntime().wrap(function _callee6$(_context6) {
158
- while (1) switch (_context6.prev = _context6.next) {
159
- case 0:
160
- _cli = (0, _cli2.cli)(), command = _cli.command, config = _cli.config, argv = _cli.argv;
161
- console.log("MySQLsyncr started via command line");
162
- if (!(command === 'ui')) {
163
- _context6.next = 12;
164
- break;
165
- }
166
- PORT = argv.uiPort;
167
- (0, _socketServer.startApiServer)(PORT, argv); // Start the Socket.IO server
168
- console.log('Server started on port', PORT);
169
- console.log('Open http://localhost:' + PORT + ' in your browser to use the UI');
170
- if (!(argv.openUI && argv.openUI === true || argv.openUI === 'true')) {
171
- _context6.next = 10;
172
- break;
173
- }
174
- _context6.next = 10;
175
- return (0, _open["default"])("http://localhost:".concat(PORT));
176
- case 10:
177
- _context6.next = 14;
178
- break;
179
- case 12:
180
- // Handle other commands (dump, compare, update) as before
181
- checker = new DBStructureChecker(config, argv.database);
182
- checker.connection.on('connect', /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee5() {
183
- var diffs, totalDiffs, _totalDiffs, previousDiffs, runCount, maxRuns, _diffs;
184
- return _regeneratorRuntime().wrap(function _callee5$(_context5) {
185
- while (1) switch (_context5.prev = _context5.next) {
186
- case 0:
187
- console.log('Connected to the database');
188
- checker.targetDatabase = argv.database;
189
- checker.command = command;
190
- checker.options = argv;
191
- _context5.prev = 4;
192
- if (!(command === 'dump')) {
193
- _context5.next = 11;
194
- break;
195
- }
196
- console.log('Dumping the database structure to files');
197
- _context5.next = 9;
198
- return (0, _dump.dumpAllDatabases)(checker.connection, command, argv);
199
- case 9:
200
- _context5.next = 42;
201
- break;
202
- case 11:
203
- if (!(command === 'compare')) {
204
- _context5.next = 21;
205
- break;
206
- }
207
- console.log('Comparing the database structure with JSON dumps (dry run)');
208
- _context5.next = 15;
209
- return (0, _compare.compareAllDatabases)(checker.connection, argv.output, false, command, argv);
210
- case 15:
211
- diffs = _context5.sent;
212
- // Dry run
213
- totalDiffs = Object.values(diffs).reduce(function (acc, arr) {
214
- return acc + arr.length;
215
- }, 0);
216
- console.log('Total differences count:', totalDiffs);
217
- _fs["default"].writeFileSync(_path["default"].join(argv.output, 'diffs.json'), JSON.stringify(diffs, null, 4));
218
- _context5.next = 42;
219
- break;
220
- case 21:
221
- if (!(command === 'update')) {
222
- _context5.next = 42;
223
- break;
224
- }
225
- console.log('Updating the database structure based on JSON dumps');
226
- _totalDiffs = Infinity; // Initialize with a large number
227
- previousDiffs = _totalDiffs; // Store previous differences
228
- runCount = 0; // Counter for the number of runs
229
- maxRuns = 6;
230
- case 27:
231
- if (!(runCount < maxRuns && _totalDiffs > 0 && (_totalDiffs < previousDiffs || previousDiffs === Infinity))) {
232
- _context5.next = 42;
233
- break;
234
- }
235
- console.log('Running update command. Run count:', runCount);
236
- _context5.next = 31;
237
- return (0, _compare.compareAllDatabases)(checker.connection, argv.output, true, command, argv);
238
- case 31:
239
- _diffs = _context5.sent;
240
- // Apply updates
241
- previousDiffs = _totalDiffs; // Update previous differences
242
- _totalDiffs = Object.values(_diffs).reduce(function (acc, arr) {
243
- return acc + arr.length;
244
- }, 0);
245
- console.log('Total differences count:', _totalDiffs);
246
- runCount++;
247
- if (!(_totalDiffs > 0 && runCount < maxRuns)) {
248
- _context5.next = 40;
249
- break;
250
- }
251
- console.log('Total differences count is still greater than 0. Waiting 1 second before next run. Run count:', runCount);
252
- _context5.next = 40;
253
- return new Promise(function (resolve) {
254
- return setTimeout(resolve, 1000);
255
- });
256
- case 40:
257
- _context5.next = 27;
258
- break;
259
- case 42:
260
- _context5.next = 47;
261
- break;
262
- case 44:
263
- _context5.prev = 44;
264
- _context5.t0 = _context5["catch"](4);
265
- console.error(_context5.t0.message);
266
- case 47:
267
- _context5.prev = 47;
268
- _context5.next = 50;
269
- return checker.closeConnection();
270
- case 50:
271
- return _context5.finish(47);
272
- case 51:
273
- case "end":
274
- return _context5.stop();
275
- }
276
- }, _callee5, null, [[4, 44, 47, 51]]);
277
- })));
278
- case 14:
279
- case "end":
280
- return _context6.stop();
281
- }
282
- }, _callee6);
283
- }))();
284
- }