dbgate-api 4.4.1 → 4.4.2

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": "4.4.1",
4
+ "version": "4.4.2",
5
5
  "homepage": "https://dbgate.org/",
6
6
  "repository": {
7
7
  "type": "git",
@@ -26,9 +26,9 @@
26
26
  "compare-versions": "^3.6.0",
27
27
  "cors": "^2.8.5",
28
28
  "cross-env": "^6.0.3",
29
- "dbgate-query-splitter": "^4.4.1",
30
- "dbgate-sqltree": "^4.4.1",
31
- "dbgate-tools": "^4.4.1",
29
+ "dbgate-query-splitter": "^4.4.2",
30
+ "dbgate-sqltree": "^4.4.2",
31
+ "dbgate-tools": "^4.4.2",
32
32
  "diff": "^5.0.0",
33
33
  "diff2html": "^3.4.13",
34
34
  "eslint": "^6.8.0",
@@ -65,7 +65,7 @@
65
65
  "devDependencies": {
66
66
  "@types/fs-extra": "^9.0.11",
67
67
  "@types/lodash": "^4.14.149",
68
- "dbgate-types": "^4.4.1",
68
+ "dbgate-types": "^4.4.2",
69
69
  "env-cmd": "^10.1.0",
70
70
  "node-loader": "^1.0.2",
71
71
  "nodemon": "^2.0.2",
@@ -97,7 +97,8 @@ module.exports = {
97
97
 
98
98
  renameFolder_meta: 'post',
99
99
  async renameFolder({ folder, newFolder }) {
100
- await fs.rename(path.join(resolveArchiveFolder(folder)), path.join(resolveArchiveFolder(newFolder)));
100
+ const uniqueName = await this.getNewArchiveFolder({ database: newFolder });
101
+ await fs.rename(path.join(archivedir(), folder), path.join(archivedir(), uniqueName));
101
102
  socket.emitChanged(`archive-folders-changed`);
102
103
  },
103
104
 
@@ -140,11 +141,14 @@ module.exports = {
140
141
  },
141
142
 
142
143
  async getNewArchiveFolder({ database }) {
144
+ const isLink = database.endsWith(database);
145
+ const name = isLink ? database.slice(0, -5) : database;
146
+ const suffix = isLink ? '.link' : '';
143
147
  if (!(await fs.exists(path.join(archivedir(), database)))) return database;
144
148
  let index = 2;
145
- while (await fs.exists(path.join(archivedir(), `${database}${index}`))) {
149
+ while (await fs.exists(path.join(archivedir(), `${name}${index}${suffix}`))) {
146
150
  index += 1;
147
151
  }
148
- return `${database}${index}`;
152
+ return `${name}${index}${suffix}`;
149
153
  },
150
154
  };
@@ -275,12 +275,17 @@ module.exports = {
275
275
 
276
276
  generateDeploySql_meta: 'post',
277
277
  async generateDeploySql({ conid, database, archiveFolder }) {
278
- const connection = await connections.get({ conid });
279
- return generateDeploySql({
280
- connection,
281
- analysedStructure: await this.structure({ conid, database }),
282
- modelFolder: resolveArchiveFolder(archiveFolder),
283
- });
278
+ const opened = await this.ensureOpened(conid, database);
279
+ const res = await this.sendRequest(opened, { msgtype: 'generateDeploySql', modelFolder: resolveArchiveFolder(archiveFolder) });
280
+ return res;
281
+
282
+ // const connection = await connections.get({ conid });
283
+ // return generateDeploySql({
284
+ // connection,
285
+ // analysedStructure: await this.structure({ conid, database }),
286
+ // modelFolder: resolveArchiveFolder(archiveFolder),
287
+ // });
288
+
284
289
  // const deployedModel = generateDbPairingId(await importDbModel(path.join(archivedir(), archiveFolder)));
285
290
  // const currentModel = generateDbPairingId(await this.structure({ conid, database }));
286
291
  // const currentModelPaired = matchPairedObjects(deployedModel, currentModel);
@@ -1,5 +1,5 @@
1
1
 
2
2
  module.exports = {
3
- version: '4.4.1',
4
- buildTime: '2021-11-22T18:42:53.218Z'
3
+ version: '4.4.2',
4
+ buildTime: '2021-12-02T07:20:50.672Z'
5
5
  };
@@ -6,10 +6,12 @@ const requireEngineDriver = require('../utility/requireEngineDriver');
6
6
  const connectUtility = require('../utility/connectUtility');
7
7
  const { handleProcessCommunication } = require('../utility/processComm');
8
8
  const { SqlGenerator } = require('dbgate-tools');
9
+ const generateDeploySql = require('../shell/generateDeploySql');
9
10
 
10
11
  let systemConnection;
11
12
  let storedConnection;
12
13
  let afterConnectCallbacks = [];
14
+ let afterAnalyseCallbacks = [];
13
15
  let analysedStructure = null;
14
16
  let lastPing = null;
15
17
  let lastStatus = null;
@@ -42,14 +44,18 @@ async function handleFullRefresh() {
42
44
  process.send({ msgtype: 'structure', structure: analysedStructure });
43
45
  process.send({ msgtype: 'structureTime', analysedTime });
44
46
  setStatusName('ok');
47
+
45
48
  loadingModel = false;
49
+ resolveAnalysedPromises();
46
50
  }
47
51
 
48
52
  async function handleIncrementalRefresh(forceSend) {
49
53
  loadingModel = true;
50
54
  const driver = requireEngineDriver(storedConnection);
51
55
  setStatusName('checkStructure');
52
- const newStructure = await checkedAsyncCall(driver.analyseIncremental(systemConnection, analysedStructure, serverVersion));
56
+ const newStructure = await checkedAsyncCall(
57
+ driver.analyseIncremental(systemConnection, analysedStructure, serverVersion)
58
+ );
53
59
  analysedTime = new Date().getTime();
54
60
  if (newStructure != null) {
55
61
  analysedStructure = newStructure;
@@ -62,6 +68,7 @@ async function handleIncrementalRefresh(forceSend) {
62
68
  process.send({ msgtype: 'structureTime', analysedTime });
63
69
  setStatusName('ok');
64
70
  loadingModel = false;
71
+ resolveAnalysedPromises();
65
72
  }
66
73
 
67
74
  function handleSyncModel() {
@@ -123,6 +130,20 @@ function waitConnected() {
123
130
  });
124
131
  }
125
132
 
133
+ function waitStructure() {
134
+ if (analysedStructure) return Promise.resolve();
135
+ return new Promise((resolve, reject) => {
136
+ afterAnalyseCallbacks.push([resolve, reject]);
137
+ });
138
+ }
139
+
140
+ function resolveAnalysedPromises() {
141
+ for (const [resolve] of afterAnalyseCallbacks) {
142
+ resolve();
143
+ }
144
+ afterAnalyseCallbacks = [];
145
+ }
146
+
126
147
  async function handleRunScript({ msgid, sql }) {
127
148
  await waitConnected();
128
149
  const driver = requireEngineDriver(storedConnection);
@@ -168,7 +189,7 @@ async function handleUpdateCollection({ msgid, changeSet }) {
168
189
  }
169
190
 
170
191
  async function handleSqlPreview({ msgid, objects, options }) {
171
- await waitConnected();
192
+ await waitStructure();
172
193
  const driver = requireEngineDriver(storedConnection);
173
194
 
174
195
  try {
@@ -188,6 +209,22 @@ async function handleSqlPreview({ msgid, objects, options }) {
188
209
  }
189
210
  }
190
211
 
212
+ async function handleGenerateDeploySql({ msgid, modelFolder }) {
213
+ await waitStructure();
214
+
215
+ try {
216
+ const res = await generateDeploySql({
217
+ systemConnection,
218
+ connection: storedConnection,
219
+ analysedStructure,
220
+ modelFolder,
221
+ });
222
+ process.send({ ...res, msgtype: 'response', msgid });
223
+ } catch (err) {
224
+ process.send({ msgtype: 'response', msgid, isError: true, errorMessage: err.message });
225
+ }
226
+ }
227
+
191
228
  // async function handleRunCommand({ msgid, sql }) {
192
229
  // await waitConnected();
193
230
  // const driver = engines(storedConnection);
@@ -208,6 +245,7 @@ const messageHandlers = {
208
245
  sqlPreview: handleSqlPreview,
209
246
  ping: handlePing,
210
247
  syncModel: handleSyncModel,
248
+ generateDeploySql: handleGenerateDeploySql,
211
249
  // runCommand: handleRunCommand,
212
250
  };
213
251
 
@@ -5,6 +5,7 @@ const {
5
5
  databaseInfoFromYamlModel,
6
6
  extendDatabaseInfo,
7
7
  modelCompareDbDiffOptions,
8
+ enrichWithPreloadedRows,
8
9
  } = require('dbgate-tools');
9
10
  const importDbModel = require('../utility/importDbModel');
10
11
  const requireEngineDriver = require('../utility/requireEngineDriver');
@@ -19,8 +20,9 @@ async function generateDeploySql({
19
20
  loadedDbModel = undefined,
20
21
  }) {
21
22
  if (!driver) driver = requireEngineDriver(connection);
23
+
24
+ const pool = systemConnection || (await connectUtility(driver, connection));
22
25
  if (!analysedStructure) {
23
- const pool = systemConnection || (await connectUtility(driver, connection));
24
26
  analysedStructure = await driver.analyseFull(pool);
25
27
  }
26
28
 
@@ -39,10 +41,20 @@ async function generateDeploySql({
39
41
  noRenameColumn: true,
40
42
  };
41
43
  const currentModelPaired = matchPairedObjects(deployedModel, currentModel, opts);
44
+ const currentModelPairedPreloaded = await enrichWithPreloadedRows(deployedModel, currentModelPaired, pool, driver);
45
+
46
+ // console.log('currentModelPairedPreloaded', currentModelPairedPreloaded.tables[0]);
42
47
  // console.log('deployedModel', deployedModel.tables[0]);
43
48
  // console.log('currentModel', currentModel.tables[0]);
44
49
  // console.log('currentModelPaired', currentModelPaired.tables[0]);
45
- const res = getAlterDatabaseScript(currentModelPaired, deployedModel, opts, deployedModel, driver);
50
+ const res = getAlterDatabaseScript(
51
+ currentModelPairedPreloaded,
52
+ deployedModel,
53
+ opts,
54
+ currentModelPairedPreloaded,
55
+ deployedModel,
56
+ driver
57
+ );
46
58
  return res;
47
59
  }
48
60