mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-26 15:36:28 +00:00
generate deploy sql moved to connection process
This commit is contained in:
@@ -275,12 +275,17 @@ module.exports = {
|
|||||||
|
|
||||||
generateDeploySql_meta: 'post',
|
generateDeploySql_meta: 'post',
|
||||||
async generateDeploySql({ conid, database, archiveFolder }) {
|
async generateDeploySql({ conid, database, archiveFolder }) {
|
||||||
const connection = await connections.get({ conid });
|
const opened = await this.ensureOpened(conid, database);
|
||||||
return generateDeploySql({
|
const res = await this.sendRequest(opened, { msgtype: 'generateDeploySql', modelFolder: resolveArchiveFolder(archiveFolder) });
|
||||||
connection,
|
return res;
|
||||||
analysedStructure: await this.structure({ conid, database }),
|
|
||||||
modelFolder: resolveArchiveFolder(archiveFolder),
|
// 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 deployedModel = generateDbPairingId(await importDbModel(path.join(archivedir(), archiveFolder)));
|
||||||
// const currentModel = generateDbPairingId(await this.structure({ conid, database }));
|
// const currentModel = generateDbPairingId(await this.structure({ conid, database }));
|
||||||
// const currentModelPaired = matchPairedObjects(deployedModel, currentModel);
|
// const currentModelPaired = matchPairedObjects(deployedModel, currentModel);
|
||||||
|
|||||||
@@ -6,10 +6,12 @@ const requireEngineDriver = require('../utility/requireEngineDriver');
|
|||||||
const connectUtility = require('../utility/connectUtility');
|
const connectUtility = require('../utility/connectUtility');
|
||||||
const { handleProcessCommunication } = require('../utility/processComm');
|
const { handleProcessCommunication } = require('../utility/processComm');
|
||||||
const { SqlGenerator } = require('dbgate-tools');
|
const { SqlGenerator } = require('dbgate-tools');
|
||||||
|
const generateDeploySql = require('../shell/generateDeploySql');
|
||||||
|
|
||||||
let systemConnection;
|
let systemConnection;
|
||||||
let storedConnection;
|
let storedConnection;
|
||||||
let afterConnectCallbacks = [];
|
let afterConnectCallbacks = [];
|
||||||
|
let afterAnalyseCallbacks = [];
|
||||||
let analysedStructure = null;
|
let analysedStructure = null;
|
||||||
let lastPing = null;
|
let lastPing = null;
|
||||||
let lastStatus = null;
|
let lastStatus = null;
|
||||||
@@ -42,14 +44,18 @@ async function handleFullRefresh() {
|
|||||||
process.send({ msgtype: 'structure', structure: analysedStructure });
|
process.send({ msgtype: 'structure', structure: analysedStructure });
|
||||||
process.send({ msgtype: 'structureTime', analysedTime });
|
process.send({ msgtype: 'structureTime', analysedTime });
|
||||||
setStatusName('ok');
|
setStatusName('ok');
|
||||||
|
|
||||||
loadingModel = false;
|
loadingModel = false;
|
||||||
|
resolveAnalysedPromises();
|
||||||
}
|
}
|
||||||
|
|
||||||
async function handleIncrementalRefresh(forceSend) {
|
async function handleIncrementalRefresh(forceSend) {
|
||||||
loadingModel = true;
|
loadingModel = true;
|
||||||
const driver = requireEngineDriver(storedConnection);
|
const driver = requireEngineDriver(storedConnection);
|
||||||
setStatusName('checkStructure');
|
setStatusName('checkStructure');
|
||||||
const newStructure = await checkedAsyncCall(driver.analyseIncremental(systemConnection, analysedStructure, serverVersion));
|
const newStructure = await checkedAsyncCall(
|
||||||
|
driver.analyseIncremental(systemConnection, analysedStructure, serverVersion)
|
||||||
|
);
|
||||||
analysedTime = new Date().getTime();
|
analysedTime = new Date().getTime();
|
||||||
if (newStructure != null) {
|
if (newStructure != null) {
|
||||||
analysedStructure = newStructure;
|
analysedStructure = newStructure;
|
||||||
@@ -62,6 +68,7 @@ async function handleIncrementalRefresh(forceSend) {
|
|||||||
process.send({ msgtype: 'structureTime', analysedTime });
|
process.send({ msgtype: 'structureTime', analysedTime });
|
||||||
setStatusName('ok');
|
setStatusName('ok');
|
||||||
loadingModel = false;
|
loadingModel = false;
|
||||||
|
resolveAnalysedPromises();
|
||||||
}
|
}
|
||||||
|
|
||||||
function handleSyncModel() {
|
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 }) {
|
async function handleRunScript({ msgid, sql }) {
|
||||||
await waitConnected();
|
await waitConnected();
|
||||||
const driver = requireEngineDriver(storedConnection);
|
const driver = requireEngineDriver(storedConnection);
|
||||||
@@ -168,7 +189,7 @@ async function handleUpdateCollection({ msgid, changeSet }) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function handleSqlPreview({ msgid, objects, options }) {
|
async function handleSqlPreview({ msgid, objects, options }) {
|
||||||
await waitConnected();
|
await waitStructure();
|
||||||
const driver = requireEngineDriver(storedConnection);
|
const driver = requireEngineDriver(storedConnection);
|
||||||
|
|
||||||
try {
|
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 }) {
|
// async function handleRunCommand({ msgid, sql }) {
|
||||||
// await waitConnected();
|
// await waitConnected();
|
||||||
// const driver = engines(storedConnection);
|
// const driver = engines(storedConnection);
|
||||||
@@ -208,6 +245,7 @@ const messageHandlers = {
|
|||||||
sqlPreview: handleSqlPreview,
|
sqlPreview: handleSqlPreview,
|
||||||
ping: handlePing,
|
ping: handlePing,
|
||||||
syncModel: handleSyncModel,
|
syncModel: handleSyncModel,
|
||||||
|
generateDeploySql: handleGenerateDeploySql,
|
||||||
// runCommand: handleRunCommand,
|
// runCommand: handleRunCommand,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -16,6 +16,7 @@
|
|||||||
import { showModal } from '../modals/modalTools';
|
import { showModal } from '../modals/modalTools';
|
||||||
import ConfirmModal from '../modals/ConfirmModal.svelte';
|
import ConfirmModal from '../modals/ConfirmModal.svelte';
|
||||||
import InputTextModal from '../modals/InputTextModal.svelte';
|
import InputTextModal from '../modals/InputTextModal.svelte';
|
||||||
|
import ErrorMessageModal from '../modals/ErrorMessageModal.svelte';
|
||||||
|
|
||||||
export let data;
|
export let data;
|
||||||
|
|
||||||
@@ -83,7 +84,11 @@ await dbgateApi.deployDb(${JSON.stringify(
|
|||||||
archiveFolder: data.name,
|
archiveFolder: data.name,
|
||||||
});
|
});
|
||||||
|
|
||||||
newQuery({ initialData: resp.data.sql });
|
if (resp.data.errorMessage) {
|
||||||
|
showModal(ErrorMessageModal, { message: resp.data.errorMessage });
|
||||||
|
} else {
|
||||||
|
newQuery({ initialData: resp.data.sql });
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleCompareWithCurrentDb = () => {
|
const handleCompareWithCurrentDb = () => {
|
||||||
|
|||||||
Reference in New Issue
Block a user