dbgate-tools 6.4.3-alpha.1 → 6.5.0
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/lib/DatabaseAnalyser.js +147 -154
- package/lib/ScriptWriter.js +62 -87
- package/lib/SqlDumper.js +7 -7
- package/lib/SqlGenerator.js +85 -95
- package/lib/alterPlan.js +11 -2
- package/lib/computeDiffRows.js +22 -2
- package/lib/createAsyncWriteStream.js +3 -12
- package/lib/createBulkInsertStreamBase.js +26 -35
- package/lib/dbKeysLoader.js +49 -8
- package/lib/diffTools.js +74 -6
- package/lib/driverBase.js +130 -155
- package/lib/getLogger.js +7 -1
- package/lib/preloadedRowsTools.js +35 -39
- package/lib/schemaEditorTools.js +89 -26
- package/lib/stringTools.d.ts +6 -0
- package/lib/stringTools.js +52 -16
- package/lib/structureTools.js +156 -13
- package/package.json +3 -3
package/lib/schemaEditorTools.js
CHANGED
|
@@ -10,27 +10,39 @@ const lodash_1 = __importDefault(require("lodash"));
|
|
|
10
10
|
const stringTools_1 = require("./stringTools");
|
|
11
11
|
function fillEditorColumnInfo(column, table) {
|
|
12
12
|
var _a, _b;
|
|
13
|
-
return
|
|
13
|
+
return {
|
|
14
|
+
isPrimaryKey: !!((_b = (_a = table === null || table === void 0 ? void 0 : table.primaryKey) === null || _a === void 0 ? void 0 : _a.columns) === null || _b === void 0 ? void 0 : _b.find(x => x.columnName == column.columnName)),
|
|
15
|
+
dataType: lodash_1.default.isEmpty(column) ? 'int' : undefined,
|
|
16
|
+
...column,
|
|
17
|
+
};
|
|
14
18
|
}
|
|
15
19
|
exports.fillEditorColumnInfo = fillEditorColumnInfo;
|
|
16
20
|
function processJsonDataUpdateCommands(obj, commands = []) {
|
|
17
21
|
for (const cmd of commands) {
|
|
18
22
|
switch (cmd.type) {
|
|
19
23
|
case 'deleteField':
|
|
20
|
-
obj =
|
|
24
|
+
obj = {
|
|
25
|
+
...obj,
|
|
26
|
+
};
|
|
21
27
|
delete obj[cmd.oldField];
|
|
22
28
|
break;
|
|
23
29
|
case 'renameField':
|
|
24
|
-
obj =
|
|
30
|
+
obj = {
|
|
31
|
+
...obj,
|
|
32
|
+
};
|
|
25
33
|
obj[cmd.newField] = obj[cmd.oldField];
|
|
26
34
|
delete obj[cmd.oldField];
|
|
27
35
|
break;
|
|
28
36
|
case 'setField':
|
|
29
|
-
obj =
|
|
37
|
+
obj = {
|
|
38
|
+
...obj,
|
|
39
|
+
};
|
|
30
40
|
obj[cmd.newField] = cmd.value;
|
|
31
41
|
break;
|
|
32
42
|
case 'setFieldIfNull':
|
|
33
|
-
obj =
|
|
43
|
+
obj = {
|
|
44
|
+
...obj,
|
|
45
|
+
};
|
|
34
46
|
if (obj[cmd.newField] == null) {
|
|
35
47
|
obj[cmd.newField] = cmd.value;
|
|
36
48
|
}
|
|
@@ -51,21 +63,36 @@ function processPrimaryKey(table, oldColumn, newColumn) {
|
|
|
51
63
|
columns: [],
|
|
52
64
|
};
|
|
53
65
|
}
|
|
54
|
-
return
|
|
66
|
+
return {
|
|
67
|
+
...table,
|
|
68
|
+
primaryKey: {
|
|
69
|
+
...primaryKey,
|
|
70
|
+
columns: [
|
|
55
71
|
...primaryKey.columns,
|
|
56
72
|
{
|
|
57
73
|
columnName: newColumn.columnName,
|
|
58
74
|
},
|
|
59
|
-
]
|
|
75
|
+
],
|
|
76
|
+
},
|
|
77
|
+
};
|
|
60
78
|
}
|
|
61
79
|
if ((oldColumn === null || oldColumn === void 0 ? void 0 : oldColumn.isPrimaryKey) && !(newColumn === null || newColumn === void 0 ? void 0 : newColumn.isPrimaryKey)) {
|
|
62
80
|
let primaryKey = table === null || table === void 0 ? void 0 : table.primaryKey;
|
|
63
81
|
if (primaryKey) {
|
|
64
|
-
primaryKey =
|
|
82
|
+
primaryKey = {
|
|
83
|
+
...primaryKey,
|
|
84
|
+
columns: table.primaryKey.columns.filter(x => x.columnName != oldColumn.columnName),
|
|
85
|
+
};
|
|
65
86
|
if (primaryKey.columns.length == 0) {
|
|
66
|
-
return
|
|
87
|
+
return {
|
|
88
|
+
...table,
|
|
89
|
+
primaryKey: null,
|
|
90
|
+
};
|
|
67
91
|
}
|
|
68
|
-
return
|
|
92
|
+
return {
|
|
93
|
+
...table,
|
|
94
|
+
primaryKey,
|
|
95
|
+
};
|
|
69
96
|
}
|
|
70
97
|
}
|
|
71
98
|
return table;
|
|
@@ -74,7 +101,10 @@ function defineDataCommand(table, cmd) {
|
|
|
74
101
|
table['__addDataCommands'] = [...(table['__addDataCommands'] || []), cmd()];
|
|
75
102
|
}
|
|
76
103
|
function editorAddColumn(table, column, addDataCommand) {
|
|
77
|
-
let res =
|
|
104
|
+
let res = {
|
|
105
|
+
...table,
|
|
106
|
+
columns: [...((table === null || table === void 0 ? void 0 : table.columns) || []), { ...column, pairingId: (0, v1_1.default)() }],
|
|
107
|
+
};
|
|
78
108
|
res = processPrimaryKey(res, null, column);
|
|
79
109
|
if (addDataCommand && column.defaultValue) {
|
|
80
110
|
defineDataCommand(res, () => ({
|
|
@@ -89,7 +119,10 @@ exports.editorAddColumn = editorAddColumn;
|
|
|
89
119
|
function editorModifyColumn(table, column, addDataCommand) {
|
|
90
120
|
var _a;
|
|
91
121
|
const oldColumn = (_a = table === null || table === void 0 ? void 0 : table.columns) === null || _a === void 0 ? void 0 : _a.find(x => x.pairingId == column.pairingId);
|
|
92
|
-
let res =
|
|
122
|
+
let res = {
|
|
123
|
+
...table,
|
|
124
|
+
columns: table.columns.map(col => (col.pairingId == column.pairingId ? (0, omit_1.default)(column, ['isPrimaryKey']) : col)),
|
|
125
|
+
};
|
|
93
126
|
res = processPrimaryKey(res, fillEditorColumnInfo(oldColumn, table), column);
|
|
94
127
|
if (addDataCommand && oldColumn.columnName != column.columnName) {
|
|
95
128
|
defineDataCommand(res, () => ({
|
|
@@ -109,7 +142,10 @@ function editorModifyColumn(table, column, addDataCommand) {
|
|
|
109
142
|
}
|
|
110
143
|
exports.editorModifyColumn = editorModifyColumn;
|
|
111
144
|
function editorDeleteColumn(table, column, addDataCommand) {
|
|
112
|
-
let res =
|
|
145
|
+
let res = {
|
|
146
|
+
...table,
|
|
147
|
+
columns: table.columns.filter(col => col.pairingId != column.pairingId),
|
|
148
|
+
};
|
|
113
149
|
res = processPrimaryKey(res, column, null);
|
|
114
150
|
if (addDataCommand) {
|
|
115
151
|
defineDataCommand(res, () => ({
|
|
@@ -121,56 +157,83 @@ function editorDeleteColumn(table, column, addDataCommand) {
|
|
|
121
157
|
}
|
|
122
158
|
exports.editorDeleteColumn = editorDeleteColumn;
|
|
123
159
|
function editorAddConstraint(table, constraint) {
|
|
124
|
-
const res =
|
|
160
|
+
const res = {
|
|
161
|
+
...table,
|
|
162
|
+
};
|
|
125
163
|
if (constraint.constraintType == 'primaryKey') {
|
|
126
|
-
res.primaryKey =
|
|
164
|
+
res.primaryKey = {
|
|
165
|
+
pairingId: (0, v1_1.default)(),
|
|
166
|
+
...constraint,
|
|
167
|
+
};
|
|
127
168
|
}
|
|
128
169
|
if (constraint.constraintType == 'sortingKey') {
|
|
129
|
-
res.sortingKey =
|
|
170
|
+
res.sortingKey = {
|
|
171
|
+
pairingId: (0, v1_1.default)(),
|
|
172
|
+
...constraint,
|
|
173
|
+
};
|
|
130
174
|
}
|
|
131
175
|
if (constraint.constraintType == 'foreignKey') {
|
|
132
176
|
res.foreignKeys = [
|
|
133
177
|
...(res.foreignKeys || []),
|
|
134
|
-
|
|
178
|
+
{
|
|
179
|
+
pairingId: (0, v1_1.default)(),
|
|
180
|
+
...constraint,
|
|
181
|
+
},
|
|
135
182
|
];
|
|
136
183
|
}
|
|
137
184
|
if (constraint.constraintType == 'index') {
|
|
138
185
|
res.indexes = [
|
|
139
186
|
...(res.indexes || []),
|
|
140
|
-
|
|
187
|
+
{
|
|
188
|
+
pairingId: (0, v1_1.default)(),
|
|
189
|
+
...constraint,
|
|
190
|
+
},
|
|
141
191
|
];
|
|
142
192
|
}
|
|
143
193
|
if (constraint.constraintType == 'unique') {
|
|
144
194
|
res.uniques = [
|
|
145
195
|
...(res.uniques || []),
|
|
146
|
-
|
|
196
|
+
{
|
|
197
|
+
pairingId: (0, v1_1.default)(),
|
|
198
|
+
...constraint,
|
|
199
|
+
},
|
|
147
200
|
];
|
|
148
201
|
}
|
|
149
202
|
return res;
|
|
150
203
|
}
|
|
151
204
|
exports.editorAddConstraint = editorAddConstraint;
|
|
152
205
|
function editorModifyConstraint(table, constraint) {
|
|
153
|
-
const res =
|
|
206
|
+
const res = {
|
|
207
|
+
...table,
|
|
208
|
+
};
|
|
154
209
|
if (constraint.constraintType == 'primaryKey') {
|
|
155
|
-
res.primaryKey =
|
|
210
|
+
res.primaryKey = {
|
|
211
|
+
...res.primaryKey,
|
|
212
|
+
...constraint,
|
|
213
|
+
};
|
|
156
214
|
}
|
|
157
215
|
if (constraint.constraintType == 'sortingKey') {
|
|
158
|
-
res.sortingKey =
|
|
216
|
+
res.sortingKey = {
|
|
217
|
+
...res.sortingKey,
|
|
218
|
+
...constraint,
|
|
219
|
+
};
|
|
159
220
|
}
|
|
160
221
|
if (constraint.constraintType == 'foreignKey') {
|
|
161
|
-
res.foreignKeys = table.foreignKeys.map(fk => fk.pairingId == constraint.pairingId ?
|
|
222
|
+
res.foreignKeys = table.foreignKeys.map(fk => fk.pairingId == constraint.pairingId ? { ...fk, ...constraint } : fk);
|
|
162
223
|
}
|
|
163
224
|
if (constraint.constraintType == 'index') {
|
|
164
|
-
res.indexes = table.indexes.map(fk => (fk.pairingId == constraint.pairingId ?
|
|
225
|
+
res.indexes = table.indexes.map(fk => (fk.pairingId == constraint.pairingId ? { ...fk, ...constraint } : fk));
|
|
165
226
|
}
|
|
166
227
|
if (constraint.constraintType == 'unique') {
|
|
167
|
-
res.uniques = table.uniques.map(fk => (fk.pairingId == constraint.pairingId ?
|
|
228
|
+
res.uniques = table.uniques.map(fk => (fk.pairingId == constraint.pairingId ? { ...fk, ...constraint } : fk));
|
|
168
229
|
}
|
|
169
230
|
return res;
|
|
170
231
|
}
|
|
171
232
|
exports.editorModifyConstraint = editorModifyConstraint;
|
|
172
233
|
function editorDeleteConstraint(table, constraint) {
|
|
173
|
-
const res =
|
|
234
|
+
const res = {
|
|
235
|
+
...table,
|
|
236
|
+
};
|
|
174
237
|
if (constraint.constraintType == 'primaryKey') {
|
|
175
238
|
res.primaryKey = null;
|
|
176
239
|
}
|
package/lib/stringTools.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { DataEditorTypesBehaviour } from 'dbgate-types';
|
|
2
|
+
export declare const MAX_GRID_TEXT_LENGTH = 1000;
|
|
2
3
|
export type EditorDataType = 'null' | 'objectid' | 'string' | 'number' | 'object' | 'date' | 'array' | 'boolean' | 'unknown';
|
|
3
4
|
export declare function arrayToHexString(byteArray: any): any;
|
|
4
5
|
export declare function hexStringToArray(inputString: any): any[];
|
|
@@ -42,3 +43,8 @@ export declare function deserializeJsTypesFromJsonParse(obj: any): any;
|
|
|
42
43
|
export declare function serializeJsTypesReplacer(key: any, value: any): any;
|
|
43
44
|
export declare function deserializeJsTypesReviver(key: any, value: any): any;
|
|
44
45
|
export declare function parseNumberSafe(value: any): number | bigint;
|
|
46
|
+
export declare function getSqlFrontMatter(text: string, yamlModule: any): any;
|
|
47
|
+
export declare function removeSqlFrontMatter(text: string): string;
|
|
48
|
+
export declare function setSqlFrontMatter(text: string, data: {
|
|
49
|
+
[key: string]: any;
|
|
50
|
+
}, yamlModule: any): string;
|
package/lib/stringTools.js
CHANGED
|
@@ -1,20 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __rest = (this && this.__rest) || function (s, e) {
|
|
3
|
-
var t = {};
|
|
4
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
5
|
-
t[p] = s[p];
|
|
6
|
-
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
7
|
-
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
8
|
-
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
9
|
-
t[p[i]] = s[p[i]];
|
|
10
|
-
}
|
|
11
|
-
return t;
|
|
12
|
-
};
|
|
13
2
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
14
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
15
4
|
};
|
|
16
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
exports.parseNumberSafe = exports.deserializeJsTypesReviver = exports.serializeJsTypesReplacer = exports.deserializeJsTypesFromJsonParse = exports.serializeJsTypesForJsonStringify = exports.jsonLinesParse = exports.jsonLinesStringify = exports.pinoLogRecordToMessageRecord = exports.getLimitedQuery = exports.safeFormatDate = exports.extractErrorLogData = exports.extractErrorStackTrace = exports.extractErrorMessage = exports.getConvertValueMenu = exports.detectTypeIcon = exports.detectCellDataType = exports.parseSqlDefaultValue = exports.getAsImageSrc = exports.arrayBufferToBase64 = exports.isWktGeometry = exports.getIconForRedisType = exports.isJsonLikeLongString = exports.shouldOpenMultilineDialog = exports.safeCompileRegExp = exports.safeJsonParse = exports.stringifyCellValue = exports.parseCellValue = exports.hexStringToArray = exports.arrayToHexString = void 0;
|
|
6
|
+
exports.setSqlFrontMatter = exports.removeSqlFrontMatter = exports.getSqlFrontMatter = exports.parseNumberSafe = exports.deserializeJsTypesReviver = exports.serializeJsTypesReplacer = exports.deserializeJsTypesFromJsonParse = exports.serializeJsTypesForJsonStringify = exports.jsonLinesParse = exports.jsonLinesStringify = exports.pinoLogRecordToMessageRecord = exports.getLimitedQuery = exports.safeFormatDate = exports.extractErrorLogData = exports.extractErrorStackTrace = exports.extractErrorMessage = exports.getConvertValueMenu = exports.detectTypeIcon = exports.detectCellDataType = exports.parseSqlDefaultValue = exports.getAsImageSrc = exports.arrayBufferToBase64 = exports.isWktGeometry = exports.getIconForRedisType = exports.isJsonLikeLongString = exports.shouldOpenMultilineDialog = exports.safeCompileRegExp = exports.safeJsonParse = exports.stringifyCellValue = exports.parseCellValue = exports.hexStringToArray = exports.arrayToHexString = exports.MAX_GRID_TEXT_LENGTH = void 0;
|
|
18
7
|
const isString_1 = __importDefault(require("lodash/isString"));
|
|
19
8
|
const isArray_1 = __importDefault(require("lodash/isArray"));
|
|
20
9
|
const isDate_1 = __importDefault(require("lodash/isDate"));
|
|
@@ -22,6 +11,10 @@ const isNumber_1 = __importDefault(require("lodash/isNumber"));
|
|
|
22
11
|
const isPlainObject_1 = __importDefault(require("lodash/isPlainObject"));
|
|
23
12
|
const pad_1 = __importDefault(require("lodash/pad"));
|
|
24
13
|
const cloneDeepWith_1 = __importDefault(require("lodash/cloneDeepWith"));
|
|
14
|
+
const isEmpty_1 = __importDefault(require("lodash/isEmpty"));
|
|
15
|
+
const omitBy_1 = __importDefault(require("lodash/omitBy"));
|
|
16
|
+
const isPlainObject_2 = __importDefault(require("lodash/isPlainObject"));
|
|
17
|
+
exports.MAX_GRID_TEXT_LENGTH = 1000; // maximum length of text in grid cell, longer text is truncated
|
|
25
18
|
const dateTimeStorageRegex = /^([0-9]+)-(0[1-9]|1[012])-(0[1-9]|[12][0-9]|3[01])[Tt]([01][0-9]|2[0-3]):([0-5][0-9]):([0-5][0-9]|60)(\.[0-9]+)?(([Zz])|()|([\+|\-]([01][0-9]|2[0-3]):[0-5][0-9]))$/;
|
|
26
19
|
const dateTimeParseRegex = /^(\d{4})-(\d{2})-(\d{2})[Tt ](\d{2}):(\d{2}):(\d{2})(\.[0-9]+)?(([Zz])|()|([\+|\-]([01][0-9]|2[0-3]):[0-5][0-9]))$/;
|
|
27
20
|
function arrayToHexString(byteArray) {
|
|
@@ -271,7 +264,8 @@ function stringifyCellValue(value, intent, editorTypes, gridFormattingOptions, j
|
|
|
271
264
|
};
|
|
272
265
|
}
|
|
273
266
|
}
|
|
274
|
-
|
|
267
|
+
const valueLimited = value.length > exports.MAX_GRID_TEXT_LENGTH ? value.substring(0, exports.MAX_GRID_TEXT_LENGTH) + '...' : value;
|
|
268
|
+
return { value: highlightSpecialCharacters(valueLimited), gridStyle: 'textCellStyle' };
|
|
275
269
|
}
|
|
276
270
|
default:
|
|
277
271
|
return { value: value };
|
|
@@ -513,7 +507,12 @@ exports.extractErrorStackTrace = extractErrorStackTrace;
|
|
|
513
507
|
function extractErrorLogData(err, additionalFields = {}) {
|
|
514
508
|
if (!err)
|
|
515
509
|
return null;
|
|
516
|
-
return
|
|
510
|
+
return {
|
|
511
|
+
errorMessage: extractErrorMessage(err),
|
|
512
|
+
errorObject: err,
|
|
513
|
+
errorStack: extractErrorStackTrace(err),
|
|
514
|
+
...additionalFields,
|
|
515
|
+
};
|
|
517
516
|
}
|
|
518
517
|
exports.extractErrorLogData = extractErrorLogData;
|
|
519
518
|
function safeFormatDate(date) {
|
|
@@ -538,7 +537,7 @@ function getLimitedQuery(sql) {
|
|
|
538
537
|
exports.getLimitedQuery = getLimitedQuery;
|
|
539
538
|
function pinoLogRecordToMessageRecord(logRecord, defaultSeverity = 'info') {
|
|
540
539
|
var _a;
|
|
541
|
-
const { level, time, msg
|
|
540
|
+
const { level, time, msg, ...rest } = logRecord;
|
|
542
541
|
const levelToSeverity = {
|
|
543
542
|
10: 'debug',
|
|
544
543
|
20: 'debug',
|
|
@@ -547,7 +546,12 @@ function pinoLogRecordToMessageRecord(logRecord, defaultSeverity = 'info') {
|
|
|
547
546
|
50: 'error',
|
|
548
547
|
60: 'error',
|
|
549
548
|
};
|
|
550
|
-
return
|
|
549
|
+
return {
|
|
550
|
+
...rest,
|
|
551
|
+
time,
|
|
552
|
+
message: msg,
|
|
553
|
+
severity: (_a = levelToSeverity[level]) !== null && _a !== void 0 ? _a : defaultSeverity,
|
|
554
|
+
};
|
|
551
555
|
}
|
|
552
556
|
exports.pinoLogRecordToMessageRecord = pinoLogRecordToMessageRecord;
|
|
553
557
|
function jsonLinesStringify(jsonArray) {
|
|
@@ -613,3 +617,35 @@ function parseNumberSafe(value) {
|
|
|
613
617
|
return parseFloat(value);
|
|
614
618
|
}
|
|
615
619
|
exports.parseNumberSafe = parseNumberSafe;
|
|
620
|
+
const frontMatterRe = /^--\ >>>[ \t\r]*\n(.*)\n-- <<<[ \t\r]*\n/s;
|
|
621
|
+
function getSqlFrontMatter(text, yamlModule) {
|
|
622
|
+
const match = text.match(frontMatterRe);
|
|
623
|
+
if (!match)
|
|
624
|
+
return null;
|
|
625
|
+
const yamlContentMapped = match[1].replace(/^--[ ]?/gm, '');
|
|
626
|
+
return yamlModule.load(yamlContentMapped);
|
|
627
|
+
}
|
|
628
|
+
exports.getSqlFrontMatter = getSqlFrontMatter;
|
|
629
|
+
function removeSqlFrontMatter(text) {
|
|
630
|
+
return text.replace(frontMatterRe, '');
|
|
631
|
+
}
|
|
632
|
+
exports.removeSqlFrontMatter = removeSqlFrontMatter;
|
|
633
|
+
function setSqlFrontMatter(text, data, yamlModule) {
|
|
634
|
+
const textClean = removeSqlFrontMatter(text);
|
|
635
|
+
if (!(0, isPlainObject_2.default)(data)) {
|
|
636
|
+
return textClean;
|
|
637
|
+
}
|
|
638
|
+
const dataClean = (0, omitBy_1.default)(data, v => v === undefined);
|
|
639
|
+
if ((0, isEmpty_1.default)(dataClean)) {
|
|
640
|
+
return textClean;
|
|
641
|
+
}
|
|
642
|
+
const yamlContent = yamlModule.dump(dataClean);
|
|
643
|
+
const yamlContentMapped = yamlContent
|
|
644
|
+
.trimRight()
|
|
645
|
+
.split('\n')
|
|
646
|
+
.map(line => '-- ' + line)
|
|
647
|
+
.join('\n');
|
|
648
|
+
const frontMatterContent = `-- >>>\n${yamlContentMapped}\n-- <<<\n`;
|
|
649
|
+
return frontMatterContent + textClean;
|
|
650
|
+
}
|
|
651
|
+
exports.setSqlFrontMatter = setSqlFrontMatter;
|
package/lib/structureTools.js
CHANGED
|
@@ -13,17 +13,106 @@ function addTableDependencies(db) {
|
|
|
13
13
|
return db;
|
|
14
14
|
}
|
|
15
15
|
const allForeignKeys = (0, flatten_1.default)(db.tables.map(x => (x === null || x === void 0 ? void 0 : x.foreignKeys) || []));
|
|
16
|
-
return
|
|
16
|
+
return {
|
|
17
|
+
...db,
|
|
18
|
+
tables: (0, compact_1.default)(db.tables).map(table => ({
|
|
19
|
+
...table,
|
|
20
|
+
dependencies: allForeignKeys.filter(x => x.refSchemaName == table.schemaName && x.refTableName == table.pureName),
|
|
21
|
+
})),
|
|
22
|
+
};
|
|
17
23
|
}
|
|
18
24
|
exports.addTableDependencies = addTableDependencies;
|
|
19
25
|
function extendTableInfo(table) {
|
|
20
|
-
return
|
|
21
|
-
|
|
22
|
-
|
|
26
|
+
return {
|
|
27
|
+
...table,
|
|
28
|
+
objectTypeField: 'tables',
|
|
29
|
+
columns: (table.columns || []).map(column => ({
|
|
30
|
+
pureName: table.pureName,
|
|
31
|
+
schemaName: table.schemaName,
|
|
32
|
+
...column,
|
|
33
|
+
})),
|
|
34
|
+
primaryKey: table.primaryKey
|
|
35
|
+
? {
|
|
36
|
+
...table.primaryKey,
|
|
37
|
+
pureName: table.pureName,
|
|
38
|
+
schemaName: table.schemaName,
|
|
39
|
+
constraintType: 'primaryKey',
|
|
40
|
+
}
|
|
41
|
+
: undefined,
|
|
42
|
+
sortingKey: table.sortingKey
|
|
43
|
+
? {
|
|
44
|
+
...table.sortingKey,
|
|
45
|
+
pureName: table.pureName,
|
|
46
|
+
schemaName: table.schemaName,
|
|
47
|
+
constraintType: 'sortingKey',
|
|
48
|
+
}
|
|
49
|
+
: undefined,
|
|
50
|
+
foreignKeys: (table.foreignKeys || []).map(cnt => ({
|
|
51
|
+
...cnt,
|
|
52
|
+
pureName: table.pureName,
|
|
53
|
+
schemaName: table.schemaName,
|
|
54
|
+
constraintType: 'foreignKey',
|
|
55
|
+
})),
|
|
56
|
+
indexes: (table.indexes || []).map(cnt => ({
|
|
57
|
+
...cnt,
|
|
58
|
+
pureName: table.pureName,
|
|
59
|
+
schemaName: table.schemaName,
|
|
60
|
+
constraintType: 'index',
|
|
61
|
+
})),
|
|
62
|
+
checks: (table.checks || []).map(cnt => ({
|
|
63
|
+
...cnt,
|
|
64
|
+
pureName: table.pureName,
|
|
65
|
+
schemaName: table.schemaName,
|
|
66
|
+
constraintType: 'check',
|
|
67
|
+
})),
|
|
68
|
+
uniques: (table.uniques || []).map(cnt => ({
|
|
69
|
+
...cnt,
|
|
70
|
+
pureName: table.pureName,
|
|
71
|
+
schemaName: table.schemaName,
|
|
72
|
+
constraintType: 'unique',
|
|
73
|
+
})),
|
|
74
|
+
};
|
|
23
75
|
}
|
|
24
76
|
exports.extendTableInfo = extendTableInfo;
|
|
25
77
|
function fillDatabaseExtendedInfo(db) {
|
|
26
|
-
return
|
|
78
|
+
return {
|
|
79
|
+
...db,
|
|
80
|
+
tables: (db.tables || []).map(extendTableInfo),
|
|
81
|
+
collections: (db.collections || []).map(obj => ({
|
|
82
|
+
...obj,
|
|
83
|
+
objectTypeField: 'collections',
|
|
84
|
+
})),
|
|
85
|
+
views: (db.views || []).map(obj => ({
|
|
86
|
+
...obj,
|
|
87
|
+
objectTypeField: 'views',
|
|
88
|
+
})),
|
|
89
|
+
matviews: (db.matviews || []).map(obj => ({
|
|
90
|
+
...obj,
|
|
91
|
+
objectTypeField: 'matviews',
|
|
92
|
+
})),
|
|
93
|
+
procedures: (db.procedures || []).map(obj => ({
|
|
94
|
+
...obj,
|
|
95
|
+
objectTypeField: 'procedures',
|
|
96
|
+
parameters: (obj.parameters || []).map(param => ({
|
|
97
|
+
...param,
|
|
98
|
+
pureName: obj.pureName,
|
|
99
|
+
schemaName: obj.schemaName,
|
|
100
|
+
})),
|
|
101
|
+
})),
|
|
102
|
+
functions: (db.functions || []).map(obj => ({
|
|
103
|
+
...obj,
|
|
104
|
+
objectTypeField: 'functions',
|
|
105
|
+
parameters: (obj.parameters || []).map(param => ({
|
|
106
|
+
...param,
|
|
107
|
+
pureName: obj.pureName,
|
|
108
|
+
schemaName: obj.schemaName,
|
|
109
|
+
})),
|
|
110
|
+
})),
|
|
111
|
+
triggers: (db.triggers || []).map(obj => ({
|
|
112
|
+
...obj,
|
|
113
|
+
objectTypeField: 'triggers',
|
|
114
|
+
})),
|
|
115
|
+
};
|
|
27
116
|
}
|
|
28
117
|
function extendDatabaseInfo(db) {
|
|
29
118
|
return fillDatabaseExtendedInfo(addTableDependencies(db));
|
|
@@ -32,12 +121,18 @@ exports.extendDatabaseInfo = extendDatabaseInfo;
|
|
|
32
121
|
function extendDatabaseInfoFromApps(db, apps) {
|
|
33
122
|
if (!db || !apps)
|
|
34
123
|
return db;
|
|
35
|
-
const dbExt =
|
|
124
|
+
const dbExt = {
|
|
125
|
+
...db,
|
|
126
|
+
tables: db.tables.map(table => ({
|
|
127
|
+
...table,
|
|
128
|
+
foreignKeys: [
|
|
36
129
|
...(table.foreignKeys || []),
|
|
37
130
|
...(0, flatten_1.default)(apps.map(app => app.virtualReferences || []))
|
|
38
131
|
.filter(fk => fk.pureName == table.pureName && fk.schemaName == table.schemaName)
|
|
39
|
-
.map(fk => (
|
|
40
|
-
]
|
|
132
|
+
.map(fk => ({ ...fk, constraintType: 'foreignKey', isVirtual: true })),
|
|
133
|
+
],
|
|
134
|
+
})),
|
|
135
|
+
};
|
|
41
136
|
return addTableDependencies(dbExt);
|
|
42
137
|
}
|
|
43
138
|
exports.extendDatabaseInfoFromApps = extendDatabaseInfoFromApps;
|
|
@@ -68,7 +163,16 @@ function filterStructureBySchema(db, schema) {
|
|
|
68
163
|
if (!db) {
|
|
69
164
|
return db;
|
|
70
165
|
}
|
|
71
|
-
return
|
|
166
|
+
return {
|
|
167
|
+
...db,
|
|
168
|
+
tables: (db.tables || []).filter(x => x.schemaName == schema),
|
|
169
|
+
views: (db.views || []).filter(x => x.schemaName == schema),
|
|
170
|
+
collections: (db.collections || []).filter(x => x.schemaName == schema),
|
|
171
|
+
matviews: (db.matviews || []).filter(x => x.schemaName == schema),
|
|
172
|
+
procedures: (db.procedures || []).filter(x => x.schemaName == schema),
|
|
173
|
+
functions: (db.functions || []).filter(x => x.schemaName == schema),
|
|
174
|
+
triggers: (db.triggers || []).filter(x => x.schemaName == schema),
|
|
175
|
+
};
|
|
72
176
|
}
|
|
73
177
|
exports.filterStructureBySchema = filterStructureBySchema;
|
|
74
178
|
function getSchemasUsedByStructure(db) {
|
|
@@ -90,14 +194,42 @@ function replaceSchemaInStructure(db, schema) {
|
|
|
90
194
|
if (!db) {
|
|
91
195
|
return db;
|
|
92
196
|
}
|
|
93
|
-
return
|
|
197
|
+
return {
|
|
198
|
+
...db,
|
|
199
|
+
tables: (db.tables || []).map(tbl => ({
|
|
200
|
+
...tbl,
|
|
201
|
+
schemaName: schema,
|
|
202
|
+
columns: (tbl.columns || []).map(column => ({ ...column, schemaName: schema })),
|
|
203
|
+
primaryKey: tbl.primaryKey ? { ...tbl.primaryKey, schemaName: schema } : undefined,
|
|
204
|
+
sortingKey: tbl.sortingKey ? { ...tbl.sortingKey, schemaName: schema } : undefined,
|
|
205
|
+
foreignKeys: (tbl.foreignKeys || []).map(fk => ({ ...fk, refSchemaName: schema, schemaName: schema })),
|
|
206
|
+
indexes: (tbl.indexes || []).map(idx => ({ ...idx, schemaName: schema })),
|
|
207
|
+
uniques: (tbl.uniques || []).map(idx => ({ ...idx, schemaName: schema })),
|
|
208
|
+
checks: (tbl.checks || []).map(idx => ({ ...idx, schemaName: schema })),
|
|
209
|
+
})),
|
|
210
|
+
views: (db.views || []).map(x => ({ ...x, schemaName: schema })),
|
|
211
|
+
collections: (db.collections || []).map(x => ({ ...x, schemaName: schema })),
|
|
212
|
+
matviews: (db.matviews || []).map(x => ({ ...x, schemaName: schema })),
|
|
213
|
+
procedures: (db.procedures || []).map(x => ({ ...x, schemaName: schema })),
|
|
214
|
+
functions: (db.functions || []).map(x => ({ ...x, schemaName: schema })),
|
|
215
|
+
triggers: (db.triggers || []).map(x => ({ ...x, schemaName: schema })),
|
|
216
|
+
};
|
|
94
217
|
}
|
|
95
218
|
exports.replaceSchemaInStructure = replaceSchemaInStructure;
|
|
96
219
|
function skipNamesInStructureByRegex(db, regex) {
|
|
97
220
|
if (!db) {
|
|
98
221
|
return db;
|
|
99
222
|
}
|
|
100
|
-
return
|
|
223
|
+
return {
|
|
224
|
+
...db,
|
|
225
|
+
tables: (db.tables || []).filter(x => !regex.test(x.pureName)),
|
|
226
|
+
views: (db.views || []).filter(x => !regex.test(x.pureName)),
|
|
227
|
+
collections: (db.collections || []).filter(x => !regex.test(x.pureName)),
|
|
228
|
+
matviews: (db.matviews || []).filter(x => !regex.test(x.pureName)),
|
|
229
|
+
procedures: (db.procedures || []).filter(x => !regex.test(x.pureName)),
|
|
230
|
+
functions: (db.functions || []).filter(x => !regex.test(x.pureName)),
|
|
231
|
+
triggers: (db.triggers || []).filter(x => !regex.test(x.pureName)),
|
|
232
|
+
};
|
|
101
233
|
}
|
|
102
234
|
exports.skipNamesInStructureByRegex = skipNamesInStructureByRegex;
|
|
103
235
|
function detectChangesInPreloadedRows(oldTable, newTable) {
|
|
@@ -143,10 +275,21 @@ function removePreloadedRowsFromStructure(db) {
|
|
|
143
275
|
if (!db) {
|
|
144
276
|
return db;
|
|
145
277
|
}
|
|
146
|
-
return
|
|
278
|
+
return {
|
|
279
|
+
...db,
|
|
280
|
+
tables: (db.tables || []).map(tbl => ({
|
|
281
|
+
...tbl,
|
|
282
|
+
preloadedRows: undefined,
|
|
283
|
+
preloadedRowsKey: undefined,
|
|
284
|
+
preloadedRowsInsertOnly: undefined,
|
|
285
|
+
})),
|
|
286
|
+
};
|
|
147
287
|
}
|
|
148
288
|
exports.removePreloadedRowsFromStructure = removePreloadedRowsFromStructure;
|
|
149
289
|
function skipDbGateInternalObjects(db) {
|
|
150
|
-
return
|
|
290
|
+
return {
|
|
291
|
+
...db,
|
|
292
|
+
tables: (db.tables || []).filter(tbl => tbl.pureName != 'dbgate_deploy_journal'),
|
|
293
|
+
};
|
|
151
294
|
}
|
|
152
295
|
exports.skipDbGateInternalObjects = skipDbGateInternalObjects;
|
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "6.
|
|
2
|
+
"version": "6.5.0",
|
|
3
3
|
"name": "dbgate-tools",
|
|
4
4
|
"main": "lib/index.js",
|
|
5
5
|
"typings": "lib/index.d.ts",
|
|
@@ -26,14 +26,14 @@
|
|
|
26
26
|
],
|
|
27
27
|
"devDependencies": {
|
|
28
28
|
"@types/node": "^13.7.0",
|
|
29
|
-
"dbgate-types": "^6.
|
|
29
|
+
"dbgate-types": "^6.5.0",
|
|
30
30
|
"jest": "^28.1.3",
|
|
31
31
|
"ts-jest": "^28.0.7",
|
|
32
32
|
"typescript": "^4.4.3"
|
|
33
33
|
},
|
|
34
34
|
"dependencies": {
|
|
35
35
|
"dbgate-query-splitter": "^4.11.5",
|
|
36
|
-
"dbgate-sqltree": "^6.
|
|
36
|
+
"dbgate-sqltree": "^6.5.0",
|
|
37
37
|
"debug": "^4.3.4",
|
|
38
38
|
"json-stable-stringify": "^1.0.1",
|
|
39
39
|
"lodash": "^4.17.21",
|