mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-19 10:46:00 +00:00
generate deploy sql moved to connection process
This commit is contained in:
@@ -275,12 +275,17 @@ module.exports = {
|
||||
|
||||
generateDeploySql_meta: 'post',
|
||||
async generateDeploySql({ conid, database, archiveFolder }) {
|
||||
const connection = await connections.get({ conid });
|
||||
return generateDeploySql({
|
||||
connection,
|
||||
analysedStructure: await this.structure({ conid, database }),
|
||||
modelFolder: resolveArchiveFolder(archiveFolder),
|
||||
});
|
||||
const opened = await this.ensureOpened(conid, database);
|
||||
const res = await this.sendRequest(opened, { msgtype: 'generateDeploySql', modelFolder: resolveArchiveFolder(archiveFolder) });
|
||||
return res;
|
||||
|
||||
// const connection = await connections.get({ conid });
|
||||
// return generateDeploySql({
|
||||
// connection,
|
||||
// analysedStructure: await this.structure({ conid, database }),
|
||||
// modelFolder: resolveArchiveFolder(archiveFolder),
|
||||
// });
|
||||
|
||||
// const deployedModel = generateDbPairingId(await importDbModel(path.join(archivedir(), archiveFolder)));
|
||||
// const currentModel = generateDbPairingId(await this.structure({ conid, database }));
|
||||
// const currentModelPaired = matchPairedObjects(deployedModel, currentModel);
|
||||
|
||||
@@ -6,10 +6,12 @@ const requireEngineDriver = require('../utility/requireEngineDriver');
|
||||
const connectUtility = require('../utility/connectUtility');
|
||||
const { handleProcessCommunication } = require('../utility/processComm');
|
||||
const { SqlGenerator } = require('dbgate-tools');
|
||||
const generateDeploySql = require('../shell/generateDeploySql');
|
||||
|
||||
let systemConnection;
|
||||
let storedConnection;
|
||||
let afterConnectCallbacks = [];
|
||||
let afterAnalyseCallbacks = [];
|
||||
let analysedStructure = null;
|
||||
let lastPing = null;
|
||||
let lastStatus = null;
|
||||
@@ -42,14 +44,18 @@ async function handleFullRefresh() {
|
||||
process.send({ msgtype: 'structure', structure: analysedStructure });
|
||||
process.send({ msgtype: 'structureTime', analysedTime });
|
||||
setStatusName('ok');
|
||||
|
||||
loadingModel = false;
|
||||
resolveAnalysedPromises();
|
||||
}
|
||||
|
||||
async function handleIncrementalRefresh(forceSend) {
|
||||
loadingModel = true;
|
||||
const driver = requireEngineDriver(storedConnection);
|
||||
setStatusName('checkStructure');
|
||||
const newStructure = await checkedAsyncCall(driver.analyseIncremental(systemConnection, analysedStructure, serverVersion));
|
||||
const newStructure = await checkedAsyncCall(
|
||||
driver.analyseIncremental(systemConnection, analysedStructure, serverVersion)
|
||||
);
|
||||
analysedTime = new Date().getTime();
|
||||
if (newStructure != null) {
|
||||
analysedStructure = newStructure;
|
||||
@@ -62,6 +68,7 @@ async function handleIncrementalRefresh(forceSend) {
|
||||
process.send({ msgtype: 'structureTime', analysedTime });
|
||||
setStatusName('ok');
|
||||
loadingModel = false;
|
||||
resolveAnalysedPromises();
|
||||
}
|
||||
|
||||
function handleSyncModel() {
|
||||
@@ -123,6 +130,20 @@ function waitConnected() {
|
||||
});
|
||||
}
|
||||
|
||||
function waitStructure() {
|
||||
if (analysedStructure) return Promise.resolve();
|
||||
return new Promise((resolve, reject) => {
|
||||
afterAnalyseCallbacks.push([resolve, reject]);
|
||||
});
|
||||
}
|
||||
|
||||
function resolveAnalysedPromises() {
|
||||
for (const [resolve] of afterAnalyseCallbacks) {
|
||||
resolve();
|
||||
}
|
||||
afterAnalyseCallbacks = [];
|
||||
}
|
||||
|
||||
async function handleRunScript({ msgid, sql }) {
|
||||
await waitConnected();
|
||||
const driver = requireEngineDriver(storedConnection);
|
||||
@@ -168,7 +189,7 @@ async function handleUpdateCollection({ msgid, changeSet }) {
|
||||
}
|
||||
|
||||
async function handleSqlPreview({ msgid, objects, options }) {
|
||||
await waitConnected();
|
||||
await waitStructure();
|
||||
const driver = requireEngineDriver(storedConnection);
|
||||
|
||||
try {
|
||||
@@ -188,6 +209,22 @@ async function handleSqlPreview({ msgid, objects, options }) {
|
||||
}
|
||||
}
|
||||
|
||||
async function handleGenerateDeploySql({ msgid, modelFolder }) {
|
||||
await waitStructure();
|
||||
|
||||
try {
|
||||
const res = await generateDeploySql({
|
||||
systemConnection,
|
||||
connection: storedConnection,
|
||||
analysedStructure,
|
||||
modelFolder,
|
||||
});
|
||||
process.send({ ...res, msgtype: 'response', msgid });
|
||||
} catch (err) {
|
||||
process.send({ msgtype: 'response', msgid, isError: true, errorMessage: err.message });
|
||||
}
|
||||
}
|
||||
|
||||
// async function handleRunCommand({ msgid, sql }) {
|
||||
// await waitConnected();
|
||||
// const driver = engines(storedConnection);
|
||||
@@ -208,6 +245,7 @@ const messageHandlers = {
|
||||
sqlPreview: handleSqlPreview,
|
||||
ping: handlePing,
|
||||
syncModel: handleSyncModel,
|
||||
generateDeploySql: handleGenerateDeploySql,
|
||||
// runCommand: handleRunCommand,
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user