mysqlsyncr 1.0.50 → 1.0.54
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/__tests__/import.cjs +23 -0
- package/dist/apply.js +459 -0
- package/dist/cli.js +65 -0
- package/dist/compare.js +251 -0
- package/dist/create.js +19 -0
- package/dist/differences.js +402 -0
- package/dist/dump.js +161 -0
- package/dist/getters.js +333 -0
- package/dist/index.cjs.cjs +5360 -0
- package/dist/index.esm.js +5354 -0
- package/dist/index.js +284 -0
- package/dist/loggers.js +144 -0
- package/dist/normalizers.js +11 -0
- package/dist/parsers.js +171 -0
- package/dist/socketServer.js +379 -0
- package/package.json +18 -4
- package/rollup.config.js +25 -0
- package/src/index.js +0 -1
|
@@ -0,0 +1,402 @@
|
|
|
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.findDifferences = void 0;
|
|
8
|
+
var _loggers = require("./loggers.js");
|
|
9
|
+
var _normalizers = require("./normalizers.js");
|
|
10
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
11
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
12
|
+
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
|
|
13
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
|
|
14
|
+
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); }
|
|
15
|
+
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; } } }; }
|
|
16
|
+
function _slicedToArray(r, e) { return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest(); }
|
|
17
|
+
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
18
|
+
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; } }
|
|
19
|
+
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; }
|
|
20
|
+
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t["return"] && (u = t["return"](), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
|
|
21
|
+
function _arrayWithHoles(r) { if (Array.isArray(r)) return r; } // Import the logger
|
|
22
|
+
var findDifferences = exports.findDifferences = function findDifferences(expected, current) {
|
|
23
|
+
var differences = [];
|
|
24
|
+
|
|
25
|
+
// Detect extra tables
|
|
26
|
+
if (!current.tables) throw new Error('No tables found in current');
|
|
27
|
+
for (var _i = 0, _Object$keys = Object.keys(current.tables); _i < _Object$keys.length; _i++) {
|
|
28
|
+
var tableName = _Object$keys[_i];
|
|
29
|
+
if (!expected.tables[tableName]) {
|
|
30
|
+
differences.push({
|
|
31
|
+
type: 'extra_table',
|
|
32
|
+
tableName: tableName
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// Compare tables and fields
|
|
38
|
+
if (!expected.tables) throw new Error('No tables found in expected');
|
|
39
|
+
for (var _i2 = 0, _Object$entries = Object.entries(expected.tables); _i2 < _Object$entries.length; _i2++) {
|
|
40
|
+
var _Object$entries$_i = _slicedToArray(_Object$entries[_i2], 2),
|
|
41
|
+
_tableName = _Object$entries$_i[0],
|
|
42
|
+
contents = _Object$entries$_i[1];
|
|
43
|
+
//check if craete table matches from json, if so, we dont need to compare indexes, triggers, or fields
|
|
44
|
+
|
|
45
|
+
if (!current.tables[_tableName]) {
|
|
46
|
+
console.log('missing_table', contents);
|
|
47
|
+
differences.push({
|
|
48
|
+
type: 'missing_table',
|
|
49
|
+
tableName: _tableName,
|
|
50
|
+
createSQL: contents.createSQL
|
|
51
|
+
});
|
|
52
|
+
continue;
|
|
53
|
+
}
|
|
54
|
+
var createTableSql = current.tables[_tableName].createSQL;
|
|
55
|
+
if (createTableSql === contents.createSQL) {
|
|
56
|
+
(0, _loggers.logger)("Table ".concat(_tableName, " createSQL matches from json, skipping indexes, triggers, and fields"));
|
|
57
|
+
continue;
|
|
58
|
+
} else {
|
|
59
|
+
(0, _loggers.logger)("Table ".concat(_tableName, " createSQL does not match from json, comparing indexes, triggers, and fields"));
|
|
60
|
+
(0, _loggers.logger)(createTableSql);
|
|
61
|
+
(0, _loggers.logger)(contents.createSQL);
|
|
62
|
+
}
|
|
63
|
+
var columns = contents.columns,
|
|
64
|
+
indexes = contents.indexes,
|
|
65
|
+
triggers = contents.triggers,
|
|
66
|
+
createSQL = contents.createSQL,
|
|
67
|
+
name = contents.name,
|
|
68
|
+
engine = contents.engine,
|
|
69
|
+
charset = contents.charset,
|
|
70
|
+
collate = contents.collate;
|
|
71
|
+
var currentFieldNames = current.tables[_tableName].columns.map(function (f) {
|
|
72
|
+
return f.Field;
|
|
73
|
+
});
|
|
74
|
+
var expectedFieldNames = columns.map(function (f) {
|
|
75
|
+
return f.Field;
|
|
76
|
+
});
|
|
77
|
+
(0, _loggers.logger)('Detecting missing fields for table', _tableName);
|
|
78
|
+
// // Detect missing fields
|
|
79
|
+
// for (const field of columns) {
|
|
80
|
+
// if (!currentFieldNames.includes(field.Field)) {
|
|
81
|
+
// differences.push({ type: 'missing_field', tableName, field });
|
|
82
|
+
// }
|
|
83
|
+
// }
|
|
84
|
+
|
|
85
|
+
(0, _loggers.logger)('Detecting extra fields for table', _tableName);
|
|
86
|
+
// Detect extra fields
|
|
87
|
+
var _iterator = _createForOfIteratorHelper(current.tables[_tableName].columns),
|
|
88
|
+
_step;
|
|
89
|
+
try {
|
|
90
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
91
|
+
var field = _step.value;
|
|
92
|
+
if (!expectedFieldNames.includes(field.Field)) {
|
|
93
|
+
differences.push({
|
|
94
|
+
type: 'extra_field',
|
|
95
|
+
tableName: _tableName,
|
|
96
|
+
field: field
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
// verify Type Null and Default
|
|
102
|
+
} catch (err) {
|
|
103
|
+
_iterator.e(err);
|
|
104
|
+
} finally {
|
|
105
|
+
_iterator.f();
|
|
106
|
+
}
|
|
107
|
+
(0, _loggers.logger)('Verifying Type Null and Default for table', _tableName);
|
|
108
|
+
var _iterator2 = _createForOfIteratorHelper(columns),
|
|
109
|
+
_step2;
|
|
110
|
+
try {
|
|
111
|
+
var _loop = function _loop() {
|
|
112
|
+
var field = _step2.value;
|
|
113
|
+
var currentField = current.tables[_tableName].columns.find(function (f) {
|
|
114
|
+
return f.Field === field.Field;
|
|
115
|
+
});
|
|
116
|
+
if (!currentField) {
|
|
117
|
+
console.error('Current field not found for', field.Field, 'in table', _tableName);
|
|
118
|
+
differences.push({
|
|
119
|
+
type: 'missing_field',
|
|
120
|
+
tableName: _tableName,
|
|
121
|
+
field: field
|
|
122
|
+
});
|
|
123
|
+
return 1; // continue
|
|
124
|
+
}
|
|
125
|
+
if (field.Type !== currentField.Type) {
|
|
126
|
+
differences.push({
|
|
127
|
+
type: 'mismatched_field',
|
|
128
|
+
info: "Type",
|
|
129
|
+
tableName: _tableName,
|
|
130
|
+
field: field,
|
|
131
|
+
currentField: currentField
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
if (field.Null !== currentField.Null) {
|
|
135
|
+
differences.push({
|
|
136
|
+
type: 'mismatched_field',
|
|
137
|
+
info: "Null",
|
|
138
|
+
tableName: _tableName,
|
|
139
|
+
field: field,
|
|
140
|
+
currentField: currentField
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
if (field.Default !== currentField.Default) {
|
|
144
|
+
differences.push({
|
|
145
|
+
type: 'mismatched_field',
|
|
146
|
+
info: "Default",
|
|
147
|
+
tableName: _tableName,
|
|
148
|
+
field: field,
|
|
149
|
+
currentField: currentField
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
};
|
|
153
|
+
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
|
154
|
+
if (_loop()) continue;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
// verify indexes
|
|
158
|
+
} catch (err) {
|
|
159
|
+
_iterator2.e(err);
|
|
160
|
+
} finally {
|
|
161
|
+
_iterator2.f();
|
|
162
|
+
}
|
|
163
|
+
(0, _loggers.logger)('Verifying indexes for table', _tableName);
|
|
164
|
+
var _iterator3 = _createForOfIteratorHelper(indexes),
|
|
165
|
+
_step3;
|
|
166
|
+
try {
|
|
167
|
+
var _loop2 = function _loop2() {
|
|
168
|
+
var index = _step3.value;
|
|
169
|
+
// Check if the current index matches the expected index structure
|
|
170
|
+
var currentIndex = current.tables[_tableName].indexes.find(function (i) {
|
|
171
|
+
return i.ColumnName.sort().join(', ') === index.ColumnName.sort().join(', ');
|
|
172
|
+
});
|
|
173
|
+
if (!currentIndex) {
|
|
174
|
+
(0, _loggers.logger)('Missing index', index);
|
|
175
|
+
differences.push({
|
|
176
|
+
type: 'missing_index',
|
|
177
|
+
tableName: _tableName,
|
|
178
|
+
indexName: index.Name,
|
|
179
|
+
index: index
|
|
180
|
+
});
|
|
181
|
+
} else {
|
|
182
|
+
// If needed, you can add further checks for uniqueness or other properties here
|
|
183
|
+
if (currentIndex.Name == index.Name) {
|
|
184
|
+
if (currentIndex.Unique !== index.Unique) {
|
|
185
|
+
differences.push({
|
|
186
|
+
type: 'mismatched_index',
|
|
187
|
+
from: 'unique',
|
|
188
|
+
tableName: _tableName,
|
|
189
|
+
indexName: index.Name,
|
|
190
|
+
index: index
|
|
191
|
+
});
|
|
192
|
+
} else if (currentIndex.Primary !== index.Primary) {
|
|
193
|
+
differences.push({
|
|
194
|
+
type: 'mismatched_index',
|
|
195
|
+
from: 'primary',
|
|
196
|
+
tableName: _tableName,
|
|
197
|
+
indexName: index.Name,
|
|
198
|
+
index: index
|
|
199
|
+
});
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
};
|
|
204
|
+
for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
|
|
205
|
+
_loop2();
|
|
206
|
+
}
|
|
207
|
+
} catch (err) {
|
|
208
|
+
_iterator3.e(err);
|
|
209
|
+
} finally {
|
|
210
|
+
_iterator3.f();
|
|
211
|
+
}
|
|
212
|
+
var _iterator4 = _createForOfIteratorHelper(current.tables[_tableName].indexes),
|
|
213
|
+
_step4;
|
|
214
|
+
try {
|
|
215
|
+
var _loop3 = function _loop3() {
|
|
216
|
+
var index = _step4.value;
|
|
217
|
+
(0, _loggers.logger)('Checking index', index);
|
|
218
|
+
var indexFound = false;
|
|
219
|
+
|
|
220
|
+
// Sort the ColumnName array for proper comparison
|
|
221
|
+
var sortedCurrentIndexColumns = index.ColumnName.sort().join(', ');
|
|
222
|
+
if (!indexes.some(function (i) {
|
|
223
|
+
return i.ColumnName.sort().join(', ') === sortedCurrentIndexColumns;
|
|
224
|
+
})) {
|
|
225
|
+
differences.push({
|
|
226
|
+
type: 'extra_index',
|
|
227
|
+
tableName: _tableName,
|
|
228
|
+
indexName: index.Name,
|
|
229
|
+
index: index
|
|
230
|
+
});
|
|
231
|
+
}
|
|
232
|
+
};
|
|
233
|
+
for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
|
|
234
|
+
_loop3();
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
//verify triggers
|
|
238
|
+
} catch (err) {
|
|
239
|
+
_iterator4.e(err);
|
|
240
|
+
} finally {
|
|
241
|
+
_iterator4.f();
|
|
242
|
+
}
|
|
243
|
+
(0, _loggers.logger)('Verifying triggers for table', _tableName);
|
|
244
|
+
var _iterator5 = _createForOfIteratorHelper(triggers),
|
|
245
|
+
_step5;
|
|
246
|
+
try {
|
|
247
|
+
var _loop4 = function _loop4() {
|
|
248
|
+
var trigger = _step5.value;
|
|
249
|
+
var currentTrigger = current.tables[_tableName].triggers.find(function (t) {
|
|
250
|
+
return t.Name === trigger.Name;
|
|
251
|
+
});
|
|
252
|
+
if (!currentTrigger) {
|
|
253
|
+
(0, _loggers.logger)('Missing trigger', trigger);
|
|
254
|
+
differences.push({
|
|
255
|
+
type: 'missing_trigger',
|
|
256
|
+
tableName: _tableName,
|
|
257
|
+
trigger: trigger
|
|
258
|
+
});
|
|
259
|
+
} else {
|
|
260
|
+
// Compare additional properties if needed
|
|
261
|
+
if (currentTrigger.Event !== trigger.Event || currentTrigger.Statement !== trigger.Statement) {
|
|
262
|
+
(0, _loggers.logger)('Mismatched trigger', {
|
|
263
|
+
expected: trigger,
|
|
264
|
+
current: currentTrigger
|
|
265
|
+
});
|
|
266
|
+
differences.push({
|
|
267
|
+
type: 'mismatched_trigger',
|
|
268
|
+
tableName: _tableName,
|
|
269
|
+
trigger: trigger
|
|
270
|
+
});
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
};
|
|
274
|
+
for (_iterator5.s(); !(_step5 = _iterator5.n()).done;) {
|
|
275
|
+
_loop4();
|
|
276
|
+
}
|
|
277
|
+
} catch (err) {
|
|
278
|
+
_iterator5.e(err);
|
|
279
|
+
} finally {
|
|
280
|
+
_iterator5.f();
|
|
281
|
+
}
|
|
282
|
+
var _iterator6 = _createForOfIteratorHelper(current.tables[_tableName].triggers),
|
|
283
|
+
_step6;
|
|
284
|
+
try {
|
|
285
|
+
var _loop5 = function _loop5() {
|
|
286
|
+
var trigger = _step6.value;
|
|
287
|
+
if (!triggers.some(function (t) {
|
|
288
|
+
return t.Name === trigger.Name;
|
|
289
|
+
})) {
|
|
290
|
+
(0, _loggers.logger)('Extra trigger', trigger);
|
|
291
|
+
differences.push({
|
|
292
|
+
type: 'extra_trigger',
|
|
293
|
+
tableName: _tableName,
|
|
294
|
+
trigger: trigger
|
|
295
|
+
});
|
|
296
|
+
}
|
|
297
|
+
};
|
|
298
|
+
for (_iterator6.s(); !(_step6 = _iterator6.n()).done;) {
|
|
299
|
+
_loop5();
|
|
300
|
+
}
|
|
301
|
+
} catch (err) {
|
|
302
|
+
_iterator6.e(err);
|
|
303
|
+
} finally {
|
|
304
|
+
_iterator6.f();
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
// Compare stored procedures
|
|
309
|
+
if (!expected.procedures) throw new Error('No procedures found in expected');
|
|
310
|
+
var _loop6 = function _loop6() {
|
|
311
|
+
var _Object$entries2$_i = _slicedToArray(_Object$entries2[_i3], 2),
|
|
312
|
+
position = _Object$entries2$_i[0],
|
|
313
|
+
contents = _Object$entries2$_i[1];
|
|
314
|
+
var procName = contents.Name;
|
|
315
|
+
var currentProc = current.procedures.find(function (p) {
|
|
316
|
+
return p.Name === procName;
|
|
317
|
+
});
|
|
318
|
+
if (!currentProc) {
|
|
319
|
+
console.log('missing_procedure', contents);
|
|
320
|
+
differences.push(_objectSpread({
|
|
321
|
+
type: 'missing_procedure'
|
|
322
|
+
}, contents));
|
|
323
|
+
return 1; // continue
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
// Check if the procedure definition matches
|
|
327
|
+
if (currentProc.Definition !== contents.Definition) {
|
|
328
|
+
var normalizedCurrentDef = (0, _normalizers.normalizeSQLDefinition)(currentProc.Definition);
|
|
329
|
+
var normalizedNewDef = (0, _normalizers.normalizeSQLDefinition)(contents.Definition);
|
|
330
|
+
if (normalizedCurrentDef !== normalizedNewDef) {
|
|
331
|
+
differences.push(_objectSpread({
|
|
332
|
+
type: 'mismatched_procedure'
|
|
333
|
+
}, contents));
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
};
|
|
337
|
+
for (var _i3 = 0, _Object$entries2 = Object.entries(expected.procedures); _i3 < _Object$entries2.length; _i3++) {
|
|
338
|
+
if (_loop6()) continue;
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
// Compare views
|
|
342
|
+
if (expected.views || current.views) {
|
|
343
|
+
// Handle missing views (when expected has views but current doesn't have them)
|
|
344
|
+
if (expected.views && !current.views) {
|
|
345
|
+
for (var _i4 = 0, _Object$entries3 = Object.entries(expected.views); _i4 < _Object$entries3.length; _i4++) {
|
|
346
|
+
var _Object$entries3$_i = _slicedToArray(_Object$entries3[_i4], 2),
|
|
347
|
+
viewName = _Object$entries3$_i[0],
|
|
348
|
+
expectedDefinition = _Object$entries3$_i[1];
|
|
349
|
+
differences.push({
|
|
350
|
+
type: 'missing_view',
|
|
351
|
+
viewName: viewName,
|
|
352
|
+
definition: expectedDefinition
|
|
353
|
+
});
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
// Handle extra views (when current has views but expected doesn't have them)
|
|
357
|
+
else if (current.views && !expected.views) {
|
|
358
|
+
for (var _i5 = 0, _Object$keys2 = Object.keys(current.views); _i5 < _Object$keys2.length; _i5++) {
|
|
359
|
+
var _viewName = _Object$keys2[_i5];
|
|
360
|
+
differences.push({
|
|
361
|
+
type: 'extra_view',
|
|
362
|
+
viewName: _viewName
|
|
363
|
+
});
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
// Compare views when both exist
|
|
367
|
+
else if (expected.views && current.views) {
|
|
368
|
+
// Check for missing and mismatched views
|
|
369
|
+
for (var _i6 = 0, _Object$entries4 = Object.entries(expected.views); _i6 < _Object$entries4.length; _i6++) {
|
|
370
|
+
var _Object$entries4$_i = _slicedToArray(_Object$entries4[_i6], 2),
|
|
371
|
+
_viewName2 = _Object$entries4$_i[0],
|
|
372
|
+
_expectedDefinition = _Object$entries4$_i[1];
|
|
373
|
+
if (!current.views[_viewName2]) {
|
|
374
|
+
differences.push({
|
|
375
|
+
type: 'missing_view',
|
|
376
|
+
viewName: _viewName2,
|
|
377
|
+
definition: _expectedDefinition
|
|
378
|
+
});
|
|
379
|
+
} else if (current.views[_viewName2] !== _expectedDefinition) {
|
|
380
|
+
differences.push({
|
|
381
|
+
type: 'mismatched_view',
|
|
382
|
+
viewName: _viewName2,
|
|
383
|
+
definition: _expectedDefinition,
|
|
384
|
+
current: current.views[_viewName2]
|
|
385
|
+
});
|
|
386
|
+
}
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
// Check for extra views
|
|
390
|
+
for (var _i7 = 0, _Object$keys3 = Object.keys(current.views); _i7 < _Object$keys3.length; _i7++) {
|
|
391
|
+
var _viewName3 = _Object$keys3[_i7];
|
|
392
|
+
if (!expected.views[_viewName3]) {
|
|
393
|
+
differences.push({
|
|
394
|
+
type: 'extra_view',
|
|
395
|
+
viewName: _viewName3
|
|
396
|
+
});
|
|
397
|
+
}
|
|
398
|
+
}
|
|
399
|
+
}
|
|
400
|
+
}
|
|
401
|
+
return differences;
|
|
402
|
+
};
|
package/dist/dump.js
ADDED
|
@@ -0,0 +1,161 @@
|
|
|
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.getDatabasesFromExistingDumps = exports.dumpAllDatabases = void 0;
|
|
8
|
+
var _module = require("module");
|
|
9
|
+
var _promises = _interopRequireDefault(require("fs/promises"));
|
|
10
|
+
var _path = _interopRequireDefault(require("path"));
|
|
11
|
+
var _getters = require("./getters.js");
|
|
12
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
|
|
13
|
+
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; }
|
|
14
|
+
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; } } }; }
|
|
15
|
+
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; } }
|
|
16
|
+
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; }
|
|
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
|
+
// const require = createRequire(import.meta.url);
|
|
20
|
+
// const { version } = require('../package.json');
|
|
21
|
+
|
|
22
|
+
var dumpAllDatabases = exports.dumpAllDatabases = /*#__PURE__*/function () {
|
|
23
|
+
var _ref = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(connection, command, options) {
|
|
24
|
+
var response, databases, _iterator, _step, database, dbStructure;
|
|
25
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
26
|
+
while (1) switch (_context.prev = _context.next) {
|
|
27
|
+
case 0:
|
|
28
|
+
response = {};
|
|
29
|
+
_context.next = 3;
|
|
30
|
+
return (0, _getters.getDatabases)(connection);
|
|
31
|
+
case 3:
|
|
32
|
+
databases = _context.sent;
|
|
33
|
+
_iterator = _createForOfIteratorHelper(databases);
|
|
34
|
+
_context.prev = 5;
|
|
35
|
+
_iterator.s();
|
|
36
|
+
case 7:
|
|
37
|
+
if ((_step = _iterator.n()).done) {
|
|
38
|
+
_context.next = 19;
|
|
39
|
+
break;
|
|
40
|
+
}
|
|
41
|
+
database = _step.value;
|
|
42
|
+
_context.next = 11;
|
|
43
|
+
return (0, _getters.getDatabaseStructure)(connection, database, command, options);
|
|
44
|
+
case 11:
|
|
45
|
+
dbStructure = _context.sent;
|
|
46
|
+
if (Object.keys(dbStructure.views).length === 0) {
|
|
47
|
+
delete dbStructure.views;
|
|
48
|
+
}
|
|
49
|
+
if (Object.keys(dbStructure.procedures).length === 0) {
|
|
50
|
+
delete dbStructure.procedures;
|
|
51
|
+
}
|
|
52
|
+
_context.next = 16;
|
|
53
|
+
return _promises["default"].writeFile(_path["default"].join(options.output, database, "".concat(database, ".json")), JSON.stringify(dbStructure, null, 4), 'utf-8');
|
|
54
|
+
case 16:
|
|
55
|
+
response[database] = dbStructure;
|
|
56
|
+
case 17:
|
|
57
|
+
_context.next = 7;
|
|
58
|
+
break;
|
|
59
|
+
case 19:
|
|
60
|
+
_context.next = 24;
|
|
61
|
+
break;
|
|
62
|
+
case 21:
|
|
63
|
+
_context.prev = 21;
|
|
64
|
+
_context.t0 = _context["catch"](5);
|
|
65
|
+
_iterator.e(_context.t0);
|
|
66
|
+
case 24:
|
|
67
|
+
_context.prev = 24;
|
|
68
|
+
_iterator.f();
|
|
69
|
+
return _context.finish(24);
|
|
70
|
+
case 27:
|
|
71
|
+
_context.next = 29;
|
|
72
|
+
return _promises["default"].writeFile(_path["default"].join(options.output, 'dumpInfo.json'), JSON.stringify({
|
|
73
|
+
timestamp: new Date().toISOString()
|
|
74
|
+
}, null, 4), 'utf-8');
|
|
75
|
+
case 29:
|
|
76
|
+
return _context.abrupt("return", response);
|
|
77
|
+
case 30:
|
|
78
|
+
case "end":
|
|
79
|
+
return _context.stop();
|
|
80
|
+
}
|
|
81
|
+
}, _callee, null, [[5, 21, 24, 27]]);
|
|
82
|
+
}));
|
|
83
|
+
return function dumpAllDatabases(_x, _x2, _x3) {
|
|
84
|
+
return _ref.apply(this, arguments);
|
|
85
|
+
};
|
|
86
|
+
}();
|
|
87
|
+
var getDatabasesFromExistingDumps = exports.getDatabasesFromExistingDumps = /*#__PURE__*/function () {
|
|
88
|
+
var _ref2 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee2(options) {
|
|
89
|
+
var exists, response, databases, _iterator2, _step2, database, dbStructure;
|
|
90
|
+
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
91
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
92
|
+
case 0:
|
|
93
|
+
console.log('Getting databases from existing dumps in ', options.output);
|
|
94
|
+
//check if the folder exists
|
|
95
|
+
_context2.next = 3;
|
|
96
|
+
return _promises["default"].stat(options.output)["catch"](function () {
|
|
97
|
+
return false;
|
|
98
|
+
});
|
|
99
|
+
case 3:
|
|
100
|
+
exists = _context2.sent;
|
|
101
|
+
if (exists) {
|
|
102
|
+
_context2.next = 7;
|
|
103
|
+
break;
|
|
104
|
+
}
|
|
105
|
+
console.log('Folder does not exist');
|
|
106
|
+
return _context2.abrupt("return", {});
|
|
107
|
+
case 7:
|
|
108
|
+
//read directory above to get the dbs. each db is in a named folder with a matching .json.
|
|
109
|
+
//combine all the .jsons into a single object
|
|
110
|
+
response = {};
|
|
111
|
+
_context2.next = 10;
|
|
112
|
+
return _promises["default"].readdir(_path["default"].join(options.output));
|
|
113
|
+
case 10:
|
|
114
|
+
databases = _context2.sent;
|
|
115
|
+
_iterator2 = _createForOfIteratorHelper(databases);
|
|
116
|
+
_context2.prev = 12;
|
|
117
|
+
_iterator2.s();
|
|
118
|
+
case 14:
|
|
119
|
+
if ((_step2 = _iterator2.n()).done) {
|
|
120
|
+
_context2.next = 25;
|
|
121
|
+
break;
|
|
122
|
+
}
|
|
123
|
+
database = _step2.value;
|
|
124
|
+
if (!(database.includes('diffs') || database.includes('dumpInfo'))) {
|
|
125
|
+
_context2.next = 19;
|
|
126
|
+
break;
|
|
127
|
+
}
|
|
128
|
+
console.log('Skipping diffs folder');
|
|
129
|
+
return _context2.abrupt("continue", 23);
|
|
130
|
+
case 19:
|
|
131
|
+
_context2.next = 21;
|
|
132
|
+
return _promises["default"].readFile(_path["default"].join(options.output, database, "".concat(database, ".json")), 'utf8');
|
|
133
|
+
case 21:
|
|
134
|
+
dbStructure = _context2.sent;
|
|
135
|
+
response[database] = JSON.parse(dbStructure);
|
|
136
|
+
case 23:
|
|
137
|
+
_context2.next = 14;
|
|
138
|
+
break;
|
|
139
|
+
case 25:
|
|
140
|
+
_context2.next = 30;
|
|
141
|
+
break;
|
|
142
|
+
case 27:
|
|
143
|
+
_context2.prev = 27;
|
|
144
|
+
_context2.t0 = _context2["catch"](12);
|
|
145
|
+
_iterator2.e(_context2.t0);
|
|
146
|
+
case 30:
|
|
147
|
+
_context2.prev = 30;
|
|
148
|
+
_iterator2.f();
|
|
149
|
+
return _context2.finish(30);
|
|
150
|
+
case 33:
|
|
151
|
+
return _context2.abrupt("return", response);
|
|
152
|
+
case 34:
|
|
153
|
+
case "end":
|
|
154
|
+
return _context2.stop();
|
|
155
|
+
}
|
|
156
|
+
}, _callee2, null, [[12, 27, 30, 33]]);
|
|
157
|
+
}));
|
|
158
|
+
return function getDatabasesFromExistingDumps(_x4) {
|
|
159
|
+
return _ref2.apply(this, arguments);
|
|
160
|
+
};
|
|
161
|
+
}();
|