mysqlsyncr 1.0.56 → 1.0.60
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 +5360 -0
- package/dist/index.js +5122 -52
- package/package.json +3 -3
- package/rollup.config.js +2 -2
- package/dist/apply.js +0 -459
- package/dist/cli.js +0 -65
- package/dist/compare.js +0 -251
- package/dist/create.js +0 -19
- package/dist/differences.js +0 -402
- package/dist/dump.js +0 -161
- package/dist/getters.js +0 -333
- package/dist/loggers.js +0 -144
- package/dist/normalizers.js +0 -11
- package/dist/parsers.js +0 -171
- package/dist/socketServer.js +0 -379
- /package/dist/{index.cjs.cjs → index.cjs.js} +0 -0
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/loggers.js
DELETED
|
@@ -1,144 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.setVerbose = exports.logger = exports.logDifferences = void 0;
|
|
7
|
-
var isVerbose = false; // Global variable to manage verbosity
|
|
8
|
-
|
|
9
|
-
var setVerbose = exports.setVerbose = function setVerbose(verbose) {
|
|
10
|
-
isVerbose = verbose; // Function to set the verbosity level
|
|
11
|
-
};
|
|
12
|
-
var logger = exports.logger = function logger() {
|
|
13
|
-
if (isVerbose) {
|
|
14
|
-
var _console;
|
|
15
|
-
(_console = console).log.apply(_console, arguments); // Log all arguments if verbose is enabled
|
|
16
|
-
}
|
|
17
|
-
};
|
|
18
|
-
var logDifferences = exports.logDifferences = function logDifferences(differences, database, dryRun) {
|
|
19
|
-
var formattedDifferences = differences.map(function (diff) {
|
|
20
|
-
switch (diff.type) {
|
|
21
|
-
case 'missing_procedure':
|
|
22
|
-
return {
|
|
23
|
-
Type: diff.type,
|
|
24
|
-
Name: diff.Name,
|
|
25
|
-
Details: "Procedure ".concat(diff.Name, " is missing"),
|
|
26
|
-
Action: 'Procedure is missing'
|
|
27
|
-
};
|
|
28
|
-
case 'mismatched_procedure':
|
|
29
|
-
return {
|
|
30
|
-
Type: diff.type,
|
|
31
|
-
Name: diff.Name,
|
|
32
|
-
Details: "Mismatched procedure ".concat(diff.Name),
|
|
33
|
-
Action: 'Mismatched procedure'
|
|
34
|
-
};
|
|
35
|
-
case 'missing_field':
|
|
36
|
-
return {
|
|
37
|
-
Type: diff.type,
|
|
38
|
-
Name: diff.tableName,
|
|
39
|
-
Details: "Field ".concat(diff.field.Field, " is missing"),
|
|
40
|
-
Action: 'Field is missing'
|
|
41
|
-
};
|
|
42
|
-
case 'missing_table':
|
|
43
|
-
return {
|
|
44
|
-
Type: diff.type,
|
|
45
|
-
Name: diff.tableName,
|
|
46
|
-
Details: "Table ".concat(diff.tableName, " is missing"),
|
|
47
|
-
Action: 'Table is missing'
|
|
48
|
-
};
|
|
49
|
-
case 'extra_field':
|
|
50
|
-
return {
|
|
51
|
-
Type: diff.type,
|
|
52
|
-
Name: diff.tableName,
|
|
53
|
-
Details: "Field ".concat(diff.field.Field, " is extra"),
|
|
54
|
-
Action: 'Field is extra'
|
|
55
|
-
};
|
|
56
|
-
case 'extra_table':
|
|
57
|
-
return {
|
|
58
|
-
Type: diff.type,
|
|
59
|
-
Name: diff.tableName,
|
|
60
|
-
Details: "Table ".concat(diff.tableName, " is extra"),
|
|
61
|
-
Action: 'Table is extra'
|
|
62
|
-
};
|
|
63
|
-
case 'missing_view':
|
|
64
|
-
return {
|
|
65
|
-
Type: diff.type,
|
|
66
|
-
Name: diff.viewName,
|
|
67
|
-
Details: "View ".concat(diff.viewName, " is missing"),
|
|
68
|
-
Action: 'View is missing'
|
|
69
|
-
};
|
|
70
|
-
case 'extra_index':
|
|
71
|
-
return {
|
|
72
|
-
Type: diff.type,
|
|
73
|
-
Name: diff.tableName,
|
|
74
|
-
Details: "Index ".concat(diff.index.Name, " is extra"),
|
|
75
|
-
Action: 'Index is extra'
|
|
76
|
-
};
|
|
77
|
-
case 'missing_index':
|
|
78
|
-
return {
|
|
79
|
-
Type: diff.type,
|
|
80
|
-
TableName: diff.tableName,
|
|
81
|
-
Name: diff.index.Name,
|
|
82
|
-
Details: "Index ".concat(diff.index.Name, " is missing"),
|
|
83
|
-
Action: 'Index is missing'
|
|
84
|
-
};
|
|
85
|
-
case 'mismatched_index':
|
|
86
|
-
return {
|
|
87
|
-
Type: diff.type,
|
|
88
|
-
TableName: diff.tableName,
|
|
89
|
-
Name: diff.index.Name,
|
|
90
|
-
From: diff.from,
|
|
91
|
-
Details: "Index ".concat(diff.index.Name, " is mismatched"),
|
|
92
|
-
Action: 'Index is mismatched'
|
|
93
|
-
};
|
|
94
|
-
case 'extra_trigger':
|
|
95
|
-
return {
|
|
96
|
-
Type: diff.type,
|
|
97
|
-
Name: diff.trigger.Name,
|
|
98
|
-
Details: "Trigger ".concat(diff.trigger.Name, " is extra"),
|
|
99
|
-
Action: 'Trigger is extra'
|
|
100
|
-
};
|
|
101
|
-
case 'mismatched_trigger':
|
|
102
|
-
return {
|
|
103
|
-
Type: diff.type,
|
|
104
|
-
Name: diff.trigger.Name,
|
|
105
|
-
Details: "Trigger ".concat(diff.trigger.Name, " is mismatched"),
|
|
106
|
-
Action: 'Trigger is mismatched'
|
|
107
|
-
};
|
|
108
|
-
case 'missing_trigger':
|
|
109
|
-
console.log('missing_trigger', diff);
|
|
110
|
-
return {
|
|
111
|
-
Type: diff.type,
|
|
112
|
-
Name: diff.trigger.Name,
|
|
113
|
-
Details: "Trigger ".concat(diff.trigger.Name, " is missing"),
|
|
114
|
-
Action: 'Trigger is missing'
|
|
115
|
-
};
|
|
116
|
-
default:
|
|
117
|
-
return {
|
|
118
|
-
Type: diff.type,
|
|
119
|
-
Details: "Unhandled difference type: ".concat(diff.type)
|
|
120
|
-
};
|
|
121
|
-
}
|
|
122
|
-
});
|
|
123
|
-
|
|
124
|
-
// Filter out any undefined or null entries
|
|
125
|
-
var filteredDifferences = formattedDifferences.filter(function (diff) {
|
|
126
|
-
return diff;
|
|
127
|
-
});
|
|
128
|
-
|
|
129
|
-
// Log the differences in a table format
|
|
130
|
-
if (filteredDifferences.length > 0) {
|
|
131
|
-
if (dryRun) {
|
|
132
|
-
logger("Dry Run: Differences for database ".concat(database, ":"));
|
|
133
|
-
} else {
|
|
134
|
-
logger("Differences applied for database ".concat(database, ":"));
|
|
135
|
-
}
|
|
136
|
-
console.table(filteredDifferences);
|
|
137
|
-
} else {
|
|
138
|
-
if (dryRun) {
|
|
139
|
-
logger("Dry Run: No differences found. Database: ".concat(database));
|
|
140
|
-
} else {
|
|
141
|
-
logger("No differences found. Database: ".concat(database));
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
};
|
package/dist/normalizers.js
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.normalizeSQLDefinition = void 0;
|
|
7
|
-
var normalizeSQLDefinition = exports.normalizeSQLDefinition = function normalizeSQLDefinition(definition) {
|
|
8
|
-
return definition.replace(/\s+/g, ' ') // Replace multiple whitespace with a single space
|
|
9
|
-
.replace(/'/g, "\\'") // Escape single quotes
|
|
10
|
-
.trim(); // Trim leading and trailing whitespace
|
|
11
|
-
};
|
package/dist/parsers.js
DELETED
|
@@ -1,171 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.parseCreateTableSQL = exports.parseConstraint = void 0;
|
|
7
|
-
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; } } }; }
|
|
8
|
-
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; } }
|
|
9
|
-
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; }
|
|
10
|
-
var parseCreateTableSQL = exports.parseCreateTableSQL = function parseCreateTableSQL(createTableSQL) {
|
|
11
|
-
if (!createTableSQL) return null;
|
|
12
|
-
var name = createTableSQL.match(/CREATE TABLE\s+`([^`]+)`/)[1];
|
|
13
|
-
var columns = [];
|
|
14
|
-
var indexes = [];
|
|
15
|
-
var constraints = [];
|
|
16
|
-
var engine = null;
|
|
17
|
-
var charset = null;
|
|
18
|
-
var collate = null;
|
|
19
|
-
|
|
20
|
-
// Split the SQL statement into lines and filter out empty lines
|
|
21
|
-
var lines = createTableSQL.split('\n').map(function (line) {
|
|
22
|
-
return line.trim();
|
|
23
|
-
}).filter(function (line) {
|
|
24
|
-
return line.length > 0;
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
// Regular expression to match column definitions
|
|
28
|
-
var columnRegex = /`([^`]+)`\s+([^\s,]+)(\s+NOT NULL|\s+NULL)?(\s+DEFAULT\s+([^,\s]+))?(\s+AUTO_INCREMENT)?/;
|
|
29
|
-
|
|
30
|
-
// Regular expression to match index definitions
|
|
31
|
-
var indexRegex = /(PRIMARY|UNIQUE)?\s*KEY\s*`([^`]+)`\s*\(([^)]+)\)|PRIMARY KEY\s*\(([^)]+)\)/;
|
|
32
|
-
|
|
33
|
-
// Regular expression to match table options (ENGINE, CHARSET, COLLATE)
|
|
34
|
-
var optionsRegex = /ENGINE=(\w+)\s+DEFAULT\s+CHARSET=(\w+)(\s+COLLATE=(\w+))?/;
|
|
35
|
-
|
|
36
|
-
// Process each line
|
|
37
|
-
var _iterator = _createForOfIteratorHelper(lines),
|
|
38
|
-
_step;
|
|
39
|
-
try {
|
|
40
|
-
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
41
|
-
var line = _step.value;
|
|
42
|
-
if (line.includes('CREATE TABLE')) {
|
|
43
|
-
continue;
|
|
44
|
-
}
|
|
45
|
-
// Check if the line contains a column definition
|
|
46
|
-
var columnMatch = columnRegex.exec(line);
|
|
47
|
-
var indexMatch = indexRegex.exec(line);
|
|
48
|
-
var constraintMatch = parseConstraint(line);
|
|
49
|
-
if (columnMatch && !indexMatch && !constraintMatch) {
|
|
50
|
-
var columnType = parseColumnType(line);
|
|
51
|
-
var column = {
|
|
52
|
-
Field: columnMatch[1],
|
|
53
|
-
Type: columnType
|
|
54
|
-
};
|
|
55
|
-
|
|
56
|
-
// Set Null property based on NOT NULL presence
|
|
57
|
-
if (columnMatch[3] && columnMatch[3].includes('NOT NULL')) {
|
|
58
|
-
column.NotNull = true; // Set to false if NOT NULL is present
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
// Set Default property if it exists
|
|
62
|
-
if (columnMatch[5]) {
|
|
63
|
-
// console.log('columnMatch[5]', columnMatch[5], columnMatch[5].replace(/'/g, ''))
|
|
64
|
-
column.Default = columnMatch[5].replace(/'/g, '');
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
// Set AutoIncrement property if it exists
|
|
68
|
-
if (columnMatch[6]) {
|
|
69
|
-
column.AutoIncrement = true; // Set to true if AUTO_INCREMENT is present
|
|
70
|
-
}
|
|
71
|
-
columns.push(column);
|
|
72
|
-
} else if (indexMatch && !constraintMatch) {
|
|
73
|
-
var isPrimary = line.includes("PRIMARY KEY"); // Check for PRIMARY in both patterns
|
|
74
|
-
var isUnique = line.includes("UNIQUE KEY"); // Only set Unique if it matches
|
|
75
|
-
|
|
76
|
-
var keyName = isPrimary ? null : indexMatch[2]; // Set KeyName to null if it's a primary key
|
|
77
|
-
var columnNames = indexMatch[3] ? indexMatch[3].split(',').map(function (col) {
|
|
78
|
-
return col.trim().replace(/`/g, '');
|
|
79
|
-
}) // Remove backticks
|
|
80
|
-
: indexMatch[4].split(',').map(function (col) {
|
|
81
|
-
return col.trim().replace(/`/g, '');
|
|
82
|
-
}); // Remove backticks
|
|
83
|
-
var index = {
|
|
84
|
-
ColumnName: columnNames
|
|
85
|
-
};
|
|
86
|
-
if (isPrimary) index.Primary = true, index.Name = "PRIMARY";
|
|
87
|
-
if (isUnique) index.Unique = true;
|
|
88
|
-
if (keyName) index.Name = keyName;
|
|
89
|
-
indexes.push(index);
|
|
90
|
-
} else if (constraintMatch) {
|
|
91
|
-
constraints.push(constraintMatch);
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
// Handle table options
|
|
96
|
-
} catch (err) {
|
|
97
|
-
_iterator.e(err);
|
|
98
|
-
} finally {
|
|
99
|
-
_iterator.f();
|
|
100
|
-
}
|
|
101
|
-
var optionsMatch = optionsRegex.exec(createTableSQL);
|
|
102
|
-
if (optionsMatch) {
|
|
103
|
-
engine = optionsMatch[1];
|
|
104
|
-
charset = optionsMatch[2];
|
|
105
|
-
collate = optionsMatch[4] || null; // Collate may not be present
|
|
106
|
-
}
|
|
107
|
-
return {
|
|
108
|
-
name: name,
|
|
109
|
-
columns: columns,
|
|
110
|
-
indexes: indexes,
|
|
111
|
-
constraints: constraints,
|
|
112
|
-
engine: engine,
|
|
113
|
-
charset: charset,
|
|
114
|
-
collate: collate
|
|
115
|
-
};
|
|
116
|
-
};
|
|
117
|
-
var parseConstraint = exports.parseConstraint = function parseConstraint(sql) {
|
|
118
|
-
if (!sql) return null;
|
|
119
|
-
var regex = /FOREIGN KEY \((`[^`]+`)\) REFERENCES (`[^`]+`)\s?\((`[^`]+`)\)(?:\sON DELETE (NO|CASCADE|SET NULL|SET DEFAULT))?(?:\sON UPDATE (NO ACTION|CASCADE|SET NULL|SET DEFAULT))?/i;
|
|
120
|
-
var match = sql.match(regex);
|
|
121
|
-
if (!match) {
|
|
122
|
-
return null;
|
|
123
|
-
}
|
|
124
|
-
var onDelete = null;
|
|
125
|
-
var onUpdate = null;
|
|
126
|
-
if (sql.includes('ON DELETE CASCADE')) {
|
|
127
|
-
onDelete = 'CASCADE';
|
|
128
|
-
} else if (sql.includes('ON DELETE SET NULL')) {
|
|
129
|
-
onDelete = 'SET NULL';
|
|
130
|
-
} else if (sql.includes('ON DELETE SET DEFAULT')) {
|
|
131
|
-
onDelete = 'SET DEFAULT';
|
|
132
|
-
} else {
|
|
133
|
-
onDelete = 'NO ACTION';
|
|
134
|
-
}
|
|
135
|
-
if (sql.includes('ON UPDATE CASCADE')) {
|
|
136
|
-
onUpdate = 'CASCADE';
|
|
137
|
-
} else if (sql.includes('ON UPDATE SET NULL')) {
|
|
138
|
-
onUpdate = 'SET NULL';
|
|
139
|
-
} else if (sql.includes('ON UPDATE SET DEFAULT')) {
|
|
140
|
-
onUpdate = 'SET DEFAULT';
|
|
141
|
-
} else {
|
|
142
|
-
onUpdate = 'NO ACTION';
|
|
143
|
-
}
|
|
144
|
-
var columnName = match[1] || '';
|
|
145
|
-
columnName = columnName.replace(/`/g, '');
|
|
146
|
-
var table = match[2] || '';
|
|
147
|
-
table = table.replace(/`/g, '');
|
|
148
|
-
var column = match[3] || '';
|
|
149
|
-
column = column.replace(/`/g, '');
|
|
150
|
-
return {
|
|
151
|
-
Name: "AlertRule",
|
|
152
|
-
// Replace with actual constraint name if needed
|
|
153
|
-
Type: "FOREIGN KEY",
|
|
154
|
-
ColumnName: [columnName],
|
|
155
|
-
// Column in the current table
|
|
156
|
-
References: {
|
|
157
|
-
Table: table,
|
|
158
|
-
// Referenced table
|
|
159
|
-
Column: column // Referenced column
|
|
160
|
-
},
|
|
161
|
-
OnDelete: onDelete,
|
|
162
|
-
OnUpdate: onUpdate
|
|
163
|
-
};
|
|
164
|
-
};
|
|
165
|
-
var parseColumnType = function parseColumnType(line) {
|
|
166
|
-
// Match type pattern including parameters, handling both single and double parameter types
|
|
167
|
-
var typeRegex = /`[^`]+`\s+([a-zA-Z]+(?:\([0-9]+(?:,[0-9]+)?\))?)/i;
|
|
168
|
-
var match = line.match(typeRegex);
|
|
169
|
-
if (!match) return null;
|
|
170
|
-
return match[1]; // Returns the full type including parameters
|
|
171
|
-
};
|