dbgate-api 5.5.4-alpha.1 → 5.5.4-alpha.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 +5 -5
- package/src/currentVersion.js +2 -2
- package/src/shell/dataDuplicator.js +29 -22
- package/src/shell/dumpDatabase.js +16 -8
- package/src/shell/executeQuery.js +10 -3
- package/src/shell/generateDeploySql.js +40 -32
- package/src/shell/importDatabase.js +19 -13
- package/src/shell/loadDatabase.js +11 -5
- package/src/shell/tableReader.js +8 -8
- package/src/shell/tableWriter.js +9 -3
- package/src/utility/connectUtility.js +12 -1
- package/src/utility/platformInfo.js +6 -2
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-alpha.
|
|
4
|
+
"version": "5.5.4-alpha.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.4-alpha.
|
|
29
|
+
"dbgate-datalib": "^5.5.4-alpha.3",
|
|
30
30
|
"dbgate-query-splitter": "^4.10.5",
|
|
31
|
-
"dbgate-sqltree": "^5.5.4-alpha.
|
|
32
|
-
"dbgate-tools": "^5.5.4-alpha.
|
|
31
|
+
"dbgate-sqltree": "^5.5.4-alpha.3",
|
|
32
|
+
"dbgate-tools": "^5.5.4-alpha.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.4-alpha.
|
|
78
|
+
"dbgate-types": "^5.5.4-alpha.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
|
@@ -19,32 +19,39 @@ async function dataDuplicator({
|
|
|
19
19
|
systemConnection,
|
|
20
20
|
}) {
|
|
21
21
|
if (!driver) driver = requireEngineDriver(connection);
|
|
22
|
-
|
|
22
|
+
|
|
23
|
+
const dbhan = systemConnection || (await connectUtility(driver, connection, 'write'));
|
|
23
24
|
|
|
24
|
-
|
|
25
|
+
try {
|
|
26
|
+
logger.info(`Connected.`);
|
|
25
27
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
28
|
+
if (!analysedStructure) {
|
|
29
|
+
analysedStructure = await driver.analyseFull(dbhan);
|
|
30
|
+
}
|
|
29
31
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
32
|
+
const dupl = new DataDuplicator(
|
|
33
|
+
dbhan,
|
|
34
|
+
driver,
|
|
35
|
+
analysedStructure,
|
|
36
|
+
items.map(item => ({
|
|
37
|
+
name: item.name,
|
|
38
|
+
operation: item.operation,
|
|
39
|
+
matchColumns: item.matchColumns,
|
|
40
|
+
openStream:
|
|
41
|
+
item.openStream ||
|
|
42
|
+
(() => jsonLinesReader({ fileName: path.join(resolveArchiveFolder(archive), `${item.name}.jsonl`) })),
|
|
43
|
+
})),
|
|
44
|
+
stream,
|
|
45
|
+
copyStream,
|
|
46
|
+
options
|
|
47
|
+
);
|
|
46
48
|
|
|
47
|
-
|
|
49
|
+
await dupl.run();
|
|
50
|
+
} finally {
|
|
51
|
+
if (!systemConnection) {
|
|
52
|
+
await driver.close(dbhan);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
48
55
|
}
|
|
49
56
|
|
|
50
57
|
module.exports = dataDuplicator;
|
|
@@ -27,15 +27,23 @@ async function dumpDatabase({
|
|
|
27
27
|
logger.info(`Dumping database`);
|
|
28
28
|
|
|
29
29
|
if (!driver) driver = requireEngineDriver(connection);
|
|
30
|
-
const pool = systemConnection || (await connectUtility(driver, connection, 'read', { forceRowsAsObjects: true }));
|
|
31
|
-
logger.info(`Connected.`);
|
|
32
30
|
|
|
33
|
-
const
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
31
|
+
const dbhan = systemConnection || (await connectUtility(driver, connection, 'read', { forceRowsAsObjects: true }));
|
|
32
|
+
|
|
33
|
+
try {
|
|
34
|
+
logger.info(`Connected.`);
|
|
35
|
+
|
|
36
|
+
const dumper = await driver.createBackupDumper(dbhan, {
|
|
37
|
+
outputFile,
|
|
38
|
+
databaseName,
|
|
39
|
+
schemaName,
|
|
40
|
+
});
|
|
41
|
+
await doDump(dumper);
|
|
42
|
+
} finally {
|
|
43
|
+
if (!systemConnection) {
|
|
44
|
+
await driver.close(dbhan);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
39
47
|
}
|
|
40
48
|
|
|
41
49
|
module.exports = dumpDatabase;
|
|
@@ -8,10 +8,17 @@ async function executeQuery({ connection = undefined, systemConnection = undefin
|
|
|
8
8
|
logger.info({ sql }, `Execute query`);
|
|
9
9
|
|
|
10
10
|
if (!driver) driver = requireEngineDriver(connection);
|
|
11
|
-
const
|
|
12
|
-
logger.info(`Connected.`);
|
|
11
|
+
const dbhan = systemConnection || (await connectUtility(driver, connection, 'script'));
|
|
13
12
|
|
|
14
|
-
|
|
13
|
+
try {
|
|
14
|
+
logger.info(`Connected.`);
|
|
15
|
+
|
|
16
|
+
await driver.script(dbhan, sql);
|
|
17
|
+
} finally {
|
|
18
|
+
if (!systemConnection) {
|
|
19
|
+
await driver.close(dbhan);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
15
22
|
}
|
|
16
23
|
|
|
17
24
|
module.exports = executeQuery;
|
|
@@ -21,41 +21,49 @@ async function generateDeploySql({
|
|
|
21
21
|
}) {
|
|
22
22
|
if (!driver) driver = requireEngineDriver(connection);
|
|
23
23
|
|
|
24
|
-
const
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
24
|
+
const dbhan = systemConnection || (await connectUtility(driver, connection, 'read'));
|
|
25
|
+
|
|
26
|
+
try {
|
|
27
|
+
if (!analysedStructure) {
|
|
28
|
+
analysedStructure = await driver.analyseFull(dbhan);
|
|
29
|
+
}
|
|
28
30
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
31
|
+
const deployedModel = generateDbPairingId(
|
|
32
|
+
extendDatabaseInfo(loadedDbModel ? databaseInfoFromYamlModel(loadedDbModel) : await importDbModel(modelFolder))
|
|
33
|
+
);
|
|
34
|
+
const currentModel = generateDbPairingId(extendDatabaseInfo(analysedStructure));
|
|
35
|
+
const opts = {
|
|
36
|
+
...modelCompareDbDiffOptions,
|
|
35
37
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
38
|
+
noDropTable: true,
|
|
39
|
+
noDropColumn: true,
|
|
40
|
+
noDropConstraint: true,
|
|
41
|
+
noDropSqlObject: true,
|
|
42
|
+
noRenameTable: true,
|
|
43
|
+
noRenameColumn: true,
|
|
44
|
+
};
|
|
45
|
+
const currentModelPaired = matchPairedObjects(deployedModel, currentModel, opts);
|
|
46
|
+
const currentModelPairedPreloaded = await enrichWithPreloadedRows(deployedModel, currentModelPaired, dbhan, driver);
|
|
45
47
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
48
|
+
// console.log('currentModelPairedPreloaded', currentModelPairedPreloaded.tables[0]);
|
|
49
|
+
// console.log('deployedModel', deployedModel.tables[0]);
|
|
50
|
+
// console.log('currentModel', currentModel.tables[0]);
|
|
51
|
+
// console.log('currentModelPaired', currentModelPaired.tables[0]);
|
|
52
|
+
const res = getAlterDatabaseScript(
|
|
53
|
+
currentModelPairedPreloaded,
|
|
54
|
+
deployedModel,
|
|
55
|
+
opts,
|
|
56
|
+
currentModelPairedPreloaded,
|
|
57
|
+
deployedModel,
|
|
58
|
+
driver
|
|
59
|
+
);
|
|
60
|
+
|
|
61
|
+
return res;
|
|
62
|
+
} finally {
|
|
63
|
+
if (!systemConnection) {
|
|
64
|
+
await driver.close(dbhan);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
59
67
|
}
|
|
60
68
|
|
|
61
69
|
module.exports = generateDeploySql;
|
|
@@ -59,21 +59,27 @@ async function importDatabase({ connection = undefined, systemConnection = undef
|
|
|
59
59
|
|
|
60
60
|
if (!driver) driver = requireEngineDriver(connection);
|
|
61
61
|
const dbhan = systemConnection || (await connectUtility(driver, connection, 'write'));
|
|
62
|
-
|
|
62
|
+
try {
|
|
63
|
+
logger.info(`Connected.`);
|
|
63
64
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
65
|
+
logger.info(`Input file: ${inputFile}`);
|
|
66
|
+
const downloadedFile = await download(inputFile);
|
|
67
|
+
logger.info(`Downloaded file: ${downloadedFile}`);
|
|
67
68
|
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
69
|
+
const fileStream = fs.createReadStream(downloadedFile, 'utf-8');
|
|
70
|
+
const splittedStream = splitQueryStream(fileStream, {
|
|
71
|
+
...driver.getQuerySplitterOptions('import'),
|
|
72
|
+
returnRichInfo: true,
|
|
73
|
+
});
|
|
74
|
+
const importStream = new ImportStream(dbhan, driver);
|
|
75
|
+
// @ts-ignore
|
|
76
|
+
splittedStream.pipe(importStream);
|
|
77
|
+
await awaitStreamEnd(importStream);
|
|
78
|
+
} finally {
|
|
79
|
+
if (!systemConnection) {
|
|
80
|
+
await driver.close(dbhan);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
77
83
|
}
|
|
78
84
|
|
|
79
85
|
module.exports = importDatabase;
|
|
@@ -9,13 +9,19 @@ async function loadDatabase({ connection = undefined, systemConnection = undefin
|
|
|
9
9
|
logger.info(`Analysing database`);
|
|
10
10
|
|
|
11
11
|
if (!driver) driver = requireEngineDriver(connection);
|
|
12
|
-
const
|
|
13
|
-
|
|
12
|
+
const dbhan = systemConnection || (await connectUtility(driver, connection, 'read', { forceRowsAsObjects: true }));
|
|
13
|
+
try {
|
|
14
|
+
logger.info(`Connected.`);
|
|
14
15
|
|
|
15
|
-
|
|
16
|
-
|
|
16
|
+
const dbInfo = await driver.analyseFull(dbhan);
|
|
17
|
+
logger.info(`Analyse finished`);
|
|
17
18
|
|
|
18
|
-
|
|
19
|
+
await exportDbModel(dbInfo, outputDir);
|
|
20
|
+
} finally {
|
|
21
|
+
if (!systemConnection) {
|
|
22
|
+
await driver.close(dbhan);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
19
25
|
}
|
|
20
26
|
|
|
21
27
|
module.exports = loadDatabase;
|
package/src/shell/tableReader.js
CHANGED
|
@@ -3,9 +3,9 @@ const requireEngineDriver = require('../utility/requireEngineDriver');
|
|
|
3
3
|
const connectUtility = require('../utility/connectUtility');
|
|
4
4
|
const logger = getLogger('tableReader');
|
|
5
5
|
|
|
6
|
-
async function tableReader({ connection, pureName, schemaName }) {
|
|
6
|
+
async function tableReader({ connection, systemConnection, pureName, schemaName }) {
|
|
7
7
|
const driver = requireEngineDriver(connection);
|
|
8
|
-
const
|
|
8
|
+
const dbhan = systemConnection || (await connectUtility(driver, connection, 'read'));
|
|
9
9
|
logger.info(`Connected.`);
|
|
10
10
|
|
|
11
11
|
const fullName = { pureName, schemaName };
|
|
@@ -14,26 +14,26 @@ async function tableReader({ connection, pureName, schemaName }) {
|
|
|
14
14
|
// @ts-ignore
|
|
15
15
|
logger.info(`Reading collection ${fullNameToString(fullName)}`);
|
|
16
16
|
// @ts-ignore
|
|
17
|
-
return await driver.readQuery(
|
|
17
|
+
return await driver.readQuery(dbhan, JSON.stringify(fullName));
|
|
18
18
|
}
|
|
19
19
|
|
|
20
|
-
const table = await driver.analyseSingleObject(
|
|
20
|
+
const table = await driver.analyseSingleObject(dbhan, fullName, 'tables');
|
|
21
21
|
const query = `select * from ${quoteFullName(driver.dialect, fullName)}`;
|
|
22
22
|
if (table) {
|
|
23
23
|
// @ts-ignore
|
|
24
24
|
logger.info(`Reading table ${fullNameToString(table)}`);
|
|
25
25
|
// @ts-ignore
|
|
26
|
-
return await driver.readQuery(
|
|
26
|
+
return await driver.readQuery(dbhan, query, table);
|
|
27
27
|
}
|
|
28
|
-
const view = await driver.analyseSingleObject(
|
|
28
|
+
const view = await driver.analyseSingleObject(dbhan, fullName, 'views');
|
|
29
29
|
if (view) {
|
|
30
30
|
// @ts-ignore
|
|
31
31
|
logger.info(`Reading view ${fullNameToString(view)}`);
|
|
32
32
|
// @ts-ignore
|
|
33
|
-
return await driver.readQuery(
|
|
33
|
+
return await driver.readQuery(dbhan, query, view);
|
|
34
34
|
}
|
|
35
35
|
|
|
36
|
-
return await driver.readQuery(
|
|
36
|
+
return await driver.readQuery(dbhan, query);
|
|
37
37
|
}
|
|
38
38
|
|
|
39
39
|
module.exports = tableReader;
|
package/src/shell/tableWriter.js
CHANGED
|
@@ -9,10 +9,16 @@ async function tableWriter({ connection, schemaName, pureName, driver, systemCon
|
|
|
9
9
|
if (!driver) {
|
|
10
10
|
driver = requireEngineDriver(connection);
|
|
11
11
|
}
|
|
12
|
-
const
|
|
12
|
+
const dbhan = systemConnection || (await connectUtility(driver, connection, 'write'));
|
|
13
13
|
|
|
14
|
-
|
|
15
|
-
|
|
14
|
+
try {
|
|
15
|
+
logger.info(`Connected.`);
|
|
16
|
+
return await driver.writeTable(dbhan, { schemaName, pureName }, options);
|
|
17
|
+
} finally {
|
|
18
|
+
if (!systemConnection) {
|
|
19
|
+
await driver.close(dbhan);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
16
22
|
}
|
|
17
23
|
|
|
18
24
|
module.exports = tableWriter;
|
|
@@ -3,9 +3,10 @@ const { decryptConnection } = require('./crypting');
|
|
|
3
3
|
const { getSshTunnelProxy } = require('./sshTunnelProxy');
|
|
4
4
|
const platformInfo = require('../utility/platformInfo');
|
|
5
5
|
const connections = require('../controllers/connections');
|
|
6
|
+
const _ = require('lodash');
|
|
6
7
|
|
|
7
8
|
async function loadConnection(driver, storedConnection, connectionMode) {
|
|
8
|
-
const { allowShellConnection } = platformInfo;
|
|
9
|
+
const { allowShellConnection, allowConnectionFromEnvVariables } = platformInfo;
|
|
9
10
|
|
|
10
11
|
if (connectionMode == 'app') {
|
|
11
12
|
return storedConnection;
|
|
@@ -33,6 +34,16 @@ async function loadConnection(driver, storedConnection, connectionMode) {
|
|
|
33
34
|
}
|
|
34
35
|
return loadedWithDb;
|
|
35
36
|
}
|
|
37
|
+
|
|
38
|
+
if (allowConnectionFromEnvVariables) {
|
|
39
|
+
return _.mapValues(storedConnection, (value, key) => {
|
|
40
|
+
if (_.isString(value) && value.startsWith('$')) {
|
|
41
|
+
return process.env[value.substring(1)];
|
|
42
|
+
}
|
|
43
|
+
return value;
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
|
|
36
47
|
return storedConnection;
|
|
37
48
|
}
|
|
38
49
|
|
|
@@ -11,6 +11,7 @@ const isLinux = platform === 'linux';
|
|
|
11
11
|
const isDocker = fs.existsSync('/home/dbgate-docker/public');
|
|
12
12
|
const isDevMode = process.env.DEVMODE == '1';
|
|
13
13
|
const isNpmDist = !!global['IS_NPM_DIST'];
|
|
14
|
+
const isDbModel = !!global['IS_DB_MODEL'];
|
|
14
15
|
const isForkedApi = processArgs.isForkedApi;
|
|
15
16
|
|
|
16
17
|
// function moduleAvailable(name) {
|
|
@@ -39,8 +40,11 @@ const platformInfo = {
|
|
|
39
40
|
environment: process.env.NODE_ENV,
|
|
40
41
|
platform,
|
|
41
42
|
runningInWebpack: !!process.env.WEBPACK_DEV_SERVER_URL,
|
|
42
|
-
allowShellConnection:
|
|
43
|
-
|
|
43
|
+
allowShellConnection:
|
|
44
|
+
(!processArgs.listenApiChild && !isNpmDist) || !!process.env.SHELL_CONNECTION || !!isElectron() || !!isDbModel,
|
|
45
|
+
allowShellScripting:
|
|
46
|
+
(!processArgs.listenApiChild && !isNpmDist) || !!process.env.SHELL_SCRIPTING || !!isElectron() || !!isDbModel,
|
|
47
|
+
allowConnectionFromEnvVariables: !!isDbModel,
|
|
44
48
|
defaultKeyfile: path.join(os.homedir(), '.ssh/id_rsa'),
|
|
45
49
|
};
|
|
46
50
|
|