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/DatabaseAnalyser.js
CHANGED
|
@@ -1,13 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
2
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
4
|
};
|
|
@@ -33,10 +24,16 @@ const STRUCTURE_FIELDS = [
|
|
|
33
24
|
];
|
|
34
25
|
const fp_pick = arg => array => (0, pick_1.default)(array, arg);
|
|
35
26
|
function mergeTableRowCounts(info, rowCounts) {
|
|
36
|
-
return
|
|
27
|
+
return {
|
|
28
|
+
...info,
|
|
29
|
+
tables: (info.tables || []).map(table => {
|
|
37
30
|
var _a, _b;
|
|
38
|
-
return (
|
|
39
|
-
|
|
31
|
+
return ({
|
|
32
|
+
...table,
|
|
33
|
+
tableRowCount: (_b = (_a = rowCounts.find(x => x.objectId == table.objectId)) === null || _a === void 0 ? void 0 : _a.tableRowCount) !== null && _b !== void 0 ? _b : table.tableRowCount,
|
|
34
|
+
});
|
|
35
|
+
}),
|
|
36
|
+
};
|
|
40
37
|
}
|
|
41
38
|
function areDifferentRowCounts(db1, db2) {
|
|
42
39
|
for (const t1 of db1.tables || []) {
|
|
@@ -55,19 +52,13 @@ class DatabaseAnalyser {
|
|
|
55
52
|
this.dialect = ((driver === null || driver === void 0 ? void 0 : driver.dialectByVersion) && (driver === null || driver === void 0 ? void 0 : driver.dialectByVersion(version))) || (driver === null || driver === void 0 ? void 0 : driver.dialect);
|
|
56
53
|
this.logger = logger;
|
|
57
54
|
}
|
|
58
|
-
_runAnalysis() {
|
|
59
|
-
return
|
|
60
|
-
return DatabaseAnalyser.createEmptyStructure();
|
|
61
|
-
});
|
|
62
|
-
}
|
|
63
|
-
_getFastSnapshot() {
|
|
64
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
65
|
-
return null;
|
|
66
|
-
});
|
|
55
|
+
async _runAnalysis() {
|
|
56
|
+
return DatabaseAnalyser.createEmptyStructure();
|
|
67
57
|
}
|
|
68
|
-
|
|
69
|
-
return
|
|
58
|
+
async _getFastSnapshot() {
|
|
59
|
+
return null;
|
|
70
60
|
}
|
|
61
|
+
async _computeSingleObjectId() { }
|
|
71
62
|
addEngineField(db) {
|
|
72
63
|
var _a;
|
|
73
64
|
if (!((_a = this.driver) === null || _a === void 0 ? void 0 : _a.engine))
|
|
@@ -82,61 +73,58 @@ class DatabaseAnalyser {
|
|
|
82
73
|
db.engine = this.driver.engine;
|
|
83
74
|
return db;
|
|
84
75
|
}
|
|
85
|
-
fullAnalysis() {
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
return res;
|
|
91
|
-
});
|
|
76
|
+
async fullAnalysis() {
|
|
77
|
+
logger.debug(`Performing full analysis, DB=${(0, schemaInfoTools_1.dbNameLogCategory)(this.dbhan.database)}, engine=${this.driver.engine}`);
|
|
78
|
+
const res = this.addEngineField(await this._runAnalysis());
|
|
79
|
+
// console.log('FULL ANALYSIS', res);
|
|
80
|
+
return res;
|
|
92
81
|
}
|
|
93
|
-
singleObjectAnalysis(name, typeField) {
|
|
82
|
+
async singleObjectAnalysis(name, typeField) {
|
|
94
83
|
var _a, _b, _c;
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
return obj;
|
|
106
|
-
});
|
|
84
|
+
// console.log('Analysing SINGLE OBJECT', name, typeField);
|
|
85
|
+
this.singleObjectFilter = { ...name, typeField };
|
|
86
|
+
await this._computeSingleObjectId();
|
|
87
|
+
const res = this.addEngineField(await this._runAnalysis());
|
|
88
|
+
// console.log('SINGLE OBJECT RES', JSON.stringify(res, null, 2));
|
|
89
|
+
const obj = ((_a = res[typeField]) === null || _a === void 0 ? void 0 : _a.length) == 1
|
|
90
|
+
? (_b = res[typeField]) === null || _b === void 0 ? void 0 : _b.find(x => x.pureName.toLowerCase() == name.pureName.toLowerCase())
|
|
91
|
+
: (_c = res[typeField]) === null || _c === void 0 ? void 0 : _c.find(x => x.pureName == name.pureName && x.schemaName == name.schemaName);
|
|
92
|
+
// console.log('SINGLE OBJECT', obj);
|
|
93
|
+
return obj;
|
|
107
94
|
}
|
|
108
|
-
incrementalAnalysis(structure) {
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
structureWithRowCounts = newStructure;
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
if (structureModifications.length == 0) {
|
|
128
|
-
return structureWithRowCounts ? this.addEngineField(structureWithRowCounts) : null;
|
|
95
|
+
async incrementalAnalysis(structure) {
|
|
96
|
+
logger.info(`Performing incremental analysis, DB=${(0, schemaInfoTools_1.dbNameLogCategory)(this.dbhan.database)}, engine=${this.driver.engine}`);
|
|
97
|
+
this.structure = structure;
|
|
98
|
+
const modifications = await this.getModifications();
|
|
99
|
+
if (modifications == null) {
|
|
100
|
+
// modifications not implemented, perform full analysis
|
|
101
|
+
this.structure = null;
|
|
102
|
+
return this.addEngineField(await this._runAnalysis());
|
|
103
|
+
}
|
|
104
|
+
const structureModifications = modifications.filter(x => x.action != 'setTableRowCounts');
|
|
105
|
+
const setTableRowCounts = modifications.find(x => x.action == 'setTableRowCounts');
|
|
106
|
+
let structureWithRowCounts = null;
|
|
107
|
+
if (setTableRowCounts) {
|
|
108
|
+
const newStructure = mergeTableRowCounts(structure, setTableRowCounts.rowCounts);
|
|
109
|
+
if (areDifferentRowCounts(structure, newStructure)) {
|
|
110
|
+
structureWithRowCounts = newStructure;
|
|
129
111
|
}
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
112
|
+
}
|
|
113
|
+
if (structureModifications.length == 0) {
|
|
114
|
+
return structureWithRowCounts ? this.addEngineField(structureWithRowCounts) : null;
|
|
115
|
+
}
|
|
116
|
+
this.modifications = structureModifications;
|
|
117
|
+
if (structureWithRowCounts)
|
|
118
|
+
this.structure = structureWithRowCounts;
|
|
119
|
+
logger.info({ modifications: this.modifications }, 'DB modifications detected:');
|
|
120
|
+
return this.addEngineField(this.mergeAnalyseResult(await this._runAnalysis()));
|
|
136
121
|
}
|
|
137
122
|
mergeAnalyseResult(newlyAnalysed) {
|
|
138
123
|
if (this.structure == null) {
|
|
139
|
-
return
|
|
124
|
+
return {
|
|
125
|
+
...DatabaseAnalyser.createEmptyStructure(),
|
|
126
|
+
...newlyAnalysed,
|
|
127
|
+
};
|
|
140
128
|
}
|
|
141
129
|
const res = {};
|
|
142
130
|
for (const field of STRUCTURE_FIELDS) {
|
|
@@ -261,82 +249,78 @@ class DatabaseAnalyser {
|
|
|
261
249
|
logger.debug(obj.analysingMessage);
|
|
262
250
|
}
|
|
263
251
|
}
|
|
264
|
-
getModifications() {
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
continue;
|
|
277
|
-
}
|
|
278
|
-
if (items === undefined) {
|
|
279
|
-
// skip - undefined meens, that field is not supported
|
|
280
|
-
continue;
|
|
281
|
-
}
|
|
282
|
-
for (const item of items) {
|
|
283
|
-
const { objectId, schemaName, pureName, contentHash } = item;
|
|
284
|
-
const obj = this.structure[field].find(x => x.objectId == objectId);
|
|
285
|
-
if (obj && contentHash && obj.contentHash == contentHash)
|
|
286
|
-
continue;
|
|
287
|
-
const action = obj
|
|
288
|
-
? {
|
|
289
|
-
newName: { schemaName, pureName },
|
|
290
|
-
oldName: (0, pick_1.default)(obj, ['schemaName', 'pureName']),
|
|
291
|
-
action: 'change',
|
|
292
|
-
objectTypeField: field,
|
|
293
|
-
objectId,
|
|
294
|
-
}
|
|
295
|
-
: {
|
|
296
|
-
newName: { schemaName, pureName },
|
|
297
|
-
action: 'add',
|
|
298
|
-
objectTypeField: field,
|
|
299
|
-
objectId,
|
|
300
|
-
};
|
|
301
|
-
res.push(action);
|
|
302
|
-
}
|
|
303
|
-
}
|
|
304
|
-
const rowCounts = (snapshot.tables || [])
|
|
305
|
-
.filter(x => x.tableRowCount != null)
|
|
306
|
-
.map(x => ({
|
|
307
|
-
objectId: x.objectId,
|
|
308
|
-
tableRowCount: x.tableRowCount,
|
|
309
|
-
}));
|
|
310
|
-
if (rowCounts.length > 0) {
|
|
311
|
-
res.push({
|
|
312
|
-
action: 'setTableRowCounts',
|
|
313
|
-
rowCounts,
|
|
314
|
-
});
|
|
315
|
-
}
|
|
316
|
-
return [...(0, compact_1.default)(res), ...this.getDeletedObjects(snapshot)];
|
|
317
|
-
});
|
|
318
|
-
}
|
|
319
|
-
analyserQuery(template, typeFields, replacements = {}) {
|
|
320
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
321
|
-
const sql = this.createQuery(template, typeFields, replacements);
|
|
322
|
-
if (!sql) {
|
|
323
|
-
return {
|
|
324
|
-
rows: [],
|
|
325
|
-
};
|
|
252
|
+
async getModifications() {
|
|
253
|
+
const snapshot = await this._getFastSnapshot();
|
|
254
|
+
if (!snapshot)
|
|
255
|
+
return null;
|
|
256
|
+
// console.log('STRUCTURE', this.structure);
|
|
257
|
+
// console.log('SNAPSHOT', snapshot);
|
|
258
|
+
const res = [];
|
|
259
|
+
for (const field in snapshot) {
|
|
260
|
+
const items = snapshot[field];
|
|
261
|
+
if (items === null) {
|
|
262
|
+
res.push({ objectTypeField: field, action: 'all' });
|
|
263
|
+
continue;
|
|
326
264
|
}
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
return res;
|
|
265
|
+
if (items === undefined) {
|
|
266
|
+
// skip - undefined meens, that field is not supported
|
|
267
|
+
continue;
|
|
331
268
|
}
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
269
|
+
for (const item of items) {
|
|
270
|
+
const { objectId, schemaName, pureName, contentHash } = item;
|
|
271
|
+
const obj = this.structure[field].find(x => x.objectId == objectId);
|
|
272
|
+
if (obj && contentHash && obj.contentHash == contentHash)
|
|
273
|
+
continue;
|
|
274
|
+
const action = obj
|
|
275
|
+
? {
|
|
276
|
+
newName: { schemaName, pureName },
|
|
277
|
+
oldName: (0, pick_1.default)(obj, ['schemaName', 'pureName']),
|
|
278
|
+
action: 'change',
|
|
279
|
+
objectTypeField: field,
|
|
280
|
+
objectId,
|
|
281
|
+
}
|
|
282
|
+
: {
|
|
283
|
+
newName: { schemaName, pureName },
|
|
284
|
+
action: 'add',
|
|
285
|
+
objectTypeField: field,
|
|
286
|
+
objectId,
|
|
287
|
+
};
|
|
288
|
+
res.push(action);
|
|
338
289
|
}
|
|
339
|
-
}
|
|
290
|
+
}
|
|
291
|
+
const rowCounts = (snapshot.tables || [])
|
|
292
|
+
.filter(x => x.tableRowCount != null)
|
|
293
|
+
.map(x => ({
|
|
294
|
+
objectId: x.objectId,
|
|
295
|
+
tableRowCount: x.tableRowCount,
|
|
296
|
+
}));
|
|
297
|
+
if (rowCounts.length > 0) {
|
|
298
|
+
res.push({
|
|
299
|
+
action: 'setTableRowCounts',
|
|
300
|
+
rowCounts,
|
|
301
|
+
});
|
|
302
|
+
}
|
|
303
|
+
return [...(0, compact_1.default)(res), ...this.getDeletedObjects(snapshot)];
|
|
304
|
+
}
|
|
305
|
+
async analyserQuery(template, typeFields, replacements = {}) {
|
|
306
|
+
const sql = this.createQuery(template, typeFields, replacements);
|
|
307
|
+
if (!sql) {
|
|
308
|
+
return {
|
|
309
|
+
rows: [],
|
|
310
|
+
};
|
|
311
|
+
}
|
|
312
|
+
try {
|
|
313
|
+
const res = await this.driver.query(this.dbhan, sql);
|
|
314
|
+
this.logger.debug({ rows: res.rows.length, template }, `Loaded analyser query`);
|
|
315
|
+
return res;
|
|
316
|
+
}
|
|
317
|
+
catch (err) {
|
|
318
|
+
logger.error((0, stringTools_1.extractErrorLogData)(err, { template }), 'Error running analyser query');
|
|
319
|
+
return {
|
|
320
|
+
rows: [],
|
|
321
|
+
isError: true,
|
|
322
|
+
};
|
|
323
|
+
}
|
|
340
324
|
}
|
|
341
325
|
static createEmptyStructure() {
|
|
342
326
|
return {
|
|
@@ -357,19 +341,28 @@ class DatabaseAnalyser {
|
|
|
357
341
|
const filtered = pkColumns.filter(DatabaseAnalyser.byTableFilter(table));
|
|
358
342
|
if (filtered.length == 0)
|
|
359
343
|
return undefined;
|
|
360
|
-
return
|
|
344
|
+
return {
|
|
345
|
+
...(0, pick_1.default)(filtered[0], ['constraintName', 'schemaName', 'pureName']),
|
|
346
|
+
constraintType: 'primaryKey',
|
|
347
|
+
columns: filtered.map(fp_pick('columnName')),
|
|
348
|
+
};
|
|
361
349
|
}
|
|
362
350
|
static extractForeignKeys(table, fkColumns) {
|
|
363
351
|
const grouped = (0, groupBy_1.default)(fkColumns.filter(DatabaseAnalyser.byTableFilter(table)), 'constraintName');
|
|
364
|
-
return Object.keys(grouped).map(constraintName => (
|
|
365
|
-
|
|
366
|
-
'
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
352
|
+
return Object.keys(grouped).map(constraintName => ({
|
|
353
|
+
constraintName,
|
|
354
|
+
constraintType: 'foreignKey',
|
|
355
|
+
...(0, pick_1.default)(grouped[constraintName][0], [
|
|
356
|
+
'constraintName',
|
|
357
|
+
'schemaName',
|
|
358
|
+
'pureName',
|
|
359
|
+
'refSchemaName',
|
|
360
|
+
'refTableName',
|
|
361
|
+
'updateAction',
|
|
362
|
+
'deleteAction',
|
|
363
|
+
]),
|
|
364
|
+
columns: grouped[constraintName].map(fp_pick(['columnName', 'refColumnName'])),
|
|
365
|
+
}));
|
|
373
366
|
}
|
|
374
367
|
}
|
|
375
368
|
exports.DatabaseAnalyser = DatabaseAnalyser;
|
package/lib/ScriptWriter.js
CHANGED
|
@@ -1,13 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
2
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
4
|
};
|
|
@@ -179,104 +170,88 @@ class ScriptWriterEval {
|
|
|
179
170
|
}
|
|
180
171
|
endLine() { }
|
|
181
172
|
requirePackage(packageName) { }
|
|
182
|
-
assign(variableName, functionName, props) {
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
}));
|
|
190
|
-
});
|
|
173
|
+
async assign(variableName, functionName, props) {
|
|
174
|
+
const func = (0, packageTools_1.evalShellApiFunctionName)(functionName, this.dbgateApi, this.requirePlugin);
|
|
175
|
+
this.variables[variableName] = await func((0, cloneDeepWith_1.default)(props, node => {
|
|
176
|
+
if (node === null || node === void 0 ? void 0 : node.$hostConnection) {
|
|
177
|
+
return this.hostConnection;
|
|
178
|
+
}
|
|
179
|
+
}));
|
|
191
180
|
}
|
|
192
181
|
assignValue(variableName, jsonValue) {
|
|
193
182
|
this.variables[variableName] = jsonValue;
|
|
194
183
|
}
|
|
195
|
-
copyStream(sourceVar, targetVar, colmapVar = null, progressName) {
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
184
|
+
async copyStream(sourceVar, targetVar, colmapVar = null, progressName) {
|
|
185
|
+
await this.dbgateApi.copyStream(this.variables[sourceVar], this.variables[targetVar], {
|
|
186
|
+
progressName: (0, cloneDeepWith_1.default)(progressName, node => {
|
|
187
|
+
if (node === null || node === void 0 ? void 0 : node.$runid) {
|
|
199
188
|
if (node === null || node === void 0 ? void 0 : node.$runid) {
|
|
200
|
-
|
|
201
|
-
return this.runid;
|
|
202
|
-
}
|
|
189
|
+
return this.runid;
|
|
203
190
|
}
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
|
|
191
|
+
}
|
|
192
|
+
}),
|
|
193
|
+
columns: colmapVar ? this.variables[colmapVar] : null,
|
|
207
194
|
});
|
|
208
195
|
}
|
|
209
196
|
comment(text) { }
|
|
210
|
-
importDatabase(options) {
|
|
211
|
-
|
|
212
|
-
yield this.dbgateApi.importDatabase(options);
|
|
213
|
-
});
|
|
197
|
+
async importDatabase(options) {
|
|
198
|
+
await this.dbgateApi.importDatabase(options);
|
|
214
199
|
}
|
|
215
|
-
dataReplicator(options) {
|
|
216
|
-
|
|
217
|
-
yield this.dbgateApi.dataReplicator(options);
|
|
218
|
-
});
|
|
200
|
+
async dataReplicator(options) {
|
|
201
|
+
await this.dbgateApi.dataReplicator(options);
|
|
219
202
|
}
|
|
220
|
-
zipDirectory(inputDirectory, outputFile) {
|
|
221
|
-
|
|
222
|
-
yield this.dbgateApi.zipDirectory(inputDirectory, outputFile);
|
|
223
|
-
});
|
|
203
|
+
async zipDirectory(inputDirectory, outputFile) {
|
|
204
|
+
await this.dbgateApi.zipDirectory(inputDirectory, outputFile);
|
|
224
205
|
}
|
|
225
206
|
getScript(schedule) {
|
|
226
207
|
throw new Error('Not implemented');
|
|
227
208
|
}
|
|
228
209
|
}
|
|
229
210
|
exports.ScriptWriterEval = ScriptWriterEval;
|
|
230
|
-
function playJsonCommand(cmd, script) {
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
}
|
|
258
|
-
});
|
|
211
|
+
async function playJsonCommand(cmd, script) {
|
|
212
|
+
switch (cmd.type) {
|
|
213
|
+
case 'assign':
|
|
214
|
+
await script.assign(cmd.variableName, cmd.functionName, cmd.props);
|
|
215
|
+
break;
|
|
216
|
+
case 'assignValue':
|
|
217
|
+
await script.assignValue(cmd.variableName, cmd.jsonValue);
|
|
218
|
+
break;
|
|
219
|
+
case 'copyStream':
|
|
220
|
+
await script.copyStream(cmd.sourceVar, cmd.targetVar, cmd.colmapVar, cmd.progressName);
|
|
221
|
+
break;
|
|
222
|
+
case 'endLine':
|
|
223
|
+
await script.endLine();
|
|
224
|
+
break;
|
|
225
|
+
case 'comment':
|
|
226
|
+
await script.comment(cmd.text);
|
|
227
|
+
break;
|
|
228
|
+
case 'importDatabase':
|
|
229
|
+
await script.importDatabase(cmd.options);
|
|
230
|
+
break;
|
|
231
|
+
case 'dataReplicator':
|
|
232
|
+
await script.dataReplicator(cmd.options);
|
|
233
|
+
break;
|
|
234
|
+
case 'zipDirectory':
|
|
235
|
+
await script.zipDirectory(cmd.inputDirectory, cmd.outputFile);
|
|
236
|
+
break;
|
|
237
|
+
}
|
|
259
238
|
}
|
|
260
|
-
function playJsonScriptWriter(json, script) {
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
}
|
|
265
|
-
});
|
|
239
|
+
async function playJsonScriptWriter(json, script) {
|
|
240
|
+
for (const cmd of json.commands) {
|
|
241
|
+
await playJsonCommand(cmd, script);
|
|
242
|
+
}
|
|
266
243
|
}
|
|
267
244
|
exports.playJsonScriptWriter = playJsonScriptWriter;
|
|
268
|
-
function jsonScriptToJavascript(json) {
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
throw new Error('Unallowed package name:' + packageName);
|
|
275
|
-
}
|
|
276
|
-
script.packageNames.push(packageName);
|
|
245
|
+
async function jsonScriptToJavascript(json) {
|
|
246
|
+
const { schedule, packageNames } = json;
|
|
247
|
+
const script = new ScriptWriterJavaScript();
|
|
248
|
+
for (const packageName of packageNames) {
|
|
249
|
+
if (!/^dbgate-plugin-.*$/.test(packageName)) {
|
|
250
|
+
throw new Error('Unallowed package name:' + packageName);
|
|
277
251
|
}
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
252
|
+
script.packageNames.push(packageName);
|
|
253
|
+
}
|
|
254
|
+
await playJsonScriptWriter(json, script);
|
|
255
|
+
return script.getScript(schedule);
|
|
281
256
|
}
|
|
282
257
|
exports.jsonScriptToJavascript = jsonScriptToJavascript;
|
package/lib/SqlDumper.js
CHANGED
|
@@ -244,12 +244,12 @@ class SqlDumper {
|
|
|
244
244
|
this.columnDefault(column);
|
|
245
245
|
}
|
|
246
246
|
if (includeNullable && !((_e = this.dialect) === null || _e === void 0 ? void 0 : _e.specificNullabilityImplementation)) {
|
|
247
|
-
this.put(column.notNull ? '^not ^null' : '^null');
|
|
247
|
+
this.put(column.notNull ? '^not ^null' : this.dialect.implicitNullDeclaration ? '' : '^null');
|
|
248
248
|
}
|
|
249
249
|
}
|
|
250
250
|
else {
|
|
251
251
|
if (includeNullable && !((_f = this.dialect) === null || _f === void 0 ? void 0 : _f.specificNullabilityImplementation)) {
|
|
252
|
-
this.put(column.notNull ? '^not ^null' : '^null');
|
|
252
|
+
this.put(column.notNull ? '^not ^null' : this.dialect.implicitNullDeclaration ? '' : '^null');
|
|
253
253
|
}
|
|
254
254
|
if (includeDefault && ((_h = (_g = column.defaultValue) === null || _g === void 0 ? void 0 : _g.toString()) === null || _h === void 0 ? void 0 : _h.trim())) {
|
|
255
255
|
this.columnDefault(column);
|
|
@@ -608,21 +608,21 @@ class SqlDumper {
|
|
|
608
608
|
if (autoinc) {
|
|
609
609
|
this.allowIdentityInsert(newTable, true);
|
|
610
610
|
}
|
|
611
|
-
this.putCmd('^insert ^into %f (%,i) select %,i ^from %f', newTable, columnPairs.map(x => x.newcol.columnName), columnPairs.map(x => x.oldcol.columnName),
|
|
611
|
+
this.putCmd('^insert ^into %f (%,i) select %,i ^from %f', newTable, columnPairs.map(x => x.newcol.columnName), columnPairs.map(x => x.oldcol.columnName), { ...oldTable, pureName: tmpTable });
|
|
612
612
|
if (autoinc) {
|
|
613
613
|
this.allowIdentityInsert(newTable, false);
|
|
614
614
|
}
|
|
615
615
|
if (this.dialect.dropForeignKey) {
|
|
616
616
|
newTable.dependencies.forEach(cnt => this.createConstraint(cnt));
|
|
617
617
|
}
|
|
618
|
-
this.dropTable(
|
|
618
|
+
this.dropTable({ ...oldTable, pureName: tmpTable });
|
|
619
619
|
}
|
|
620
620
|
else {
|
|
621
621
|
// we have to preserve old table as long as possible
|
|
622
|
-
this.createTable(
|
|
623
|
-
this.putCmd('^insert ^into %f (%,i) select %,s ^from %f',
|
|
622
|
+
this.createTable({ ...newTable, pureName: tmpTable });
|
|
623
|
+
this.putCmd('^insert ^into %f (%,i) select %,s ^from %f', { ...newTable, pureName: tmpTable }, columnPairs.map(x => x.newcol.columnName), columnPairs.map(x => x.oldcol.columnName), oldTable);
|
|
624
624
|
this.dropTable(oldTable);
|
|
625
|
-
this.renameTable(
|
|
625
|
+
this.renameTable({ ...newTable, pureName: tmpTable }, newTable.pureName);
|
|
626
626
|
}
|
|
627
627
|
}
|
|
628
628
|
createSqlObject(obj) {
|