mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-16 10:58:30 -05:00
Add Detach Database option to database context menu (#23480)
This commit is contained in:
@@ -0,0 +1,57 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import { ObjectManagementDialogBase, ObjectManagementDialogOptions } from './objectManagementDialogBase';
|
||||
import { IObjectManagementService, ObjectManagement } from 'mssql';
|
||||
import { Database, DatabaseViewInfo } from '../interfaces';
|
||||
import { DetachDatabaseDocUrl } from '../constants';
|
||||
import { DatabaseFileGroupLabel, DatabaseFileNameLabel, DatabaseFilePathLabel, DatabaseFileTypeLabel, DatabaseFilesLabel, DetachDatabaseDialogTitle, DetachDatabaseOptions, DetachDropConnections, DetachUpdateStatistics } from '../localizedConstants';
|
||||
|
||||
export class DetachDatabaseDialog extends ObjectManagementDialogBase<Database, DatabaseViewInfo> {
|
||||
private _dropConnections = false;
|
||||
private _updateStatistics = false;
|
||||
|
||||
constructor(objectManagementService: IObjectManagementService, options: ObjectManagementDialogOptions) {
|
||||
super(objectManagementService, options, DetachDatabaseDialogTitle(options.database), 'DetachDatabase');
|
||||
}
|
||||
|
||||
protected override get isDirty(): boolean {
|
||||
return true;
|
||||
}
|
||||
|
||||
protected async initializeUI(): Promise<void> {
|
||||
let tableData = this.viewInfo.files.map(file => [file.name, file.type, file.fileGroup, file.path]);
|
||||
let columnNames = [DatabaseFileNameLabel, DatabaseFileTypeLabel, DatabaseFileGroupLabel, DatabaseFilePathLabel];
|
||||
let fileTable = this.createTable(DatabaseFilesLabel, columnNames, tableData);
|
||||
let tableGroup = this.createGroup(DatabaseFilesLabel, [fileTable], false);
|
||||
|
||||
let connCheckbox = this.createCheckbox(DetachDropConnections, async checked => {
|
||||
this._dropConnections = checked;
|
||||
});
|
||||
let updateCheckbox = this.createCheckbox(DetachUpdateStatistics, async checked => {
|
||||
this._updateStatistics = checked;
|
||||
});
|
||||
let checkboxGroup = this.createGroup(DetachDatabaseOptions, [connCheckbox, updateCheckbox], false);
|
||||
|
||||
let components = [tableGroup, checkboxGroup];
|
||||
this.formContainer.addItems(components);
|
||||
}
|
||||
|
||||
protected override get helpUrl(): string {
|
||||
return DetachDatabaseDocUrl;
|
||||
}
|
||||
|
||||
protected override async saveChanges(contextId: string, object: ObjectManagement.SqlObject): Promise<void> {
|
||||
await this.objectManagementService.detachDatabase(this.options.connectionUri, this.options.objectUrn, this._dropConnections, this._updateStatistics, false);
|
||||
}
|
||||
|
||||
protected override async generateScript(): Promise<string> {
|
||||
return await this.objectManagementService.detachDatabase(this.options.connectionUri, this.options.objectUrn, this._dropConnections, this._updateStatistics, true);
|
||||
}
|
||||
|
||||
protected override async validateInput(): Promise<string[]> {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
@@ -35,12 +35,16 @@ export abstract class ObjectManagementDialogBase<ObjectInfoType extends ObjectMa
|
||||
private _viewInfo: ViewInfoType;
|
||||
private _originalObjectInfo: ObjectInfoType;
|
||||
|
||||
constructor(protected readonly objectManagementService: IObjectManagementService, options: ObjectManagementDialogOptions) {
|
||||
super(options.isNewObject ? localizedConstants.NewObjectDialogTitle(localizedConstants.getNodeTypeDisplayName(options.objectType, true)) :
|
||||
localizedConstants.ObjectPropertiesDialogTitle(localizedConstants.getNodeTypeDisplayName(options.objectType, true), options.objectName),
|
||||
getDialogName(options.objectType, options.isNewObject),
|
||||
options
|
||||
);
|
||||
constructor(protected readonly objectManagementService: IObjectManagementService, options: ObjectManagementDialogOptions, dialogTitle?: string, dialogName?: string) {
|
||||
if (!dialogTitle) {
|
||||
dialogTitle = options.isNewObject
|
||||
? localizedConstants.NewObjectDialogTitle(localizedConstants.getNodeTypeDisplayName(options.objectType, true))
|
||||
: localizedConstants.ObjectPropertiesDialogTitle(localizedConstants.getNodeTypeDisplayName(options.objectType, true), options.objectName);
|
||||
}
|
||||
if (!dialogName) {
|
||||
dialogName = getDialogName(options.objectType, options.isNewObject);
|
||||
}
|
||||
super(dialogTitle, dialogName, options);
|
||||
this._contextId = generateUuid();
|
||||
}
|
||||
|
||||
@@ -54,6 +58,10 @@ export abstract class ObjectManagementDialogBase<ObjectInfoType extends ObjectMa
|
||||
return errors;
|
||||
}
|
||||
|
||||
protected async saveChanges(contextId: string, object: ObjectManagement.SqlObject): Promise<void> {
|
||||
await this.objectManagementService.save(this._contextId, this.objectInfo);
|
||||
}
|
||||
|
||||
protected override async initialize(): Promise<void> {
|
||||
await super.initialize();
|
||||
const typeDisplayName = localizedConstants.getNodeTypeDisplayName(this.options.objectType);
|
||||
@@ -67,7 +75,7 @@ export abstract class ObjectManagementDialogBase<ObjectInfoType extends ObjectMa
|
||||
try {
|
||||
if (this.isDirty) {
|
||||
const startTime = Date.now();
|
||||
await this.objectManagementService.save(this._contextId, this.objectInfo);
|
||||
await this.saveChanges(this._contextId, this.objectInfo);
|
||||
if (this.options.objectExplorerContext) {
|
||||
if (this.options.isNewObject) {
|
||||
await refreshNode(this.options.objectExplorerContext);
|
||||
|
||||
Reference in New Issue
Block a user