mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-27 09:06:00 +00:00
renameCollection, cloneCollection - in driver
This commit is contained in:
@@ -93,7 +93,7 @@
|
|||||||
{
|
{
|
||||||
divider: true,
|
divider: true,
|
||||||
},
|
},
|
||||||
{
|
hasPermission('dbops/model/edit') && {
|
||||||
label: 'Drop table',
|
label: 'Drop table',
|
||||||
isDrop: true,
|
isDrop: true,
|
||||||
requiresWriteAccess: true,
|
requiresWriteAccess: true,
|
||||||
@@ -394,22 +394,22 @@
|
|||||||
forceNewTab: true,
|
forceNewTab: true,
|
||||||
icon: 'img perspective',
|
icon: 'img perspective',
|
||||||
},
|
},
|
||||||
{
|
hasPermission('dbops/export') && {
|
||||||
label: 'Export',
|
label: 'Export',
|
||||||
isExport: true,
|
isExport: true,
|
||||||
functionName: 'tableReader',
|
functionName: 'tableReader',
|
||||||
},
|
},
|
||||||
{
|
hasPermission('dbops/model/edit') && {
|
||||||
label: 'Drop collection',
|
label: 'Drop collection',
|
||||||
isDropCollection: true,
|
isDropCollection: true,
|
||||||
requiresWriteAccess: true,
|
requiresWriteAccess: true,
|
||||||
},
|
},
|
||||||
{
|
hasPermission('dbops/table/rename') && {
|
||||||
label: 'Rename collection',
|
label: 'Rename collection',
|
||||||
isRenameCollection: true,
|
isRenameCollection: true,
|
||||||
requiresWriteAccess: true,
|
requiresWriteAccess: true,
|
||||||
},
|
},
|
||||||
{
|
hasPermission('dbops/table/backup') && {
|
||||||
label: 'Create collection backup',
|
label: 'Create collection backup',
|
||||||
isDuplicateCollection: true,
|
isDuplicateCollection: true,
|
||||||
requiresWriteAccess: true,
|
requiresWriteAccess: true,
|
||||||
@@ -563,11 +563,11 @@
|
|||||||
value: data.pureName,
|
value: data.pureName,
|
||||||
onConfirm: async newName => {
|
onConfirm: async newName => {
|
||||||
const dbid = _.pick(data, ['conid', 'database']);
|
const dbid = _.pick(data, ['conid', 'database']);
|
||||||
await apiCall('database-connections/run-script', {
|
runOperationOnDatabase(dbid, {
|
||||||
...dbid,
|
type: 'renameCollection',
|
||||||
sql: `db.renameCollection('${data.pureName}', '${newName}')`,
|
collection: data.pureName,
|
||||||
|
newName,
|
||||||
});
|
});
|
||||||
apiCall('database-connections/sync-model', dbid);
|
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
} else if (menu.isDuplicateCollection) {
|
} else if (menu.isDuplicateCollection) {
|
||||||
@@ -577,7 +577,11 @@
|
|||||||
message: `Really create collection copy named ${newName}?`,
|
message: `Really create collection copy named ${newName}?`,
|
||||||
onConfirm: async () => {
|
onConfirm: async () => {
|
||||||
const dbid = _.pick(data, ['conid', 'database']);
|
const dbid = _.pick(data, ['conid', 'database']);
|
||||||
saveScriptToDatabase(dbid, `db.collection('${data.pureName}').aggregate([{$out: '${newName}'}]).toArray()`);
|
runOperationOnDatabase(dbid, {
|
||||||
|
type: 'cloneCollection',
|
||||||
|
collection: data.pureName,
|
||||||
|
newName,
|
||||||
|
});
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
} else if (menu.isDuplicateTable) {
|
} else if (menu.isDuplicateTable) {
|
||||||
|
|||||||
@@ -107,6 +107,15 @@ const driver = {
|
|||||||
case 'dropCollection':
|
case 'dropCollection':
|
||||||
await this.script(pool, `db.dropCollection('${operation.collection}')`);
|
await this.script(pool, `db.dropCollection('${operation.collection}')`);
|
||||||
break;
|
break;
|
||||||
|
case 'renameCollection':
|
||||||
|
await this.script(pool, `db.renameCollection('${operation.collection}', '${operation.newName}')`);
|
||||||
|
break;
|
||||||
|
case 'cloneCollection':
|
||||||
|
await this.script(
|
||||||
|
pool,
|
||||||
|
`db.collection('${operation.collection}').aggregate([{$out: '${operation.newName}'}]).toArray()`
|
||||||
|
);
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
throw new Error(`Operation type ${type} not supported`);
|
throw new Error(`Operation type ${type} not supported`);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user