dbgate-tools 5.2.1 → 5.2.2-alpha.11
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.d.ts +1 -2
- package/lib/DatabaseAnalyser.js +15 -7
- package/lib/SqlGenerator.js +3 -1
- package/lib/createBulkInsertStreamBase.js +4 -3
- package/lib/getLogger.d.ts +4 -0
- package/lib/getLogger.js +34 -0
- package/lib/index.d.ts +1 -0
- package/lib/index.js +1 -0
- package/package.json +4 -3
|
@@ -17,14 +17,13 @@ export declare class DatabaseAnalyser {
|
|
|
17
17
|
incrementalAnalysis(structure: any): Promise<DatabaseInfo>;
|
|
18
18
|
mergeAnalyseResult(newlyAnalysed: any): any;
|
|
19
19
|
getRequestedObjectPureNames(objectTypeField: any, allPureNames: any): any;
|
|
20
|
-
containsObjectIdCondition(typeFields: any): boolean;
|
|
21
20
|
createQuery(template: any, typeFields: any): any;
|
|
22
21
|
createQueryCore(template: any, typeFields: any): any;
|
|
23
22
|
getDeletedObjectsForField(snapshot: any, objectTypeField: any): any;
|
|
24
23
|
getDeletedObjects(snapshot: any): any[];
|
|
25
24
|
feedback(obj: any): void;
|
|
26
25
|
getModifications(): Promise<any[]>;
|
|
27
|
-
|
|
26
|
+
analyserQuery(template: any, typeFields: any): Promise<import("dbgate-types").QueryResult>;
|
|
28
27
|
static createEmptyStructure(): DatabaseInfo;
|
|
29
28
|
static byTableFilter(table: any): (x: any) => boolean;
|
|
30
29
|
static extractPrimaryKeys(table: any, pkColumns: any): {
|
package/lib/DatabaseAnalyser.js
CHANGED
|
@@ -17,6 +17,8 @@ const sortBy_1 = __importDefault(require("lodash/sortBy"));
|
|
|
17
17
|
const groupBy_1 = __importDefault(require("lodash/groupBy"));
|
|
18
18
|
const pick_1 = __importDefault(require("lodash/pick"));
|
|
19
19
|
const compact_1 = __importDefault(require("lodash/compact"));
|
|
20
|
+
const getLogger_1 = require("./getLogger");
|
|
21
|
+
const logger = (0, getLogger_1.getLogger)('dbAnalyser');
|
|
20
22
|
const STRUCTURE_FIELDS = ['tables', 'collections', 'views', 'matviews', 'functions', 'procedures', 'triggers'];
|
|
21
23
|
const fp_pick = arg => array => (0, pick_1.default)(array, arg);
|
|
22
24
|
function mergeTableRowCounts(info, rowCounts) {
|
|
@@ -114,7 +116,7 @@ class DatabaseAnalyser {
|
|
|
114
116
|
this.modifications = structureModifications;
|
|
115
117
|
if (structureWithRowCounts)
|
|
116
118
|
this.structure = structureWithRowCounts;
|
|
117
|
-
|
|
119
|
+
logger.info({ modifications: this.modifications }, 'DB modifications detected:');
|
|
118
120
|
return this.addEngineField(this.mergeAnalyseResult(yield this._runAnalysis()));
|
|
119
121
|
});
|
|
120
122
|
}
|
|
@@ -165,9 +167,9 @@ class DatabaseAnalyser {
|
|
|
165
167
|
// findObjectById(id) {
|
|
166
168
|
// return this.structure.tables.find((x) => x.objectId == id);
|
|
167
169
|
// }
|
|
168
|
-
containsObjectIdCondition(typeFields) {
|
|
169
|
-
|
|
170
|
-
}
|
|
170
|
+
// containsObjectIdCondition(typeFields) {
|
|
171
|
+
// return this.createQueryCore('=OBJECT_ID_CONDITION', typeFields) != ' is not null';
|
|
172
|
+
// }
|
|
171
173
|
createQuery(template, typeFields) {
|
|
172
174
|
return this.createQueryCore(template, typeFields);
|
|
173
175
|
}
|
|
@@ -192,7 +194,7 @@ class DatabaseAnalyser {
|
|
|
192
194
|
.filter(x => typeFields.includes(x.objectTypeField) && (x.action == 'add' || x.action == 'change'))
|
|
193
195
|
.map(x => x.objectId);
|
|
194
196
|
if (filterIds.length == 0) {
|
|
195
|
-
return
|
|
197
|
+
return null;
|
|
196
198
|
}
|
|
197
199
|
return template.replace(/=OBJECT_ID_CONDITION/g, ` in (${filterIds.map(x => `'${x}'`).join(',')})`);
|
|
198
200
|
}
|
|
@@ -282,13 +284,19 @@ class DatabaseAnalyser {
|
|
|
282
284
|
return [...(0, compact_1.default)(res), ...this.getDeletedObjects(snapshot)];
|
|
283
285
|
});
|
|
284
286
|
}
|
|
285
|
-
|
|
287
|
+
analyserQuery(template, typeFields) {
|
|
286
288
|
return __awaiter(this, void 0, void 0, function* () {
|
|
289
|
+
const sql = this.createQuery(template, typeFields);
|
|
290
|
+
if (!sql) {
|
|
291
|
+
return {
|
|
292
|
+
rows: [],
|
|
293
|
+
};
|
|
294
|
+
}
|
|
287
295
|
try {
|
|
288
296
|
return yield this.driver.query(this.pool, sql);
|
|
289
297
|
}
|
|
290
298
|
catch (err) {
|
|
291
|
-
|
|
299
|
+
logger.error({ err }, 'Error running analyser query');
|
|
292
300
|
return {
|
|
293
301
|
rows: [],
|
|
294
302
|
};
|
package/lib/SqlGenerator.js
CHANGED
|
@@ -15,7 +15,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
15
15
|
exports.SqlGenerator = void 0;
|
|
16
16
|
const flatten_1 = __importDefault(require("lodash/flatten"));
|
|
17
17
|
const uniqBy_1 = __importDefault(require("lodash/uniqBy"));
|
|
18
|
+
const getLogger_1 = require("./getLogger");
|
|
18
19
|
const structureTools_1 = require("./structureTools");
|
|
20
|
+
const logger = (0, getLogger_1.getLogger)('sqlGenerator');
|
|
19
21
|
class SqlGenerator {
|
|
20
22
|
constructor(dbinfo, options, objects, dmp, driver, pool) {
|
|
21
23
|
this.options = options;
|
|
@@ -26,7 +28,7 @@ class SqlGenerator {
|
|
|
26
28
|
this.isTruncated = false;
|
|
27
29
|
this.isUnhandledException = false;
|
|
28
30
|
this.handleException = error => {
|
|
29
|
-
|
|
31
|
+
logger.error({ error }, 'Unhandled error');
|
|
30
32
|
this.isUnhandledException = true;
|
|
31
33
|
};
|
|
32
34
|
this.dbinfo = (0, structureTools_1.extendDatabaseInfo)(dbinfo);
|
|
@@ -14,7 +14,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
15
|
exports.createBulkInsertStreamBase = void 0;
|
|
16
16
|
const intersection_1 = __importDefault(require("lodash/intersection"));
|
|
17
|
+
const getLogger_1 = require("./getLogger");
|
|
17
18
|
const tableTransforms_1 = require("./tableTransforms");
|
|
19
|
+
const logger = (0, getLogger_1.getLogger)('bulkStreamBase');
|
|
18
20
|
function createBulkInsertStreamBase(driver, stream, pool, name, options) {
|
|
19
21
|
const fullNameQuoted = name.schemaName
|
|
20
22
|
? `${driver.dialect.quoteIdentifier(name.schemaName)}.${driver.dialect.quoteIdentifier(name.pureName)}`
|
|
@@ -39,14 +41,13 @@ function createBulkInsertStreamBase(driver, stream, pool, name, options) {
|
|
|
39
41
|
let structure = yield driver.analyseSingleTable(pool, name);
|
|
40
42
|
// console.log('ANALYSING', name, structure);
|
|
41
43
|
if (structure && options.dropIfExists) {
|
|
42
|
-
|
|
44
|
+
logger.info(`Dropping table ${fullNameQuoted}`);
|
|
43
45
|
yield driver.script(pool, `DROP TABLE ${fullNameQuoted}`);
|
|
44
46
|
}
|
|
45
47
|
if (options.createIfNotExists && (!structure || options.dropIfExists)) {
|
|
46
|
-
console.log(`Creating table ${fullNameQuoted}`);
|
|
47
48
|
const dmp = driver.createDumper();
|
|
48
49
|
dmp.createTable((0, tableTransforms_1.prepareTableForImport)(Object.assign(Object.assign({}, writable.structure), name)));
|
|
49
|
-
|
|
50
|
+
logger.info({ sql: dmp.s }, `Creating table ${fullNameQuoted}`);
|
|
50
51
|
yield driver.script(pool, dmp.s);
|
|
51
52
|
structure = yield driver.analyseSingleTable(pool, name);
|
|
52
53
|
}
|
package/lib/getLogger.js
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
var _a;
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.getLogger = exports.setLoggerName = exports.setLogger = void 0;
|
|
8
|
+
const pinomin_1 = __importDefault(require("pinomin"));
|
|
9
|
+
let _logger;
|
|
10
|
+
let _name = null;
|
|
11
|
+
const defaultLogger = (0, pinomin_1.default)({
|
|
12
|
+
base: { pid: (_a = global === null || global === void 0 ? void 0 : global.process) === null || _a === void 0 ? void 0 : _a.pid },
|
|
13
|
+
targets: [{ type: 'console', level: 'info' }],
|
|
14
|
+
});
|
|
15
|
+
function setLogger(value) {
|
|
16
|
+
_logger = value;
|
|
17
|
+
}
|
|
18
|
+
exports.setLogger = setLogger;
|
|
19
|
+
function setLoggerName(value) {
|
|
20
|
+
_name = value;
|
|
21
|
+
}
|
|
22
|
+
exports.setLoggerName = setLoggerName;
|
|
23
|
+
function getLogger(caller) {
|
|
24
|
+
let res = _logger || defaultLogger;
|
|
25
|
+
if (caller) {
|
|
26
|
+
const props = { caller };
|
|
27
|
+
if (_name) {
|
|
28
|
+
props['name'] = _name;
|
|
29
|
+
}
|
|
30
|
+
res = res.child(props);
|
|
31
|
+
}
|
|
32
|
+
return res;
|
|
33
|
+
}
|
|
34
|
+
exports.getLogger = getLogger;
|
package/lib/index.d.ts
CHANGED
package/lib/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "5.2.
|
|
2
|
+
"version": "5.2.2-alpha.11",
|
|
3
3
|
"name": "dbgate-tools",
|
|
4
4
|
"main": "lib/index.js",
|
|
5
5
|
"typings": "lib/index.d.ts",
|
|
@@ -25,17 +25,18 @@
|
|
|
25
25
|
],
|
|
26
26
|
"devDependencies": {
|
|
27
27
|
"@types/node": "^13.7.0",
|
|
28
|
-
"dbgate-types": "^5.2.
|
|
28
|
+
"dbgate-types": "^5.2.2-alpha.11",
|
|
29
29
|
"jest": "^24.9.0",
|
|
30
30
|
"ts-jest": "^25.2.1",
|
|
31
31
|
"typescript": "^4.4.3"
|
|
32
32
|
},
|
|
33
33
|
"dependencies": {
|
|
34
34
|
"dbgate-query-splitter": "^4.9.3",
|
|
35
|
-
"dbgate-sqltree": "^5.2.
|
|
35
|
+
"dbgate-sqltree": "^5.2.2-alpha.11",
|
|
36
36
|
"debug": "^4.3.4",
|
|
37
37
|
"json-stable-stringify": "^1.0.1",
|
|
38
38
|
"lodash": "^4.17.21",
|
|
39
|
+
"pinomin": "^1.0.1",
|
|
39
40
|
"uuid": "^3.4.0"
|
|
40
41
|
}
|
|
41
42
|
}
|