dbgate-api 5.5.4-alpha.2 → 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "dbgate-api",
3
3
  "main": "src/index.js",
4
- "version": "5.5.4-alpha.2",
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.2",
29
+ "dbgate-datalib": "^5.5.4-alpha.3",
30
30
  "dbgate-query-splitter": "^4.10.5",
31
- "dbgate-sqltree": "^5.5.4-alpha.2",
32
- "dbgate-tools": "^5.5.4-alpha.2",
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.2",
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",
@@ -1,5 +1,5 @@
1
1
 
2
2
  module.exports = {
3
- version: '5.5.4-alpha.2',
4
- buildTime: '2024-10-01T08:41:09.234Z'
3
+ version: '5.5.4-alpha.3',
4
+ buildTime: '2024-10-01T09:09:17.169Z'
5
5
  };
@@ -19,32 +19,39 @@ async function dataDuplicator({
19
19
  systemConnection,
20
20
  }) {
21
21
  if (!driver) driver = requireEngineDriver(connection);
22
- const pool = systemConnection || (await connectUtility(driver, connection, 'write'));
22
+
23
+ const dbhan = systemConnection || (await connectUtility(driver, connection, 'write'));
23
24
 
24
- logger.info(`Connected.`);
25
+ try {
26
+ logger.info(`Connected.`);
25
27
 
26
- if (!analysedStructure) {
27
- analysedStructure = await driver.analyseFull(pool);
28
- }
28
+ if (!analysedStructure) {
29
+ analysedStructure = await driver.analyseFull(dbhan);
30
+ }
29
31
 
30
- const dupl = new DataDuplicator(
31
- pool,
32
- driver,
33
- analysedStructure,
34
- items.map(item => ({
35
- name: item.name,
36
- operation: item.operation,
37
- matchColumns: item.matchColumns,
38
- openStream:
39
- item.openStream ||
40
- (() => jsonLinesReader({ fileName: path.join(resolveArchiveFolder(archive), `${item.name}.jsonl`) })),
41
- })),
42
- stream,
43
- copyStream,
44
- options
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
- await dupl.run();
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 dumper = await driver.createBackupDumper(pool, {
34
- outputFile,
35
- databaseName,
36
- schemaName,
37
- });
38
- await doDump(dumper);
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;
@@ -9,12 +9,15 @@ async function executeQuery({ connection = undefined, systemConnection = undefin
9
9
 
10
10
  if (!driver) driver = requireEngineDriver(connection);
11
11
  const dbhan = systemConnection || (await connectUtility(driver, connection, 'script'));
12
- logger.info(`Connected.`);
13
12
 
14
- await driver.script(dbhan, sql);
13
+ try {
14
+ logger.info(`Connected.`);
15
15
 
16
- if (!systemConnection) {
17
- await driver.close(dbhan);
16
+ await driver.script(dbhan, sql);
17
+ } finally {
18
+ if (!systemConnection) {
19
+ await driver.close(dbhan);
20
+ }
18
21
  }
19
22
  }
20
23
 
@@ -22,44 +22,48 @@ async function generateDeploySql({
22
22
  if (!driver) driver = requireEngineDriver(connection);
23
23
 
24
24
  const dbhan = systemConnection || (await connectUtility(driver, connection, 'read'));
25
- if (!analysedStructure) {
26
- analysedStructure = await driver.analyseFull(dbhan);
27
- }
28
25
 
29
- const deployedModel = generateDbPairingId(
30
- extendDatabaseInfo(loadedDbModel ? databaseInfoFromYamlModel(loadedDbModel) : await importDbModel(modelFolder))
31
- );
32
- const currentModel = generateDbPairingId(extendDatabaseInfo(analysedStructure));
33
- const opts = {
34
- ...modelCompareDbDiffOptions,
26
+ try {
27
+ if (!analysedStructure) {
28
+ analysedStructure = await driver.analyseFull(dbhan);
29
+ }
35
30
 
36
- noDropTable: true,
37
- noDropColumn: true,
38
- noDropConstraint: true,
39
- noDropSqlObject: true,
40
- noRenameTable: true,
41
- noRenameColumn: true,
42
- };
43
- const currentModelPaired = matchPairedObjects(deployedModel, currentModel, opts);
44
- const currentModelPairedPreloaded = await enrichWithPreloadedRows(deployedModel, currentModelPaired, dbhan, driver);
31
+ const deployedModel = generateDbPairingId(
32
+ extendDatabaseInfo(loadedDbModel ? databaseInfoFromYamlModel(loadedDbModel) : await importDbModel(modelFolder))
33
+ );
34
+ const currentModel = generateDbPairingId(extendDatabaseInfo(analysedStructure));
35
+ const opts = {
36
+ ...modelCompareDbDiffOptions,
45
37
 
46
- // console.log('currentModelPairedPreloaded', currentModelPairedPreloaded.tables[0]);
47
- // console.log('deployedModel', deployedModel.tables[0]);
48
- // console.log('currentModel', currentModel.tables[0]);
49
- // console.log('currentModelPaired', currentModelPaired.tables[0]);
50
- const res = getAlterDatabaseScript(
51
- currentModelPairedPreloaded,
52
- deployedModel,
53
- opts,
54
- currentModelPairedPreloaded,
55
- deployedModel,
56
- driver
57
- );
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);
58
47
 
59
- if (!systemConnection) {
60
- await driver.close(dbhan);
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
+ }
61
66
  }
62
- return res;
63
67
  }
64
68
 
65
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
- logger.info(`Connected.`);
62
+ try {
63
+ logger.info(`Connected.`);
63
64
 
64
- logger.info(`Input file: ${inputFile}`);
65
- const downloadedFile = await download(inputFile);
66
- logger.info(`Downloaded file: ${downloadedFile}`);
65
+ logger.info(`Input file: ${inputFile}`);
66
+ const downloadedFile = await download(inputFile);
67
+ logger.info(`Downloaded file: ${downloadedFile}`);
67
68
 
68
- const fileStream = fs.createReadStream(downloadedFile, 'utf-8');
69
- const splittedStream = splitQueryStream(fileStream, {
70
- ...driver.getQuerySplitterOptions('import'),
71
- returnRichInfo: true,
72
- });
73
- const importStream = new ImportStream(dbhan, driver);
74
- // @ts-ignore
75
- splittedStream.pipe(importStream);
76
- await awaitStreamEnd(importStream);
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 pool = systemConnection || (await connectUtility(driver, connection, 'read', { forceRowsAsObjects: true }));
13
- logger.info(`Connected.`);
12
+ const dbhan = systemConnection || (await connectUtility(driver, connection, 'read', { forceRowsAsObjects: true }));
13
+ try {
14
+ logger.info(`Connected.`);
14
15
 
15
- const dbInfo = await driver.analyseFull(pool);
16
- logger.info(`Analyse finished`);
16
+ const dbInfo = await driver.analyseFull(dbhan);
17
+ logger.info(`Analyse finished`);
17
18
 
18
- await exportDbModel(dbInfo, outputDir);
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;
@@ -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 pool = await connectUtility(driver, connection, 'read');
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(pool, JSON.stringify(fullName));
17
+ return await driver.readQuery(dbhan, JSON.stringify(fullName));
18
18
  }
19
19
 
20
- const table = await driver.analyseSingleObject(pool, fullName, 'tables');
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(pool, query, table);
26
+ return await driver.readQuery(dbhan, query, table);
27
27
  }
28
- const view = await driver.analyseSingleObject(pool, fullName, 'views');
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(pool, query, view);
33
+ return await driver.readQuery(dbhan, query, view);
34
34
  }
35
35
 
36
- return await driver.readQuery(pool, query);
36
+ return await driver.readQuery(dbhan, query);
37
37
  }
38
38
 
39
39
  module.exports = tableReader;
@@ -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 pool = systemConnection || (await connectUtility(driver, connection, 'write'));
12
+ const dbhan = systemConnection || (await connectUtility(driver, connection, 'write'));
13
13
 
14
- logger.info(`Connected.`);
15
- return await driver.writeTable(pool, { schemaName, pureName }, options);
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
 
@@ -44,6 +44,7 @@ const platformInfo = {
44
44
  (!processArgs.listenApiChild && !isNpmDist) || !!process.env.SHELL_CONNECTION || !!isElectron() || !!isDbModel,
45
45
  allowShellScripting:
46
46
  (!processArgs.listenApiChild && !isNpmDist) || !!process.env.SHELL_SCRIPTING || !!isElectron() || !!isDbModel,
47
+ allowConnectionFromEnvVariables: !!isDbModel,
47
48
  defaultKeyfile: path.join(os.homedir(), '.ssh/id_rsa'),
48
49
  };
49
50