drop all objects WIP
Some checks are pending
Run tests / test-runner (push) Waiting to run

This commit is contained in:
SPRINX0\prochazka 2024-11-06 17:06:58 +01:00
parent 83610783e0
commit 6a02ba3220
2 changed files with 44 additions and 0 deletions

View File

@ -0,0 +1,42 @@
const executeQuery = require('./executeQuery');
const requireEngineDriver = require('../utility/requireEngineDriver');
const connectUtility = require('../utility/connectUtility');
const { getLogger, extendDatabaseInfo } = require('dbgate-tools');
const logger = getLogger('dropAllDbObjects');
async function dropAllDbObjects({ connection, systemConnection, driver, analysedStructure }) {
if (!driver) driver = requireEngineDriver(connection);
const dbhan = systemConnection || (await connectUtility(driver, connection, 'write'));
logger.info(`Connected.`);
if (!analysedStructure) {
analysedStructure = await driver.analyseFull(dbhan);
}
analysedStructure = extendDatabaseInfo(analysedStructure);
const dmp = driver.createDumper();
for (const table of analysedStructure.tables) {
for (const fk of table.foreignKeys) {
dmp.dropForeignKey(fk);
}
}
for (const table of analysedStructure.tables) {
dmp.dropTable(table);
}
for (const field of Object.keys(analysedStructure)) {
if (dmp.getSqlObjectSqlName(field)) {
for (const obj of analysedStructure[field]) {
dmp.dropSqlObject(obj);
}
}
}
await executeQuery({ connection, systemConnection, driver, sql: dmp.s, logScriptItems: true });
}
module.exports = dropAllDbObjects;

View File

@ -34,6 +34,7 @@ const dataTypeMapperTransform = require('./dataTypeMapperTransform');
const sqlTextReplacementTransform = require('./sqlTextReplacementTransform');
const autoIndexForeignKeysTransform = require('./autoIndexForeignKeysTransform');
const generateDeploySql = require('./generateDeploySql');
const dropAllDbObjects = require('./dropAllDbObjects');
const dbgateApi = {
queryReader,
@ -71,6 +72,7 @@ const dbgateApi = {
sqlTextReplacementTransform,
autoIndexForeignKeysTransform,
generateDeploySql,
dropAllDbObjects,
};
requirePlugin.initializeDbgateApi(dbgateApi);