dbgate-tools 6.6.3 → 6.6.4
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 +4 -0
- package/lib/DatabaseAnalyser.js +43 -23
- package/lib/nameTools.d.ts +4 -0
- package/lib/nameTools.js +17 -1
- package/lib/stringTools.d.ts +1 -0
- package/lib/stringTools.js +16 -1
- package/lib/testPermission.js +18 -2
- package/package.json +5 -4
|
@@ -9,12 +9,16 @@ export declare class DatabaseAnalyser<TClient = any> {
|
|
|
9
9
|
singleObjectId: string;
|
|
10
10
|
dialect: SqlDialect;
|
|
11
11
|
logger: Logger;
|
|
12
|
+
startedTm: number;
|
|
13
|
+
analyseIdentifier: string;
|
|
12
14
|
constructor(dbhan: DatabaseHandle<TClient>, driver: EngineDriver, version: any);
|
|
13
15
|
_runAnalysis(): Promise<DatabaseInfo>;
|
|
14
16
|
_getFastSnapshot(): Promise<DatabaseInfo>;
|
|
15
17
|
_computeSingleObjectId(): Promise<void>;
|
|
16
18
|
addEngineField(db: DatabaseInfo): DatabaseInfo;
|
|
17
19
|
getLogDbInfo(): {
|
|
20
|
+
analyserTime: number;
|
|
21
|
+
analyseIdentifier: string;
|
|
18
22
|
database?: string;
|
|
19
23
|
engine: string;
|
|
20
24
|
conid?: string;
|
package/lib/DatabaseAnalyser.js
CHANGED
|
@@ -49,6 +49,8 @@ class DatabaseAnalyser {
|
|
|
49
49
|
this.dbhan = dbhan;
|
|
50
50
|
this.driver = driver;
|
|
51
51
|
this.singleObjectId = null;
|
|
52
|
+
this.startedTm = Date.now();
|
|
53
|
+
this.analyseIdentifier = Math.random().toString().substring(2);
|
|
52
54
|
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);
|
|
53
55
|
this.logger = logger;
|
|
54
56
|
}
|
|
@@ -74,13 +76,24 @@ class DatabaseAnalyser {
|
|
|
74
76
|
return db;
|
|
75
77
|
}
|
|
76
78
|
getLogDbInfo() {
|
|
77
|
-
return
|
|
79
|
+
return {
|
|
80
|
+
...this.driver.getLogDbInfo(this.dbhan),
|
|
81
|
+
analyserTime: Date.now() - this.startedTm,
|
|
82
|
+
analyseIdentifier: this.analyseIdentifier,
|
|
83
|
+
};
|
|
78
84
|
}
|
|
79
85
|
async fullAnalysis() {
|
|
80
86
|
logger.debug(this.getLogDbInfo(), 'DBGM-00126 Performing full analysis');
|
|
81
|
-
|
|
87
|
+
try {
|
|
88
|
+
const res = this.addEngineField(await this._runAnalysis());
|
|
89
|
+
logger.debug(this.getLogDbInfo(), 'DBGM-00271 Full analysis finished successfully');
|
|
90
|
+
return res;
|
|
91
|
+
}
|
|
92
|
+
catch (err) {
|
|
93
|
+
logger.error((0, stringTools_1.extractErrorLogData)(err, this.getLogDbInfo()), 'DBGM-00272 Error during full analysis');
|
|
94
|
+
throw err;
|
|
95
|
+
}
|
|
82
96
|
// console.log('FULL ANALYSIS', res);
|
|
83
|
-
return res;
|
|
84
97
|
}
|
|
85
98
|
async singleObjectAnalysis(name, typeField) {
|
|
86
99
|
var _a, _b, _c;
|
|
@@ -98,29 +111,36 @@ class DatabaseAnalyser {
|
|
|
98
111
|
async incrementalAnalysis(structure) {
|
|
99
112
|
logger.info(this.getLogDbInfo(), 'DBGM-00127 Performing incremental analysis');
|
|
100
113
|
this.structure = structure;
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
const structureModifications = modifications.filter(x => x.action != 'setTableRowCounts');
|
|
108
|
-
const setTableRowCounts = modifications.find(x => x.action == 'setTableRowCounts');
|
|
109
|
-
let structureWithRowCounts = null;
|
|
110
|
-
if (setTableRowCounts) {
|
|
111
|
-
const newStructure = mergeTableRowCounts(structure, setTableRowCounts.rowCounts);
|
|
112
|
-
if (areDifferentRowCounts(structure, newStructure)) {
|
|
113
|
-
structureWithRowCounts = newStructure;
|
|
114
|
+
try {
|
|
115
|
+
const modifications = await this.getModifications();
|
|
116
|
+
if (modifications == null) {
|
|
117
|
+
// modifications not implemented, perform full analysis
|
|
118
|
+
this.structure = null;
|
|
119
|
+
return this.addEngineField(await this._runAnalysis());
|
|
114
120
|
}
|
|
121
|
+
const structureModifications = modifications.filter(x => x.action != 'setTableRowCounts');
|
|
122
|
+
const setTableRowCounts = modifications.find(x => x.action == 'setTableRowCounts');
|
|
123
|
+
let structureWithRowCounts = null;
|
|
124
|
+
if (setTableRowCounts) {
|
|
125
|
+
const newStructure = mergeTableRowCounts(structure, setTableRowCounts.rowCounts);
|
|
126
|
+
if (areDifferentRowCounts(structure, newStructure)) {
|
|
127
|
+
structureWithRowCounts = newStructure;
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
if (structureModifications.length == 0) {
|
|
131
|
+
logger.debug(this.getLogDbInfo(), 'DBGM-00267 No changes in database structure detected');
|
|
132
|
+
return structureWithRowCounts ? this.addEngineField(structureWithRowCounts) : null;
|
|
133
|
+
}
|
|
134
|
+
this.modifications = structureModifications;
|
|
135
|
+
if (structureWithRowCounts)
|
|
136
|
+
this.structure = structureWithRowCounts;
|
|
137
|
+
logger.info({ ...this.getLogDbInfo(), modifications: this.modifications }, 'DBGM-00128 DB modifications detected');
|
|
138
|
+
return this.addEngineField(this.mergeAnalyseResult(await this._runAnalysis()));
|
|
115
139
|
}
|
|
116
|
-
|
|
117
|
-
|
|
140
|
+
catch (err) {
|
|
141
|
+
logger.error((0, stringTools_1.extractErrorLogData)(err, this.getLogDbInfo()), 'DBGM-00273 Error during incremental analysis');
|
|
142
|
+
throw err;
|
|
118
143
|
}
|
|
119
|
-
this.modifications = structureModifications;
|
|
120
|
-
if (structureWithRowCounts)
|
|
121
|
-
this.structure = structureWithRowCounts;
|
|
122
|
-
logger.info({ ...this.getLogDbInfo(), modifications: this.modifications }, 'DBGM-00128 DB modifications detected');
|
|
123
|
-
return this.addEngineField(this.mergeAnalyseResult(await this._runAnalysis()));
|
|
124
144
|
}
|
|
125
145
|
mergeAnalyseResult(newlyAnalysed) {
|
|
126
146
|
if (this.structure == null) {
|
package/lib/nameTools.d.ts
CHANGED
|
@@ -24,3 +24,7 @@ export declare function findObjectLike({ pureName, schemaName }: {
|
|
|
24
24
|
export declare function findForeignKeyForColumn(table: TableInfo, column: ColumnInfo | string): import("dbgate-types").ForeignKeyInfo;
|
|
25
25
|
export declare function makeUniqueColumnNames(res: ColumnInfo[]): void;
|
|
26
26
|
export declare function fillConstraintNames(table: TableInfo, dialect: SqlDialect): TableInfo;
|
|
27
|
+
export declare const DATA_FOLDER_NAMES: {
|
|
28
|
+
name: string;
|
|
29
|
+
label: string;
|
|
30
|
+
}[];
|
package/lib/nameTools.js
CHANGED
|
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.fillConstraintNames = exports.makeUniqueColumnNames = exports.findForeignKeyForColumn = exports.findObjectLike = exports.equalFullName = exports.equalStringLike = exports.quoteFullName = exports.fullNameToLabel = exports.fullNameToString = exports.fullNameFromString = void 0;
|
|
6
|
+
exports.DATA_FOLDER_NAMES = exports.fillConstraintNames = exports.makeUniqueColumnNames = exports.findForeignKeyForColumn = exports.findObjectLike = exports.equalFullName = exports.equalStringLike = exports.quoteFullName = exports.fullNameToLabel = exports.fullNameToString = exports.fullNameFromString = void 0;
|
|
7
7
|
const cloneDeep_1 = __importDefault(require("lodash/cloneDeep"));
|
|
8
8
|
const isString_1 = __importDefault(require("lodash/isString"));
|
|
9
9
|
function fullNameFromString(name) {
|
|
@@ -110,3 +110,19 @@ function fillConstraintNames(table, dialect) {
|
|
|
110
110
|
return res;
|
|
111
111
|
}
|
|
112
112
|
exports.fillConstraintNames = fillConstraintNames;
|
|
113
|
+
exports.DATA_FOLDER_NAMES = [
|
|
114
|
+
{ name: 'sql', label: 'SQL scripts' },
|
|
115
|
+
{ name: 'shell', label: 'Shell scripts' },
|
|
116
|
+
{ name: 'markdown', label: 'Markdown files' },
|
|
117
|
+
{ name: 'charts', label: 'Charts' },
|
|
118
|
+
{ name: 'query', label: 'Query designs' },
|
|
119
|
+
{ name: 'sqlite', label: 'SQLite files' },
|
|
120
|
+
{ name: 'duckdb', label: 'DuckDB files' },
|
|
121
|
+
{ name: 'diagrams', label: 'Diagrams' },
|
|
122
|
+
{ name: 'perspectives', label: 'Perspectives' },
|
|
123
|
+
{ name: 'impexp', label: 'Import/Export jobs' },
|
|
124
|
+
{ name: 'modtrans', label: 'Model transforms' },
|
|
125
|
+
{ name: 'datadeploy', label: 'Data deploy jobs' },
|
|
126
|
+
{ name: 'dbcompare', label: 'Database compare jobs' },
|
|
127
|
+
{ name: 'apps', label: 'Applications' },
|
|
128
|
+
];
|
package/lib/stringTools.d.ts
CHANGED
|
@@ -48,3 +48,4 @@ export declare function removeSqlFrontMatter(text: string): string;
|
|
|
48
48
|
export declare function setSqlFrontMatter(text: string, data: {
|
|
49
49
|
[key: string]: any;
|
|
50
50
|
}, yamlModule: any): string;
|
|
51
|
+
export declare function shortenIdentifier(s: string, maxLength?: number): string;
|
package/lib/stringTools.js
CHANGED
|
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
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;
|
|
6
|
+
exports.shortenIdentifier = 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;
|
|
7
7
|
const isString_1 = __importDefault(require("lodash/isString"));
|
|
8
8
|
const isArray_1 = __importDefault(require("lodash/isArray"));
|
|
9
9
|
const isDate_1 = __importDefault(require("lodash/isDate"));
|
|
@@ -14,6 +14,7 @@ const cloneDeepWith_1 = __importDefault(require("lodash/cloneDeepWith"));
|
|
|
14
14
|
const isEmpty_1 = __importDefault(require("lodash/isEmpty"));
|
|
15
15
|
const omitBy_1 = __importDefault(require("lodash/omitBy"));
|
|
16
16
|
const isPlainObject_2 = __importDefault(require("lodash/isPlainObject"));
|
|
17
|
+
const blueimp_md5_1 = __importDefault(require("blueimp-md5"));
|
|
17
18
|
exports.MAX_GRID_TEXT_LENGTH = 1000; // maximum length of text in grid cell, longer text is truncated
|
|
18
19
|
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]))$/;
|
|
19
20
|
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]))$/;
|
|
@@ -344,6 +345,9 @@ function safeJsonParse(json, defaultValue, logError = false) {
|
|
|
344
345
|
if ((0, isArray_1.default)(json) || (0, isPlainObject_1.default)(json)) {
|
|
345
346
|
return json;
|
|
346
347
|
}
|
|
348
|
+
if (!json) {
|
|
349
|
+
return defaultValue;
|
|
350
|
+
}
|
|
347
351
|
try {
|
|
348
352
|
return JSON.parse(json);
|
|
349
353
|
}
|
|
@@ -706,3 +710,14 @@ function setSqlFrontMatter(text, data, yamlModule) {
|
|
|
706
710
|
return frontMatterContent + (textClean || '');
|
|
707
711
|
}
|
|
708
712
|
exports.setSqlFrontMatter = setSqlFrontMatter;
|
|
713
|
+
function shortenIdentifier(s, maxLength) {
|
|
714
|
+
if (!maxLength || maxLength < 10)
|
|
715
|
+
return s;
|
|
716
|
+
if (s.length <= maxLength)
|
|
717
|
+
return s;
|
|
718
|
+
const hash = (0, blueimp_md5_1.default)(s).substring(0, 8);
|
|
719
|
+
const partLength = Math.floor((maxLength - 9) / 2);
|
|
720
|
+
const restLength = maxLength - 10 - partLength;
|
|
721
|
+
return s.substring(0, partLength) + '_' + hash + '_' + s.substring(s.length - restLength);
|
|
722
|
+
}
|
|
723
|
+
exports.shortenIdentifier = shortenIdentifier;
|
package/lib/testPermission.js
CHANGED
|
@@ -97,9 +97,25 @@ function getPredefinedPermissions(predefinedRoleName) {
|
|
|
97
97
|
case 'superadmin':
|
|
98
98
|
return ['*', '~widgets/*', 'widgets/admin', 'widgets/database', '~all-connections'];
|
|
99
99
|
case 'logged-user':
|
|
100
|
-
return [
|
|
100
|
+
return [
|
|
101
|
+
'*',
|
|
102
|
+
'~widgets/admin',
|
|
103
|
+
'~admin/*',
|
|
104
|
+
'~internal-storage',
|
|
105
|
+
'~all-connections',
|
|
106
|
+
'~run-shell-script',
|
|
107
|
+
'~all-team-files/*',
|
|
108
|
+
];
|
|
101
109
|
case 'anonymous-user':
|
|
102
|
-
return [
|
|
110
|
+
return [
|
|
111
|
+
'*',
|
|
112
|
+
'~widgets/admin',
|
|
113
|
+
'~admin/*',
|
|
114
|
+
'~internal-storage',
|
|
115
|
+
'~all-connections',
|
|
116
|
+
'~run-shell-script',
|
|
117
|
+
'~all-team-files/*',
|
|
118
|
+
];
|
|
103
119
|
default:
|
|
104
120
|
return null;
|
|
105
121
|
}
|
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "6.6.
|
|
2
|
+
"version": "6.6.4",
|
|
3
3
|
"name": "dbgate-tools",
|
|
4
4
|
"main": "lib/index.js",
|
|
5
5
|
"typings": "lib/index.d.ts",
|
|
@@ -26,14 +26,15 @@
|
|
|
26
26
|
],
|
|
27
27
|
"devDependencies": {
|
|
28
28
|
"@types/node": "^13.7.0",
|
|
29
|
-
"dbgate-types": "^6.6.
|
|
29
|
+
"dbgate-types": "^6.6.4",
|
|
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
|
-
"
|
|
36
|
-
"dbgate-
|
|
35
|
+
"blueimp-md5": "^2.19.0",
|
|
36
|
+
"dbgate-query-splitter": "^4.11.7",
|
|
37
|
+
"dbgate-sqltree": "^6.6.4",
|
|
37
38
|
"debug": "^4.3.4",
|
|
38
39
|
"json-stable-stringify": "^1.0.1",
|
|
39
40
|
"lodash": "^4.17.21",
|