Schema Compare save scmp file (#6150)

* initial changes

* send source and target excludes

* disable save scmp button until there is source and target

* addressing comments
This commit is contained in:
Kim Santiago
2019-06-25 15:07:58 -07:00
committed by GitHub
parent ac76302d6c
commit f01c318c30
10 changed files with 136 additions and 3 deletions

View File

@@ -0,0 +1,3 @@
<svg width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M14 1C14.1406 1 14.2708 1.02604 14.3906 1.07812C14.5104 1.13021 14.6146 1.20312 14.7031 1.29688C14.7969 1.38542 14.8698 1.48958 14.9219 1.60938C14.974 1.72917 15 1.85938 15 2V15H2.78906L1 13.2031V2C1 1.85938 1.02604 1.72917 1.07812 1.60938C1.13021 1.48958 1.20052 1.38542 1.28906 1.29688C1.38281 1.20312 1.48958 1.13021 1.60938 1.07812C1.72917 1.02604 1.85938 1 2 1H14ZM4 7H12V2H4V7ZM10 11H5V14H6V12H7V14H10V11ZM14 2H13V8H3V2H2V12.7891L3.20312 14H4V10H11V14H14V2Z" fill="#4894FE"/>
</svg>

After

Width:  |  Height:  |  Size: 594 B

View File

@@ -0,0 +1,3 @@
<svg width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M14 1C14.1406 1 14.2708 1.02604 14.3906 1.07812C14.5104 1.13021 14.6146 1.20312 14.7031 1.29688C14.7969 1.38542 14.8698 1.48958 14.9219 1.60938C14.974 1.72917 15 1.85938 15 2V15H2.78906L1 13.2031V2C1 1.85938 1.02604 1.72917 1.07812 1.60938C1.13021 1.48958 1.20052 1.38542 1.28906 1.29688C1.38281 1.20312 1.48958 1.13021 1.60938 1.07812C1.72917 1.02604 1.85938 1 2 1H14ZM4 7H12V2H4V7ZM10 11H5V14H6V12H7V14H10V11ZM14 2H13V8H3V2H2V12.7891L3.20312 14H4V10H11V14H14V2Z" fill="#015CDA"/>
</svg>

After

Width:  |  Height:  |  Size: 594 B

View File

@@ -46,6 +46,7 @@ export class SchemaCompareResult {
private applyButton: azdata.ButtonComponent;
private selectSourceButton: azdata.ButtonComponent;
private selectTargetButton: azdata.ButtonComponent;
private saveScmpButton: azdata.ButtonComponent;
private SchemaCompareActionMap: Map<Number, string>;
private operationId: string;
private comparisonResult: azdata.SchemaCompareResult;
@@ -121,6 +122,7 @@ export class SchemaCompareResult {
this.createApplyButton(view);
this.createOptionsButton(view);
this.createSourceAndTargetButtons(view);
this.createSaveScmpButton(view);
this.resetButtons(false); // disable buttons because source and target aren't both selected yet
let toolBar = view.modelBuilder.toolbarContainer();
@@ -136,7 +138,10 @@ export class SchemaCompareResult {
component: this.optionsButton,
toolbarSeparatorAfter: true
}, {
component: this.switchButton
component: this.switchButton,
toolbarSeparatorAfter: true
}, {
component: this.saveScmpButton
}]);
let sourceLabel = view.modelBuilder.text().withProperties({
@@ -674,6 +679,7 @@ export class SchemaCompareResult {
this.optionsButton.enabled = true;
this.switchButton.enabled = true;
this.cancelCompareButton.enabled = false;
this.saveScmpButton.enabled = true;
}
else {
this.compareButton.enabled = false;
@@ -761,6 +767,72 @@ export class SchemaCompareResult {
});
}
private createSaveScmpButton(view: azdata.ModelView): void {
this.saveScmpButton = view.modelBuilder.button().withProperties({
label: localize('schemaCompare.saveScmpButton', 'Save .scmp file'),
iconPath: {
light: path.join(__dirname, 'media', 'save-scmp.svg'),
dark: path.join(__dirname, 'media', 'save-scmp-inverse.svg')
},
title: localize('schemaCompare.saveScmpButtonTitle', 'Save source and target, options, and excluded elements'),
enabled: false
}).component();
this.saveScmpButton.onDidClick(async (click) => {
const rootPath = vscode.workspace.rootPath ? vscode.workspace.rootPath : os.homedir();
const filePath = await vscode.window.showSaveDialog(
{
defaultUri: vscode.Uri.file(rootPath),
saveLabel: localize('schemaCompare.saveFile', 'Save'),
filters: {
'scmp Files': ['scmp'],
}
}
);
if (!filePath) {
return;
}
// convert include/exclude maps to arrays of object ids
let sourceExcludes: azdata.SchemaCompareObjectId[] = this.convertExcludesToObjectIds(this.originalSourceExcludes);
let targetExcludes: azdata.SchemaCompareObjectId[] = this.convertExcludesToObjectIds(this.originalTargetExcludes);
let startTime = Date.now();
Telemetry.sendTelemetryEvent('SchemaCompareSaveScmp');
const service = await SchemaCompareResult.getService(msSqlProvider);
const result = await service.schemaCompareSaveScmp(this.sourceEndpointInfo, this.targetEndpointInfo, azdata.TaskExecutionMode.execute, this.deploymentOptions, filePath.fsPath, sourceExcludes, targetExcludes);
if (!result || !result.success) {
Telemetry.sendTelemetryEvent('SchemaCompareSaveScmpFailed', {
'errorType': getTelemetryErrorType(result.errorMessage),
'operationId': this.comparisonResult.operationId
});
vscode.window.showErrorMessage(
localize('schemaCompare.saveScmpErrorMessage', "Save scmp failed: '{0}'", (result && result.errorMessage) ? result.errorMessage : 'Unknown'));
}
Telemetry.sendTelemetryEvent('SchemaCompareSaveScmpEnded', {
'totalSaveTime:': (Date.now() - startTime).toString(),
'operationId': this.comparisonResult.operationId
});
});
}
/**
* Converts excluded diff entries into object ids which are needed to save them in an scmp
*/
private convertExcludesToObjectIds(excludedDiffEntries: Map<string, azdata.DiffEntry>): azdata.SchemaCompareObjectId[] {
let result = [];
excludedDiffEntries.forEach((value: azdata.DiffEntry) => {
result.push({
nameParts: value.sourceValue ? value.sourceValue : value.targetValue,
sqlObjectType: `Microsoft.Data.Tools.Schema.Sql.SchemaModel.${value.name}`
});
});
return result;
}
private setButtonStatesForNoChanges(enableButtons: boolean): void {
// generate script and apply can only be enabled if the target is a database
if (this.targetEndpointInfo.endpointType === azdata.SchemaCompareEndpointType.Database) {

View File

@@ -27,6 +27,11 @@ export class SchemaCompareTestService implements azdata.SchemaCompareServicesPro
throw new Error('Method not implemented.');
}
schemaCompareSaveScmp(sourceEndpointInfo: azdata.SchemaCompareEndpointInfo, targetEndpointInfo: azdata.SchemaCompareEndpointInfo, taskExecutionMode: azdata.TaskExecutionMode, deploymentOptions: azdata.DeploymentOptions, scmpFilePath: string, excludedSourceObjects: azdata.SchemaCompareObjectId[], excludedTargetObjects: azdata.SchemaCompareObjectId[]): Thenable<azdata.ResultStatus> {
throw new Error('Method not implemented.');
}
schemaCompare(operationId: string, sourceEndpointInfo: azdata.SchemaCompareEndpointInfo, targetEndpointInfo: azdata.SchemaCompareEndpointInfo, taskExecutionMode: azdata.TaskExecutionMode): Thenable<azdata.SchemaCompareResult> {
let result: azdata.SchemaCompareResult = {
operationId: this.testOperationId,