dbgate-tools 6.6.0 → 6.6.1
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 +5 -0
- package/lib/DatabaseAnalyser.js +9 -6
- package/lib/SqlGenerator.js +1 -1
- package/lib/alterPlan.d.ts +1 -0
- package/lib/alterPlan.js +18 -8
- package/lib/createBulkInsertStreamBase.js +5 -5
- package/lib/diffTools.d.ts +1 -0
- package/lib/diffTools.js +5 -3
- package/lib/driverBase.d.ts +5 -0
- package/lib/driverBase.js +8 -1
- package/lib/schemaInfoTools.d.ts +0 -1
- package/lib/schemaInfoTools.js +10 -11
- package/package.json +4 -4
|
@@ -14,6 +14,11 @@ export declare class DatabaseAnalyser<TClient = any> {
|
|
|
14
14
|
_getFastSnapshot(): Promise<DatabaseInfo>;
|
|
15
15
|
_computeSingleObjectId(): Promise<void>;
|
|
16
16
|
addEngineField(db: DatabaseInfo): DatabaseInfo;
|
|
17
|
+
getLogDbInfo(): {
|
|
18
|
+
database?: string;
|
|
19
|
+
engine: string;
|
|
20
|
+
conid?: string;
|
|
21
|
+
};
|
|
17
22
|
fullAnalysis(): Promise<DatabaseInfo>;
|
|
18
23
|
singleObjectAnalysis(name: any, typeField: any): Promise<any>;
|
|
19
24
|
incrementalAnalysis(structure: any): Promise<DatabaseInfo>;
|
package/lib/DatabaseAnalyser.js
CHANGED
|
@@ -73,8 +73,11 @@ class DatabaseAnalyser {
|
|
|
73
73
|
db.engine = this.driver.engine;
|
|
74
74
|
return db;
|
|
75
75
|
}
|
|
76
|
+
getLogDbInfo() {
|
|
77
|
+
return this.driver.getLogDbInfo(this.dbhan);
|
|
78
|
+
}
|
|
76
79
|
async fullAnalysis() {
|
|
77
|
-
logger.debug(
|
|
80
|
+
logger.debug(this.getLogDbInfo(), 'DBGM-00126 Performing full analysis');
|
|
78
81
|
const res = this.addEngineField(await this._runAnalysis());
|
|
79
82
|
// console.log('FULL ANALYSIS', res);
|
|
80
83
|
return res;
|
|
@@ -93,7 +96,7 @@ class DatabaseAnalyser {
|
|
|
93
96
|
return obj;
|
|
94
97
|
}
|
|
95
98
|
async incrementalAnalysis(structure) {
|
|
96
|
-
logger.info(
|
|
99
|
+
logger.info(this.getLogDbInfo(), 'DBGM-00127 Performing incremental analysis');
|
|
97
100
|
this.structure = structure;
|
|
98
101
|
const modifications = await this.getModifications();
|
|
99
102
|
if (modifications == null) {
|
|
@@ -116,7 +119,7 @@ class DatabaseAnalyser {
|
|
|
116
119
|
this.modifications = structureModifications;
|
|
117
120
|
if (structureWithRowCounts)
|
|
118
121
|
this.structure = structureWithRowCounts;
|
|
119
|
-
logger.info({ modifications: this.modifications }, 'DB modifications detected
|
|
122
|
+
logger.info({ ...this.getLogDbInfo(), modifications: this.modifications }, 'DBGM-00128 DB modifications detected');
|
|
120
123
|
return this.addEngineField(this.mergeAnalyseResult(await this._runAnalysis()));
|
|
121
124
|
}
|
|
122
125
|
mergeAnalyseResult(newlyAnalysed) {
|
|
@@ -246,7 +249,7 @@ class DatabaseAnalyser {
|
|
|
246
249
|
this.dbhan.feedback(obj);
|
|
247
250
|
}
|
|
248
251
|
if (obj && obj.analysingMessage) {
|
|
249
|
-
logger.debug(obj.analysingMessage);
|
|
252
|
+
logger.debug(this.getLogDbInfo(), obj.analysingMessage);
|
|
250
253
|
}
|
|
251
254
|
}
|
|
252
255
|
async getModifications() {
|
|
@@ -311,11 +314,11 @@ class DatabaseAnalyser {
|
|
|
311
314
|
}
|
|
312
315
|
try {
|
|
313
316
|
const res = await this.driver.query(this.dbhan, sql);
|
|
314
|
-
this.logger.debug({ rows: res.rows.length, template }, `Loaded analyser query`);
|
|
317
|
+
this.logger.debug({ ...this.getLogDbInfo(), rows: res.rows.length, template }, `DBGM-00129 Loaded analyser query`);
|
|
315
318
|
return res;
|
|
316
319
|
}
|
|
317
320
|
catch (err) {
|
|
318
|
-
logger.error((0, stringTools_1.extractErrorLogData)(err, { template }), 'Error running analyser query');
|
|
321
|
+
logger.error((0, stringTools_1.extractErrorLogData)(err, { template, ...this.getLogDbInfo() }), 'DBGM-00130 Error running analyser query');
|
|
319
322
|
return {
|
|
320
323
|
rows: [],
|
|
321
324
|
isError: true,
|
package/lib/SqlGenerator.js
CHANGED
|
@@ -20,7 +20,7 @@ class SqlGenerator {
|
|
|
20
20
|
this.isTruncated = false;
|
|
21
21
|
this.isUnhandledException = false;
|
|
22
22
|
this.handleException = error => {
|
|
23
|
-
logger.error((0, stringTools_1.extractErrorLogData)(error), 'Unhandled error');
|
|
23
|
+
logger.error((0, stringTools_1.extractErrorLogData)(error), 'DBGM-00186 Unhandled error');
|
|
24
24
|
this.isUnhandledException = true;
|
|
25
25
|
};
|
|
26
26
|
this.dbinfo = (0, structureTools_1.extendDatabaseInfo)(dbinfo);
|
package/lib/alterPlan.d.ts
CHANGED
|
@@ -114,6 +114,7 @@ export declare class AlterPlan {
|
|
|
114
114
|
fillPreloadedRows(table: NamedObjectInfo, oldRows: any[], newRows: any[], key: string[], insertOnly: string[], autoIncrementColumn: string): void;
|
|
115
115
|
setTableOption(table: TableInfo, optionName: string, optionValue: string): void;
|
|
116
116
|
run(processor: AlterProcessor): void;
|
|
117
|
+
_hasOnlyCommentChange(op: AlterOperation): boolean;
|
|
117
118
|
_getDependendColumnConstraints(column: ColumnInfo, dependencyDefinition: any): import("dbgate-types/dbinfo").PrimaryKeyInfo[];
|
|
118
119
|
_addLogicalDependencies(): AlterOperation[];
|
|
119
120
|
_transformToImplementedOps(): AlterOperation[];
|
package/lib/alterPlan.js
CHANGED
|
@@ -143,6 +143,12 @@ class AlterPlan {
|
|
|
143
143
|
runAlterOperation(op, processor);
|
|
144
144
|
}
|
|
145
145
|
}
|
|
146
|
+
_hasOnlyCommentChange(op) {
|
|
147
|
+
if (op.operationType === 'changeColumn') {
|
|
148
|
+
return lodash_1.default.isEqual(lodash_1.default.omit(op.oldObject, ['columnComment', 'ordinal']), lodash_1.default.omit(op.newObject, ['columnComment', 'ordinal']));
|
|
149
|
+
}
|
|
150
|
+
return false;
|
|
151
|
+
}
|
|
146
152
|
_getDependendColumnConstraints(column, dependencyDefinition) {
|
|
147
153
|
const table = this.wholeOldDb.tables.find(x => x.pureName == column.pureName && x.schemaName == column.schemaName);
|
|
148
154
|
if (!table)
|
|
@@ -184,28 +190,32 @@ class AlterPlan {
|
|
|
184
190
|
]) {
|
|
185
191
|
if (op.operationType == testedOperationType) {
|
|
186
192
|
const constraints = this._getDependendColumnConstraints(testedObject, testedDependencies);
|
|
193
|
+
const ignoreContraints = this.dialect.safeCommentChanges && this._hasOnlyCommentChange(op);
|
|
187
194
|
// if (constraints.length > 0 && this.opts.noDropConstraint) {
|
|
188
195
|
// return [];
|
|
189
196
|
// }
|
|
190
|
-
const res = [
|
|
191
|
-
|
|
197
|
+
const res = [];
|
|
198
|
+
if (!ignoreContraints) {
|
|
199
|
+
res.push(...constraints.map(oldObject => {
|
|
192
200
|
const opRes = {
|
|
193
201
|
operationType: 'dropConstraint',
|
|
194
202
|
oldObject,
|
|
195
203
|
isRecreate: true,
|
|
196
204
|
};
|
|
197
205
|
return opRes;
|
|
198
|
-
})
|
|
199
|
-
|
|
200
|
-
|
|
206
|
+
}));
|
|
207
|
+
}
|
|
208
|
+
res.push(op);
|
|
209
|
+
if (!ignoreContraints) {
|
|
210
|
+
res.push(...lodash_1.default.reverse([...constraints]).map(newObject => {
|
|
201
211
|
const opRes = {
|
|
202
212
|
operationType: 'createConstraint',
|
|
203
213
|
newObject,
|
|
204
214
|
};
|
|
205
215
|
return opRes;
|
|
206
|
-
})
|
|
207
|
-
|
|
208
|
-
if (constraints.length > 0) {
|
|
216
|
+
}));
|
|
217
|
+
}
|
|
218
|
+
if (!ignoreContraints && constraints.length > 0) {
|
|
209
219
|
this.recreates.constraints += 1;
|
|
210
220
|
}
|
|
211
221
|
return res;
|
|
@@ -42,20 +42,20 @@ function createBulkInsertStreamBase(driver, stream, dbhan, name, options) {
|
|
|
42
42
|
writable.structure = structure;
|
|
43
43
|
}
|
|
44
44
|
if (structure && options.dropIfExists) {
|
|
45
|
-
logger.info(`Dropping table ${fullNameQuoted}`);
|
|
45
|
+
logger.info(`DBGM-00123 Dropping table ${fullNameQuoted}`);
|
|
46
46
|
await driver.script(dbhan, `DROP TABLE ${fullNameQuoted}`);
|
|
47
47
|
}
|
|
48
48
|
if (options.createIfNotExists && (!structure || options.dropIfExists)) {
|
|
49
49
|
const dmp = driver.createDumper();
|
|
50
50
|
const createdTableInfo = driver.adaptTableInfo((0, tableTransforms_1.prepareTableForImport)({ ...writable.structure, ...name }));
|
|
51
51
|
dmp.createTable(createdTableInfo);
|
|
52
|
-
logger.info({ sql: dmp.s }, `Creating table ${fullNameQuoted}`);
|
|
52
|
+
logger.info({ sql: dmp.s }, `DBGM-00124 Creating table ${fullNameQuoted}`);
|
|
53
53
|
await driver.script(dbhan, dmp.s);
|
|
54
54
|
structure = await driver.analyseSingleTable(dbhan, name);
|
|
55
55
|
writable.structure = structure;
|
|
56
56
|
}
|
|
57
57
|
if (!writable.structure) {
|
|
58
|
-
throw new Error(`Error importing table - ${fullNameQuoted} not found`);
|
|
58
|
+
throw new Error(`DBGM-00125 Error importing table - ${fullNameQuoted} not found`);
|
|
59
59
|
}
|
|
60
60
|
if (options.truncate) {
|
|
61
61
|
await driver.script(dbhan, `TRUNCATE TABLE ${fullNameQuoted}`);
|
|
@@ -70,7 +70,7 @@ function createBulkInsertStreamBase(driver, stream, dbhan, name, options) {
|
|
|
70
70
|
}));
|
|
71
71
|
}
|
|
72
72
|
catch (err) {
|
|
73
|
-
logger.error((0, stringTools_1.extractErrorLogData)(err), 'Error during preparing bulk insert table, stopped');
|
|
73
|
+
logger.error((0, stringTools_1.extractErrorLogData)(err), 'DBGM-00184 Error during preparing bulk insert table, stopped');
|
|
74
74
|
writable.destroy(err);
|
|
75
75
|
}
|
|
76
76
|
};
|
|
@@ -121,7 +121,7 @@ function createBulkInsertStreamBase(driver, stream, dbhan, name, options) {
|
|
|
121
121
|
}
|
|
122
122
|
}
|
|
123
123
|
catch (err) {
|
|
124
|
-
logger.error((0, stringTools_1.extractErrorLogData)(err), 'Error during base bulk insert, insert stopped');
|
|
124
|
+
logger.error((0, stringTools_1.extractErrorLogData)(err), 'DBGM-00185 Error during base bulk insert, insert stopped');
|
|
125
125
|
writable.destroy(err);
|
|
126
126
|
}
|
|
127
127
|
};
|
package/lib/diffTools.d.ts
CHANGED
|
@@ -19,6 +19,7 @@ export interface DbDiffOptions {
|
|
|
19
19
|
noRenameColumn?: boolean;
|
|
20
20
|
ignoreForeignKeyActions?: boolean;
|
|
21
21
|
ignoreDataTypes?: boolean;
|
|
22
|
+
ignoreComments?: boolean;
|
|
22
23
|
}
|
|
23
24
|
export declare function generateTablePairingId(table: TableInfo): TableInfo;
|
|
24
25
|
export declare function removeTablePairingId(table: TableInfo): TableInfo;
|
package/lib/diffTools.js
CHANGED
|
@@ -252,9 +252,11 @@ function testEqualColumns(a, b, checkName, checkDefault, opts = {}) {
|
|
|
252
252
|
console.debug(`Column ${a.pureName}.${a.columnName}, ${b.pureName}.${b.columnName}: different zerofill: ${a.isZerofill}, ${b.isZerofill}`);
|
|
253
253
|
return false;
|
|
254
254
|
}
|
|
255
|
-
if (
|
|
256
|
-
|
|
257
|
-
|
|
255
|
+
if (!opts.ignoreComments) {
|
|
256
|
+
if ((a.columnComment || '') != (b.columnComment || '')) {
|
|
257
|
+
console.debug(`Column ${a.pureName}.${a.columnName}, ${b.pureName}.${b.columnName}: different comment: ${a.columnComment}, ${b.columnComment}`);
|
|
258
|
+
return false;
|
|
259
|
+
}
|
|
258
260
|
}
|
|
259
261
|
if (!testEqualTypes(a, b, opts)) {
|
|
260
262
|
return false;
|
package/lib/driverBase.d.ts
CHANGED
|
@@ -53,4 +53,9 @@ export declare const driverBase: {
|
|
|
53
53
|
adaptTableInfo(table: any): any;
|
|
54
54
|
listSchemas(pool: any): Promise<any>;
|
|
55
55
|
writeQueryFromStream(dbhan: any, sql: any): Promise<any>;
|
|
56
|
+
getLogDbInfo(dbhan: any): {
|
|
57
|
+
database: any;
|
|
58
|
+
engine: any;
|
|
59
|
+
conid: any;
|
|
60
|
+
};
|
|
56
61
|
};
|
package/lib/driverBase.js
CHANGED
|
@@ -96,7 +96,7 @@ exports.driverBase = {
|
|
|
96
96
|
for (const sqlItem of (0, dbgate_query_splitter_1.splitQuery)(sql, this.getQuerySplitterOptions('script'))) {
|
|
97
97
|
try {
|
|
98
98
|
if (options === null || options === void 0 ? void 0 : options.logScriptItems) {
|
|
99
|
-
logger.info({ sql: (0, stringTools_1.getLimitedQuery)(sqlItem) }, 'Execute script item');
|
|
99
|
+
logger.info({ sql: (0, stringTools_1.getLimitedQuery)(sqlItem) }, 'DBGM-00131 Execute script item');
|
|
100
100
|
}
|
|
101
101
|
await this.query(pool, sqlItem, { discardResult: true, ...options === null || options === void 0 ? void 0 : options.queryOptions });
|
|
102
102
|
}
|
|
@@ -238,4 +238,11 @@ exports.driverBase = {
|
|
|
238
238
|
async writeQueryFromStream(dbhan, sql) {
|
|
239
239
|
return null;
|
|
240
240
|
},
|
|
241
|
+
getLogDbInfo(dbhan) {
|
|
242
|
+
return {
|
|
243
|
+
database: dbhan ? dbhan.database : undefined,
|
|
244
|
+
engine: this.engine,
|
|
245
|
+
conid: dbhan ? dbhan.conid : undefined,
|
|
246
|
+
};
|
|
247
|
+
},
|
|
241
248
|
};
|
package/lib/schemaInfoTools.d.ts
CHANGED
|
@@ -7,7 +7,6 @@ export declare function splitCompositeDbName(name: string): {
|
|
|
7
7
|
};
|
|
8
8
|
export declare function extractDbNameFromComposite(name: string): string;
|
|
9
9
|
export declare function extractSchemaNameFromComposite(name: string): string;
|
|
10
|
-
export declare function dbNameLogCategory(database: string): string;
|
|
11
10
|
export declare function compositeDbNameIfNeeded(connnection: {
|
|
12
11
|
useSeparateSchemas: boolean;
|
|
13
12
|
}, database: string, schema: string): string;
|
package/lib/schemaInfoTools.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.compositeDbNameIfNeeded = exports.
|
|
3
|
+
exports.compositeDbNameIfNeeded = exports.extractSchemaNameFromComposite = exports.extractDbNameFromComposite = exports.splitCompositeDbName = exports.isCompositeDbName = exports.findDefaultSchema = void 0;
|
|
4
4
|
function findDefaultSchema(schemaList, dialect, schemaInStorage = null) {
|
|
5
5
|
var _a;
|
|
6
6
|
if (!schemaList) {
|
|
@@ -39,16 +39,15 @@ function extractSchemaNameFromComposite(name) {
|
|
|
39
39
|
return (_a = splitCompositeDbName(name)) === null || _a === void 0 ? void 0 : _a.schema;
|
|
40
40
|
}
|
|
41
41
|
exports.extractSchemaNameFromComposite = extractSchemaNameFromComposite;
|
|
42
|
-
function
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
}
|
|
51
|
-
exports.dbNameLogCategory = dbNameLogCategory;
|
|
42
|
+
// export function getDbNameLogFace(database: string): string {
|
|
43
|
+
// if (isCompositeDbName(database)) {
|
|
44
|
+
// return '~composite';
|
|
45
|
+
// }
|
|
46
|
+
// if (database) {
|
|
47
|
+
// return '~simple';
|
|
48
|
+
// }
|
|
49
|
+
// return '~nodb';
|
|
50
|
+
// }
|
|
52
51
|
function compositeDbNameIfNeeded(connnection, database, schema) {
|
|
53
52
|
if (connnection === null || connnection === void 0 ? void 0 : connnection.useSeparateSchemas) {
|
|
54
53
|
return `${database}::${schema}`;
|
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "6.6.
|
|
2
|
+
"version": "6.6.1",
|
|
3
3
|
"name": "dbgate-tools",
|
|
4
4
|
"main": "lib/index.js",
|
|
5
5
|
"typings": "lib/index.d.ts",
|
|
@@ -26,18 +26,18 @@
|
|
|
26
26
|
],
|
|
27
27
|
"devDependencies": {
|
|
28
28
|
"@types/node": "^13.7.0",
|
|
29
|
-
"dbgate-types": "^6.6.
|
|
29
|
+
"dbgate-types": "^6.6.1",
|
|
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.6.
|
|
36
|
+
"dbgate-sqltree": "^6.6.1",
|
|
37
37
|
"debug": "^4.3.4",
|
|
38
38
|
"json-stable-stringify": "^1.0.1",
|
|
39
39
|
"lodash": "^4.17.21",
|
|
40
|
-
"pinomin": "^1.0.
|
|
40
|
+
"pinomin": "^1.0.5",
|
|
41
41
|
"toposort": "^2.0.2",
|
|
42
42
|
"uuid": "^3.4.0"
|
|
43
43
|
}
|