mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-05-01 15:33:57 +00:00
drop database #384
This commit is contained in:
@@ -152,4 +152,13 @@ module.exports = {
|
|||||||
opened.subprocess.send({ msgtype: 'createDatabase', name });
|
opened.subprocess.send({ msgtype: 'createDatabase', name });
|
||||||
return { status: 'ok' };
|
return { status: 'ok' };
|
||||||
},
|
},
|
||||||
|
|
||||||
|
dropDatabase_meta: true,
|
||||||
|
async dropDatabase({ conid, name }, req) {
|
||||||
|
testConnectionPermission(conid, req);
|
||||||
|
const opened = await this.ensureOpened(conid);
|
||||||
|
if (opened.connection.isReadOnly) return false;
|
||||||
|
opened.subprocess.send({ msgtype: 'dropDatabase', name });
|
||||||
|
return { status: 'ok' };
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ const stableStringify = require('json-stable-stringify');
|
|||||||
const { extractBoolSettingsValue, extractIntSettingsValue } = require('dbgate-tools');
|
const { extractBoolSettingsValue, extractIntSettingsValue } = require('dbgate-tools');
|
||||||
const childProcessChecker = require('../utility/childProcessChecker');
|
const childProcessChecker = require('../utility/childProcessChecker');
|
||||||
const requireEngineDriver = require('../utility/requireEngineDriver');
|
const requireEngineDriver = require('../utility/requireEngineDriver');
|
||||||
const { decryptConnection } = require('../utility/crypting');
|
|
||||||
const connectUtility = require('../utility/connectUtility');
|
const connectUtility = require('../utility/connectUtility');
|
||||||
const { handleProcessCommunication } = require('../utility/processComm');
|
const { handleProcessCommunication } = require('../utility/processComm');
|
||||||
|
|
||||||
@@ -81,14 +80,16 @@ function handlePing() {
|
|||||||
lastPing = new Date().getTime();
|
lastPing = new Date().getTime();
|
||||||
}
|
}
|
||||||
|
|
||||||
async function handleCreateDatabase({ name }) {
|
async function handleDatabaseOp(op, { name }) {
|
||||||
const driver = requireEngineDriver(storedConnection);
|
const driver = requireEngineDriver(storedConnection);
|
||||||
systemConnection = await connectUtility(driver, storedConnection, 'app');
|
systemConnection = await connectUtility(driver, storedConnection, 'app');
|
||||||
console.log(`RUNNING SCRIPT: CREATE DATABASE ${driver.dialect.quoteIdentifier(name)}`);
|
if (driver[op]) {
|
||||||
if (driver.createDatabase) {
|
await driver[op](systemConnection, name);
|
||||||
await driver.createDatabase(systemConnection, name);
|
|
||||||
} else {
|
} else {
|
||||||
await driver.query(systemConnection, `CREATE DATABASE ${driver.dialect.quoteIdentifier(name)}`);
|
const dmp = driver.createDumper();
|
||||||
|
dmp[op](name);
|
||||||
|
console.log(`RUNNING SCRIPT: ${dmp.s}`);
|
||||||
|
await driver.query(systemConnection, dmp.s);
|
||||||
}
|
}
|
||||||
await handleRefresh();
|
await handleRefresh();
|
||||||
}
|
}
|
||||||
@@ -96,7 +97,8 @@ async function handleCreateDatabase({ name }) {
|
|||||||
const messageHandlers = {
|
const messageHandlers = {
|
||||||
connect: handleConnect,
|
connect: handleConnect,
|
||||||
ping: handlePing,
|
ping: handlePing,
|
||||||
createDatabase: handleCreateDatabase,
|
createDatabase: props => handleDatabaseOp('createDatabase', props),
|
||||||
|
dropDatabase: props => handleDatabaseOp('dropDatabase', props),
|
||||||
};
|
};
|
||||||
|
|
||||||
async function handleMessage({ msgtype, ...other }) {
|
async function handleMessage({ msgtype, ...other }) {
|
||||||
|
|||||||
@@ -181,6 +181,14 @@ export class SqlDumper implements AlterProcessor {
|
|||||||
this.put(' ^auto_increment');
|
this.put(' ^auto_increment');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
createDatabase(name: string) {
|
||||||
|
this.putCmd('^create ^database %i', name);
|
||||||
|
}
|
||||||
|
|
||||||
|
dropDatabase(name: string) {
|
||||||
|
this.putCmd('^drop ^database %i', name);
|
||||||
|
}
|
||||||
|
|
||||||
specialColumnOptions(column) {}
|
specialColumnOptions(column) {}
|
||||||
|
|
||||||
columnDefinition(column: ColumnInfo, { includeDefault = true, includeNullable = true, includeCollate = true } = {}) {
|
columnDefinition(column: ColumnInfo, { includeDefault = true, includeNullable = true, includeCollate = true } = {}) {
|
||||||
|
|||||||
2
packages/types/dumper.d.ts
vendored
2
packages/types/dumper.d.ts
vendored
@@ -14,6 +14,8 @@ export interface SqlDumper extends AlterProcessor {
|
|||||||
putValue(value: string | number | Date);
|
putValue(value: string | number | Date);
|
||||||
putCollection<T>(delimiter: string, collection: T[], lambda: (item: T) => void);
|
putCollection<T>(delimiter: string, collection: T[], lambda: (item: T) => void);
|
||||||
transform(type: TransformType, dumpExpr: () => void);
|
transform(type: TransformType, dumpExpr: () => void);
|
||||||
|
createDatabase(name: string);
|
||||||
|
dropDatabase(name: string);
|
||||||
|
|
||||||
endCommand();
|
endCommand();
|
||||||
allowIdentityInsert(table: NamedObjectInfo, allow: boolean);
|
allowIdentityInsert(table: NamedObjectInfo, allow: boolean);
|
||||||
|
|||||||
1
packages/types/engines.d.ts
vendored
1
packages/types/engines.d.ts
vendored
@@ -110,6 +110,7 @@ export interface EngineDriver {
|
|||||||
updateCollection(pool: any, changeSet: any): Promise<any>;
|
updateCollection(pool: any, changeSet: any): Promise<any>;
|
||||||
getCollectionUpdateScript(changeSet: any): string;
|
getCollectionUpdateScript(changeSet: any): string;
|
||||||
createDatabase(pool: any, name: string): Promise;
|
createDatabase(pool: any, name: string): Promise;
|
||||||
|
dropDatabase(pool: any, name: string): Promise;
|
||||||
getQuerySplitterOptions(usage: 'stream' | 'script' | 'editor'): any;
|
getQuerySplitterOptions(usage: 'stream' | 'script' | 'editor'): any;
|
||||||
script(pool: any, sql: string): Promise;
|
script(pool: any, sql: string): Promise;
|
||||||
getNewObjectTemplates(): NewObjectTemplate[];
|
getNewObjectTemplates(): NewObjectTemplate[];
|
||||||
|
|||||||
@@ -77,6 +77,17 @@
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const handleDropDatabase = () => {
|
||||||
|
showModal(ConfirmModal, {
|
||||||
|
message: `Really drop database ${name}? All opened sessions with this database will be forcefully closed.`,
|
||||||
|
onConfirm: () =>
|
||||||
|
apiCall('server-connections/drop-database', {
|
||||||
|
conid: connection._id,
|
||||||
|
name,
|
||||||
|
}),
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
const handleNewCollection = () => {
|
const handleNewCollection = () => {
|
||||||
showModal(InputTextModal, {
|
showModal(InputTextModal, {
|
||||||
value: '',
|
value: '',
|
||||||
@@ -233,6 +244,9 @@
|
|||||||
{ onClick: handleNewQuery, text: 'New query', isNewQuery: true },
|
{ onClick: handleNewQuery, text: 'New query', isNewQuery: true },
|
||||||
driver?.databaseEngineTypes?.includes('sql') && { onClick: handleNewTable, text: 'New table' },
|
driver?.databaseEngineTypes?.includes('sql') && { onClick: handleNewTable, text: 'New table' },
|
||||||
driver?.databaseEngineTypes?.includes('document') && { onClick: handleNewCollection, text: 'New collection' },
|
driver?.databaseEngineTypes?.includes('document') && { onClick: handleNewCollection, text: 'New collection' },
|
||||||
|
isSqlOrDoc &&
|
||||||
|
!connection.isReadOnly &&
|
||||||
|
!connection.singleDatabase && { onClick: handleDropDatabase, text: 'Drop database' },
|
||||||
{ divider: true },
|
{ divider: true },
|
||||||
isSqlOrDoc && !connection.isReadOnly && { onClick: handleImport, text: 'Import wizard' },
|
isSqlOrDoc && !connection.isReadOnly && { onClick: handleImport, text: 'Import wizard' },
|
||||||
isSqlOrDoc && { onClick: handleExport, text: 'Export wizard' },
|
isSqlOrDoc && { onClick: handleExport, text: 'Export wizard' },
|
||||||
|
|||||||
@@ -276,6 +276,11 @@ const driver = {
|
|||||||
await db.createCollection('collection1');
|
await db.createCollection('collection1');
|
||||||
},
|
},
|
||||||
|
|
||||||
|
async dropDatabase(pool, name) {
|
||||||
|
const db = pool.db(name);
|
||||||
|
await db.dropDatabase();
|
||||||
|
},
|
||||||
|
|
||||||
async loadFieldValues(pool, name, field, search) {
|
async loadFieldValues(pool, name, field, search) {
|
||||||
try {
|
try {
|
||||||
const collection = pool.__getDatabase().collection(name.pureName);
|
const collection = pool.__getDatabase().collection(name.pureName);
|
||||||
|
|||||||
@@ -16,6 +16,16 @@ class MsSqlDumper extends SqlDumper {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
dropDatabase(name) {
|
||||||
|
this.putCmd(
|
||||||
|
`USE master;
|
||||||
|
ALTER DATABASE %i SET SINGLE_USER WITH ROLLBACK IMMEDIATE;
|
||||||
|
DROP DATABASE %i`,
|
||||||
|
name,
|
||||||
|
name
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
autoIncrement() {
|
autoIncrement() {
|
||||||
this.put(' ^identity');
|
this.put(' ^identity');
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,6 +26,10 @@ class Dumper extends SqlDumper {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
dropDatabase(name) {
|
||||||
|
this.putCmd('^drop ^database %i ^with(^force)', name);
|
||||||
|
}
|
||||||
|
|
||||||
dropRecreatedTempTable(tmptable) {
|
dropRecreatedTempTable(tmptable) {
|
||||||
this.putCmd('^drop ^table %i ^cascade', tmptable);
|
this.putCmd('^drop ^table %i ^cascade', tmptable);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user