dbgate-api 5.5.2 → 5.5.3
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/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dbgate-api",
|
|
3
3
|
"main": "src/index.js",
|
|
4
|
-
"version": "5.5.
|
|
4
|
+
"version": "5.5.3",
|
|
5
5
|
"homepage": "https://dbgate.org/",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
@@ -26,10 +26,10 @@
|
|
|
26
26
|
"compare-versions": "^3.6.0",
|
|
27
27
|
"cors": "^2.8.5",
|
|
28
28
|
"cross-env": "^6.0.3",
|
|
29
|
-
"dbgate-datalib": "^5.5.
|
|
30
|
-
"dbgate-query-splitter": "^4.10.
|
|
31
|
-
"dbgate-sqltree": "^5.5.
|
|
32
|
-
"dbgate-tools": "^5.5.
|
|
29
|
+
"dbgate-datalib": "^5.5.3",
|
|
30
|
+
"dbgate-query-splitter": "^4.10.5",
|
|
31
|
+
"dbgate-sqltree": "^5.5.3",
|
|
32
|
+
"dbgate-tools": "^5.5.3",
|
|
33
33
|
"debug": "^4.3.4",
|
|
34
34
|
"diff": "^5.0.0",
|
|
35
35
|
"diff2html": "^3.4.13",
|
|
@@ -75,7 +75,7 @@
|
|
|
75
75
|
"devDependencies": {
|
|
76
76
|
"@types/fs-extra": "^9.0.11",
|
|
77
77
|
"@types/lodash": "^4.14.149",
|
|
78
|
-
"dbgate-types": "^5.5.
|
|
78
|
+
"dbgate-types": "^5.5.3",
|
|
79
79
|
"env-cmd": "^10.1.0",
|
|
80
80
|
"node-loader": "^1.0.2",
|
|
81
81
|
"nodemon": "^2.0.2",
|
package/src/currentVersion.js
CHANGED
|
@@ -1,7 +1,13 @@
|
|
|
1
1
|
const stableStringify = require('json-stable-stringify');
|
|
2
2
|
const { splitQuery } = require('dbgate-query-splitter');
|
|
3
3
|
const childProcessChecker = require('../utility/childProcessChecker');
|
|
4
|
-
const {
|
|
4
|
+
const {
|
|
5
|
+
extractBoolSettingsValue,
|
|
6
|
+
extractIntSettingsValue,
|
|
7
|
+
getLogger,
|
|
8
|
+
isCompositeDbName,
|
|
9
|
+
dbNameLogCategory,
|
|
10
|
+
} = require('dbgate-tools');
|
|
5
11
|
const requireEngineDriver = require('../utility/requireEngineDriver');
|
|
6
12
|
const connectUtility = require('../utility/connectUtility');
|
|
7
13
|
const { handleProcessCommunication } = require('../utility/processComm');
|
|
@@ -28,6 +34,25 @@ function getStatusCounter() {
|
|
|
28
34
|
return statusCounter;
|
|
29
35
|
}
|
|
30
36
|
|
|
37
|
+
function extractErrorMessage(err, defaultMessage) {
|
|
38
|
+
if (!err) {
|
|
39
|
+
return defaultMessage;
|
|
40
|
+
}
|
|
41
|
+
if (err.errors) {
|
|
42
|
+
try {
|
|
43
|
+
return err.errors.map(x => x.message).join('\n');
|
|
44
|
+
} catch (e2) {}
|
|
45
|
+
}
|
|
46
|
+
if (err.message) {
|
|
47
|
+
return err.message;
|
|
48
|
+
}
|
|
49
|
+
const s = `${err}`;
|
|
50
|
+
if (s && (!s.endsWith('Error') || s.includes(' '))) {
|
|
51
|
+
return s;
|
|
52
|
+
}
|
|
53
|
+
return defaultMessage;
|
|
54
|
+
}
|
|
55
|
+
|
|
31
56
|
async function checkedAsyncCall(promise) {
|
|
32
57
|
try {
|
|
33
58
|
const res = await promise;
|
|
@@ -35,7 +60,7 @@ async function checkedAsyncCall(promise) {
|
|
|
35
60
|
} catch (err) {
|
|
36
61
|
setStatus({
|
|
37
62
|
name: 'error',
|
|
38
|
-
message: err
|
|
63
|
+
message: extractErrorMessage(err, 'Checked call error'),
|
|
39
64
|
});
|
|
40
65
|
// console.error(err);
|
|
41
66
|
setTimeout(() => process.exit(1), 1000);
|
|
@@ -46,6 +71,12 @@ async function checkedAsyncCall(promise) {
|
|
|
46
71
|
let loadingModel = false;
|
|
47
72
|
|
|
48
73
|
async function handleFullRefresh() {
|
|
74
|
+
if (storedConnection.useSeparateSchemas && !isCompositeDbName(dbhan?.database)) {
|
|
75
|
+
resolveAnalysedPromises();
|
|
76
|
+
// skip loading DB structure
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
|
|
49
80
|
loadingModel = true;
|
|
50
81
|
const driver = requireEngineDriver(storedConnection);
|
|
51
82
|
setStatusName('loadStructure');
|
|
@@ -60,6 +91,11 @@ async function handleFullRefresh() {
|
|
|
60
91
|
}
|
|
61
92
|
|
|
62
93
|
async function handleIncrementalRefresh(forceSend) {
|
|
94
|
+
if (storedConnection.useSeparateSchemas && !isCompositeDbName(dbhan?.database)) {
|
|
95
|
+
resolveAnalysedPromises();
|
|
96
|
+
// skip loading DB structure
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
63
99
|
loadingModel = true;
|
|
64
100
|
const driver = requireEngineDriver(storedConnection);
|
|
65
101
|
setStatusName('checkStructure');
|
|
@@ -102,6 +138,7 @@ function setStatusName(name) {
|
|
|
102
138
|
async function readVersion() {
|
|
103
139
|
const driver = requireEngineDriver(storedConnection);
|
|
104
140
|
const version = await driver.getVersion(dbhan);
|
|
141
|
+
logger.debug(`Got server version: ${version.version}`);
|
|
105
142
|
process.send({ msgtype: 'version', version });
|
|
106
143
|
serverVersion = version;
|
|
107
144
|
}
|
|
@@ -113,6 +150,11 @@ async function handleConnect({ connection, structure, globalSettings }) {
|
|
|
113
150
|
if (!structure) setStatusName('pending');
|
|
114
151
|
const driver = requireEngineDriver(storedConnection);
|
|
115
152
|
dbhan = await checkedAsyncCall(connectUtility(driver, storedConnection, 'app'));
|
|
153
|
+
logger.debug(
|
|
154
|
+
`Connected to database, driver: ${storedConnection.engine}, separate schemas: ${
|
|
155
|
+
storedConnection.useSeparateSchemas ? 'YES' : 'NO'
|
|
156
|
+
}, 'DB: ${dbNameLogCategory(dbhan.database)} }`
|
|
157
|
+
);
|
|
116
158
|
dbhan.feedback = feedback => setStatus({ feedback });
|
|
117
159
|
await checkedAsyncCall(readVersion());
|
|
118
160
|
if (structure) {
|
|
@@ -164,7 +206,11 @@ async function handleRunScript({ msgid, sql, useTransaction }, skipReadonlyCheck
|
|
|
164
206
|
await driver.script(dbhan, sql, { useTransaction });
|
|
165
207
|
process.send({ msgtype: 'response', msgid });
|
|
166
208
|
} catch (err) {
|
|
167
|
-
process.send({
|
|
209
|
+
process.send({
|
|
210
|
+
msgtype: 'response',
|
|
211
|
+
msgid,
|
|
212
|
+
errorMessage: extractErrorMessage(err, 'Error executing SQL script'),
|
|
213
|
+
});
|
|
168
214
|
}
|
|
169
215
|
}
|
|
170
216
|
|
|
@@ -176,7 +222,11 @@ async function handleRunOperation({ msgid, operation, useTransaction }, skipRead
|
|
|
176
222
|
await driver.operation(dbhan, operation, { useTransaction });
|
|
177
223
|
process.send({ msgtype: 'response', msgid });
|
|
178
224
|
} catch (err) {
|
|
179
|
-
process.send({
|
|
225
|
+
process.send({
|
|
226
|
+
msgtype: 'response',
|
|
227
|
+
msgid,
|
|
228
|
+
errorMessage: extractErrorMessage(err, 'Error executing DB operation'),
|
|
229
|
+
});
|
|
180
230
|
}
|
|
181
231
|
}
|
|
182
232
|
|
|
@@ -189,7 +239,11 @@ async function handleQueryData({ msgid, sql }, skipReadonlyCheck = false) {
|
|
|
189
239
|
const res = await driver.query(dbhan, sql);
|
|
190
240
|
process.send({ msgtype: 'response', msgid, ...res });
|
|
191
241
|
} catch (err) {
|
|
192
|
-
process.send({
|
|
242
|
+
process.send({
|
|
243
|
+
msgtype: 'response',
|
|
244
|
+
msgid,
|
|
245
|
+
errorMessage: extractErrorMessage(err, 'Error executing SQL script'),
|
|
246
|
+
});
|
|
193
247
|
}
|
|
194
248
|
}
|
|
195
249
|
|
|
@@ -208,7 +262,7 @@ async function handleDriverDataCore(msgid, callMethod, { logName }) {
|
|
|
208
262
|
process.send({ msgtype: 'response', msgid, result });
|
|
209
263
|
} catch (err) {
|
|
210
264
|
logger.error(err, `Error when handling message ${logName}`);
|
|
211
|
-
process.send({ msgtype: 'response', msgid, errorMessage: err
|
|
265
|
+
process.send({ msgtype: 'response', msgid, errorMessage: extractErrorMessage(err, 'Error executing DB data') });
|
|
212
266
|
}
|
|
213
267
|
}
|
|
214
268
|
|
|
@@ -277,7 +331,7 @@ async function handleUpdateCollection({ msgid, changeSet }) {
|
|
|
277
331
|
const result = await driver.updateCollection(dbhan, changeSet);
|
|
278
332
|
process.send({ msgtype: 'response', msgid, result });
|
|
279
333
|
} catch (err) {
|
|
280
|
-
process.send({ msgtype: 'response', msgid, errorMessage: err
|
|
334
|
+
process.send({ msgtype: 'response', msgid, errorMessage: extractErrorMessage(err, 'Error updating collection') });
|
|
281
335
|
}
|
|
282
336
|
}
|
|
283
337
|
|
|
@@ -298,7 +352,12 @@ async function handleSqlPreview({ msgid, objects, options }) {
|
|
|
298
352
|
}, 500);
|
|
299
353
|
}
|
|
300
354
|
} catch (err) {
|
|
301
|
-
process.send({
|
|
355
|
+
process.send({
|
|
356
|
+
msgtype: 'response',
|
|
357
|
+
msgid,
|
|
358
|
+
isError: true,
|
|
359
|
+
errorMessage: extractErrorMessage(err, 'Error generating SQL preview'),
|
|
360
|
+
});
|
|
302
361
|
}
|
|
303
362
|
}
|
|
304
363
|
|
|
@@ -314,7 +373,12 @@ async function handleGenerateDeploySql({ msgid, modelFolder }) {
|
|
|
314
373
|
});
|
|
315
374
|
process.send({ ...res, msgtype: 'response', msgid });
|
|
316
375
|
} catch (err) {
|
|
317
|
-
process.send({
|
|
376
|
+
process.send({
|
|
377
|
+
msgtype: 'response',
|
|
378
|
+
msgid,
|
|
379
|
+
isError: true,
|
|
380
|
+
errorMessage: extractErrorMessage(err, 'Error generating deploy SQL'),
|
|
381
|
+
});
|
|
318
382
|
}
|
|
319
383
|
}
|
|
320
384
|
|
|
@@ -373,7 +437,7 @@ function start() {
|
|
|
373
437
|
await handleMessage(message);
|
|
374
438
|
} catch (err) {
|
|
375
439
|
logger.error({ err }, 'Error in DB connection');
|
|
376
|
-
process.send({ msgtype: 'error', error: err
|
|
440
|
+
process.send({ msgtype: 'error', error: extractErrorMessage(err, 'Error processing message') });
|
|
377
441
|
}
|
|
378
442
|
});
|
|
379
443
|
}
|
|
@@ -9,14 +9,28 @@ const { getLogger } = require('dbgate-tools');
|
|
|
9
9
|
const logger = getLogger('importDb');
|
|
10
10
|
|
|
11
11
|
class ImportStream extends stream.Transform {
|
|
12
|
-
constructor(
|
|
12
|
+
constructor(dbhan, driver) {
|
|
13
13
|
super({ objectMode: true });
|
|
14
|
-
this.
|
|
14
|
+
this.dbhan = dbhan;
|
|
15
15
|
this.driver = driver;
|
|
16
|
+
this.writeQueryStream = null;
|
|
16
17
|
}
|
|
17
18
|
async _transform(chunk, encoding, cb) {
|
|
18
19
|
try {
|
|
19
|
-
|
|
20
|
+
if (chunk.specialMarker == 'copy_stdin_start') {
|
|
21
|
+
this.writeQueryStream = await this.driver.writeQueryFromStream(this.dbhan, chunk.text);
|
|
22
|
+
} else if (chunk.specialMarker == 'copy_stdin_line') {
|
|
23
|
+
this.writeQueryStream.write(chunk.text);
|
|
24
|
+
} else if (chunk.specialMarker == 'copy_stdin_end') {
|
|
25
|
+
this.writeQueryStream.end();
|
|
26
|
+
await new Promise((resolve, reject) => {
|
|
27
|
+
this.writeQueryStream.on('finish', resolve);
|
|
28
|
+
this.writeQueryStream.on('error', reject);
|
|
29
|
+
});
|
|
30
|
+
this.writeQueryStream = null;
|
|
31
|
+
} else {
|
|
32
|
+
await this.driver.script(this.dbhan, chunk.text, { queryOptions: { importSqlDump: true } });
|
|
33
|
+
}
|
|
20
34
|
} catch (err) {
|
|
21
35
|
this.emit('error', err.message);
|
|
22
36
|
}
|
|
@@ -44,7 +58,7 @@ async function importDatabase({ connection = undefined, systemConnection = undef
|
|
|
44
58
|
logger.info(`Importing database`);
|
|
45
59
|
|
|
46
60
|
if (!driver) driver = requireEngineDriver(connection);
|
|
47
|
-
const
|
|
61
|
+
const dbhan = systemConnection || (await connectUtility(driver, connection, 'write'));
|
|
48
62
|
logger.info(`Connected.`);
|
|
49
63
|
|
|
50
64
|
logger.info(`Input file: ${inputFile}`);
|
|
@@ -52,8 +66,11 @@ async function importDatabase({ connection = undefined, systemConnection = undef
|
|
|
52
66
|
logger.info(`Downloaded file: ${downloadedFile}`);
|
|
53
67
|
|
|
54
68
|
const fileStream = fs.createReadStream(downloadedFile, 'utf-8');
|
|
55
|
-
const splittedStream = splitQueryStream(fileStream,
|
|
56
|
-
|
|
69
|
+
const splittedStream = splitQueryStream(fileStream, {
|
|
70
|
+
...driver.getQuerySplitterOptions('import'),
|
|
71
|
+
returnRichInfo: true,
|
|
72
|
+
});
|
|
73
|
+
const importStream = new ImportStream(dbhan, driver);
|
|
57
74
|
// @ts-ignore
|
|
58
75
|
splittedStream.pipe(importStream);
|
|
59
76
|
await awaitStreamEnd(importStream);
|