mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-22 08:46:00 +00:00
deploy DB WIP
This commit is contained in:
@@ -3,13 +3,15 @@ const connections = require('./connections');
|
||||
const archive = require('./archive');
|
||||
const socket = require('../utility/socket');
|
||||
const { fork } = require('child_process');
|
||||
const { DatabaseAnalyser } = require('dbgate-tools');
|
||||
const { DatabaseAnalyser, getAlterDatabaseScript, generateDbPairingId, matchPairedObjects } = require('dbgate-tools');
|
||||
const { handleProcessCommunication } = require('../utility/processComm');
|
||||
const config = require('./config');
|
||||
const fs = require('fs-extra');
|
||||
const exportDbModel = require('../utility/exportDbModel');
|
||||
const { archivedir } = require('../utility/directories');
|
||||
const path = require('path');
|
||||
const importDbModel = require('../utility/importDbModel');
|
||||
const requireEngineDriver = require('../utility/requireEngineDriver');
|
||||
|
||||
module.exports = {
|
||||
/** @type {import('dbgate-types').OpenedDatabaseConnection[]} */
|
||||
@@ -253,6 +255,22 @@ module.exports = {
|
||||
return { archiveFolder };
|
||||
},
|
||||
|
||||
generateDeploySql_meta: 'post',
|
||||
async generateDeploySql({ conid, database, archiveFolder }) {
|
||||
const deployedModel = generateDbPairingId(await importDbModel(path.join(archivedir(), archiveFolder)));
|
||||
const currentModel = generateDbPairingId(await this.structure({ conid, database }));
|
||||
const currentModelPaired = matchPairedObjects(deployedModel, currentModel);
|
||||
const connection = await connections.get({ conid });
|
||||
const driver = requireEngineDriver(connection);
|
||||
const { sql } = getAlterDatabaseScript(currentModelPaired, deployedModel, {}, deployedModel, driver);
|
||||
return {
|
||||
deployedModel,
|
||||
currentModel,
|
||||
currentModelPaired,
|
||||
sql,
|
||||
};
|
||||
return sql;
|
||||
},
|
||||
// runCommand_meta: 'post',
|
||||
// async runCommand({ conid, database, sql }) {
|
||||
// console.log(`Running SQL command , conid=${conid}, database=${database}, sql=${sql}`);
|
||||
|
||||
@@ -19,6 +19,7 @@ const requirePlugin = require('./requirePlugin');
|
||||
const download = require('./download');
|
||||
const executeQuery = require('./executeQuery');
|
||||
const loadFile = require('./loadFile');
|
||||
const deployDb = require('./deployDb');
|
||||
const initializeApiEnvironment = require('./initializeApiEnvironment');
|
||||
|
||||
const dbgateApi = {
|
||||
@@ -42,6 +43,7 @@ const dbgateApi = {
|
||||
registerPlugins,
|
||||
executeQuery,
|
||||
loadFile,
|
||||
deployDb,
|
||||
initializeApiEnvironment,
|
||||
};
|
||||
|
||||
|
||||
@@ -2,22 +2,27 @@ const fs = require('fs-extra');
|
||||
const path = require('path');
|
||||
const yaml = require('js-yaml');
|
||||
const { tableInfoFromYaml, DatabaseAnalyser } = require('dbgate-tools');
|
||||
const { startsWith } = require('lodash');
|
||||
const { archivedir } = require('./directories');
|
||||
|
||||
async function importDbModel(inputDir) {
|
||||
const tablesYaml = [];
|
||||
|
||||
const model = DatabaseAnalyser.createEmptyStructure();
|
||||
|
||||
for (const file of await fs.readdir(inputDir)) {
|
||||
const dir = inputDir.startsWith('archive:')
|
||||
? path.join(archivedir(), inputDir.substring('archive:'.length))
|
||||
: inputDir;
|
||||
|
||||
for (const file of await fs.readdir(dir)) {
|
||||
if (file.endsWith('.table.yaml') || file.endsWith('.sql')) {
|
||||
const content = await fs.readFile(path.join(inputDir, file), { encoding: 'utf-8' });
|
||||
const content = await fs.readFile(path.join(dir, file), { encoding: 'utf-8' });
|
||||
|
||||
if (file.endsWith('.table.yaml')) {
|
||||
const json = yaml.load(content);
|
||||
tablesYaml.push(json);
|
||||
}
|
||||
|
||||
|
||||
if (file.endsWith('.view.sql')) {
|
||||
model.views.push({
|
||||
pureName: file.slice(0, -'.view.sql'.length),
|
||||
|
||||
Reference in New Issue
Block a user