mirror of
https://github.com/dbgate/dbgate
synced 2024-11-07 04:00:59 +00:00
This commit is contained in:
parent
83610783e0
commit
6a02ba3220
42
packages/api/src/shell/dropAllDbObjects.js
Normal file
42
packages/api/src/shell/dropAllDbObjects.js
Normal 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;
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user