From 4b1088edbc73a0f41d21f230f58ac1c95ba16da2 Mon Sep 17 00:00:00 2001 From: udeeshagautam <46980425+udeeshagautam@users.noreply.github.com> Date: Wed, 29 May 2019 13:30:22 -0700 Subject: [PATCH] Bug/schema compare apply confirmation (#5698) * Ask confirmation before apply * Adding PR comments --- extensions/mssql/src/config.json | 2 +- .../schema-compare/src/schemaCompareResult.ts | 50 +++++++++++-------- 2 files changed, 30 insertions(+), 22 deletions(-) diff --git a/extensions/mssql/src/config.json b/extensions/mssql/src/config.json index 0573ac4274..3da2f1ed58 100644 --- a/extensions/mssql/src/config.json +++ b/extensions/mssql/src/config.json @@ -1,6 +1,6 @@ { "downloadUrl": "https://github.com/Microsoft/sqltoolsservice/releases/download/v{#version#}/microsoft.sqltools.servicelayer-{#fileName#}", - "version": "1.5.0-alpha.96", + "version": "1.5.0-alpha.98", "downloadFileNames": { "Windows_86": "win-x86-netcoreapp2.2.zip", "Windows_64": "win-x64-netcoreapp2.2.zip", diff --git a/extensions/schema-compare/src/schemaCompareResult.ts b/extensions/schema-compare/src/schemaCompareResult.ts index 6a8289d81f..f9100eaed5 100644 --- a/extensions/schema-compare/src/schemaCompareResult.ts +++ b/extensions/schema-compare/src/schemaCompareResult.ts @@ -13,6 +13,7 @@ import { Telemetry } from './telemetry'; import { getTelemetryErrorType } from './utils'; const localize = nls.loadMessageBundle(); const diffEditorTitle = localize('schemaCompare.ObjectDefinitionsTitle', 'Object Definitions'); +const applyConfirmation = localize('schemaCompare.ApplyConfirmation', 'Are you sure you want to update the target?'); export class SchemaCompareResult { private differencesTable: azdata.TableComponent; @@ -182,7 +183,7 @@ export class SchemaCompareResult { this.deploymentOptions = this.schemaCompareOptionDialog.deploymentOptions; } Telemetry.sendTelemetryEvent('SchemaComparisonStarted'); - let service = await SchemaCompareResult.getService('MSSQL'); + const service = await SchemaCompareResult.getService('MSSQL'); this.comparisonResult = await service.schemaCompare(this.sourceEndpointInfo, this.targetEndpointInfo, azdata.TaskExecutionMode.execute, this.deploymentOptions); if (!this.comparisonResult || !this.comparisonResult.success) { Telemetry.sendTelemetryEventForError('SchemaComparisonFailed', { @@ -431,8 +432,8 @@ export class SchemaCompareResult { 'startTime:': Date.now().toString(), 'operationId': this.comparisonResult.operationId }); - let service = await SchemaCompareResult.getService('MSSQL'); - let result = await service.schemaCompareGenerateScript(this.comparisonResult.operationId, this.targetEndpointInfo.serverName, this.targetEndpointInfo.databaseName, azdata.TaskExecutionMode.script); + const service = await SchemaCompareResult.getService('MSSQL'); + const result = await service.schemaCompareGenerateScript(this.comparisonResult.operationId, this.targetEndpointInfo.serverName, this.targetEndpointInfo.databaseName, azdata.TaskExecutionMode.script); if (!result || !result.success) { Telemetry.sendTelemetryEvent('SchemaCompareGenerateScriptFailed', { 'errorType': getTelemetryErrorType(result.errorMessage), @@ -482,24 +483,31 @@ export class SchemaCompareResult { }, }).component(); + // need only yes button - since the modal dialog has a default cancel + const yesString = localize('schemaCompare.ApplyYes', 'Yes'); this.applyButton.onDidClick(async (click) => { - Telemetry.sendTelemetryEvent('SchemaCompareApplyStarted', { - 'startTime': Date.now().toString(), - 'operationId': this.comparisonResult.operationId - }); - let service = await SchemaCompareResult.getService('MSSQL'); - let result = await service.schemaComparePublishChanges(this.comparisonResult.operationId, this.targetEndpointInfo.serverName, this.targetEndpointInfo.databaseName, azdata.TaskExecutionMode.execute); - if (!result || !result.success) { - Telemetry.sendTelemetryEvent('SchemaCompareApplyFailed', { - 'errorType': getTelemetryErrorType(result.errorMessage), - 'operationId': this.comparisonResult.operationId - }); - vscode.window.showErrorMessage( - localize('schemaCompare.updateErrorMessage', "Schema Compare Apply failed '{0}'", result.errorMessage ? result.errorMessage : 'Unknown')); - } - Telemetry.sendTelemetryEvent('SchemaCompareApplyEnded', { - 'endTime': Date.now().toString(), - 'operationId': this.comparisonResult.operationId + + vscode.window.showWarningMessage(applyConfirmation, { modal: true }, yesString).then(async (result) => { + if (result === yesString) { + Telemetry.sendTelemetryEvent('SchemaCompareApplyStarted', { + 'startTime': Date.now().toString(), + 'operationId': this.comparisonResult.operationId + }); + const service = await SchemaCompareResult.getService('MSSQL'); + const result = await service.schemaComparePublishChanges(this.comparisonResult.operationId, this.targetEndpointInfo.serverName, this.targetEndpointInfo.databaseName, azdata.TaskExecutionMode.execute); + if (!result || !result.success) { + Telemetry.sendTelemetryEvent('SchemaCompareApplyFailed', { + 'errorType': getTelemetryErrorType(result.errorMessage), + 'operationId': this.comparisonResult.operationId + }); + vscode.window.showErrorMessage( + localize('schemaCompare.updateErrorMessage', "Schema Compare Apply failed '{0}'", result.errorMessage ? result.errorMessage : 'Unknown')); + } + Telemetry.sendTelemetryEvent('SchemaCompareApplyEnded', { + 'endTime': Date.now().toString(), + 'operationId': this.comparisonResult.operationId + }); + } }); }); } @@ -571,7 +579,7 @@ export class SchemaCompareResult { private async GetDefaultDeploymentOptions(): Promise { // Same as dacfx default options - let service = await SchemaCompareResult.getService('MSSQL'); + const service = await SchemaCompareResult.getService('MSSQL'); let result = await service.schemaCompareGetDefaultOptions(); this.deploymentOptions = result.defaultDeploymentOptions; }