Remove dacfx and schema compare from the azdata api (#6684)

* refactor mssql extension to directly expose dacfx and schema compare

* remove more code

* fix compile errors
This commit is contained in:
Anthony Dresser
2019-08-19 16:34:09 -07:00
committed by GitHub
parent 87b0e08a6a
commit 986ad33678
40 changed files with 1196 additions and 1556 deletions

View File

@@ -8,6 +8,7 @@ import * as azdata from 'azdata';
import * as vscode from 'vscode';
import * as os from 'os';
import * as path from 'path';
import * as mssql from '../../mssql';
import { SchemaCompareOptionsDialog } from './dialogs/schemaCompareOptionsDialog';
import { Telemetry } from './telemetry';
import { getTelemetryErrorType, getEndpointName, verifyConnectionAndGetOwnerUri } from './utils';
@@ -56,28 +57,28 @@ export class SchemaCompareMainWindow {
private saveScmpButton: azdata.ButtonComponent;
private SchemaCompareActionMap: Map<Number, string>;
private operationId: string;
private comparisonResult: azdata.SchemaCompareResult;
private comparisonResult: mssql.SchemaCompareResult;
private sourceNameComponent: azdata.TableComponent;
private targetNameComponent: azdata.TableComponent;
private deploymentOptions: azdata.DeploymentOptions;
private deploymentOptions: mssql.DeploymentOptions;
private schemaCompareOptionDialog: SchemaCompareOptionsDialog;
private tablelistenersToDispose: vscode.Disposable[] = [];
private originalSourceExcludes = new Map<string, azdata.DiffEntry>();
private originalTargetExcludes = new Map<string, azdata.DiffEntry>();
private originalSourceExcludes = new Map<string, mssql.DiffEntry>();
private originalTargetExcludes = new Map<string, mssql.DiffEntry>();
private sourceTargetSwitched = false;
private sourceName: string;
private targetName: string;
private scmpSourceExcludes: azdata.SchemaCompareObjectId[];
private scmpTargetExcludes: azdata.SchemaCompareObjectId[];
private scmpSourceExcludes: mssql.SchemaCompareObjectId[];
private scmpTargetExcludes: mssql.SchemaCompareObjectId[];
public sourceEndpointInfo: azdata.SchemaCompareEndpointInfo;
public targetEndpointInfo: azdata.SchemaCompareEndpointInfo;
public sourceEndpointInfo: mssql.SchemaCompareEndpointInfo;
public targetEndpointInfo: mssql.SchemaCompareEndpointInfo;
constructor() {
this.SchemaCompareActionMap = new Map<Number, string>();
this.SchemaCompareActionMap[azdata.SchemaUpdateAction.Delete] = localize('schemaCompare.deleteAction', 'Delete');
this.SchemaCompareActionMap[azdata.SchemaUpdateAction.Change] = localize('schemaCompare.changeAction', 'Change');
this.SchemaCompareActionMap[azdata.SchemaUpdateAction.Add] = localize('schemaCompare.addAction', 'Add');
this.SchemaCompareActionMap[mssql.SchemaUpdateAction.Delete] = localize('schemaCompare.deleteAction', 'Delete');
this.SchemaCompareActionMap[mssql.SchemaUpdateAction.Change] = localize('schemaCompare.changeAction', 'Change');
this.SchemaCompareActionMap[mssql.SchemaUpdateAction.Add] = localize('schemaCompare.addAction', 'Add');
this.editor = azdata.workspace.createModelViewEditor(localize('schemaCompare.Title', 'Schema Compare'), { retainContextWhenHidden: true, supportsSave: true, resourceName: schemaCompareResourceName });
}
@@ -88,7 +89,7 @@ export class SchemaCompareMainWindow {
if (profile) {
let ownerUri = await azdata.connection.getUriForConnection((profile.id));
this.sourceEndpointInfo = {
endpointType: azdata.SchemaCompareEndpointType.Database,
endpointType: mssql.SchemaCompareEndpointType.Database,
serverDisplayName: `${profile.serverName} ${profile.userName}`,
serverName: profile.serverName,
databaseName: profile.databaseName,
@@ -257,16 +258,16 @@ export class SchemaCompareMainWindow {
}
// only for test
public getComparisonResult(): azdata.SchemaCompareResult {
public getComparisonResult(): mssql.SchemaCompareResult {
return this.comparisonResult;
}
// only for test
public getDeploymentOptions(): azdata.DeploymentOptions {
public getDeploymentOptions(): mssql.DeploymentOptions {
return this.deploymentOptions;
}
public setDeploymentOptions(deploymentOptions: azdata.DeploymentOptions): void {
public setDeploymentOptions(deploymentOptions: mssql.DeploymentOptions): void {
this.deploymentOptions = deploymentOptions;
}
@@ -348,7 +349,7 @@ export class SchemaCompareMainWindow {
this.flexModel.addItem(this.splitView, { CSSStyles: { 'overflow': 'hidden' } });
// only enable generate script button if the target is a db
if (this.targetEndpointInfo.endpointType === azdata.SchemaCompareEndpointType.Database) {
if (this.targetEndpointInfo.endpointType === mssql.SchemaCompareEndpointType.Database) {
this.generateScriptButton.enabled = true;
this.applyButton.enabled = true;
} else {
@@ -435,7 +436,7 @@ export class SchemaCompareMainWindow {
}
}
private shouldDiffBeIncluded(diff: azdata.DiffEntry): boolean {
private shouldDiffBeIncluded(diff: mssql.DiffEntry): boolean {
let key = (diff.sourceValue && diff.sourceValue.length > 0) ? this.createName(diff.sourceValue) : this.createName(diff.targetValue);
if (key) {
if (this.sourceTargetSwitched === true
@@ -453,7 +454,7 @@ export class SchemaCompareMainWindow {
return true;
}
private hasExcludeEntry(collection: azdata.SchemaCompareObjectId[], entryName: string): boolean {
private hasExcludeEntry(collection: mssql.SchemaCompareObjectId[], entryName: string): boolean {
let found = false;
if (collection) {
const index = collection.findIndex(e => this.createName(e.nameParts) === entryName);
@@ -462,7 +463,7 @@ export class SchemaCompareMainWindow {
return found;
}
private removeExcludeEntry(collection: azdata.SchemaCompareObjectId[], entryName: string) {
private removeExcludeEntry(collection: mssql.SchemaCompareObjectId[], entryName: string) {
if (collection) {
console.error('removing ' + entryName);
const index = collection.findIndex(e => this.createName(e.nameParts) === entryName);
@@ -470,12 +471,12 @@ export class SchemaCompareMainWindow {
}
}
private getAllDifferences(differences: azdata.DiffEntry[]): string[][] {
private getAllDifferences(differences: mssql.DiffEntry[]): string[][] {
let data = [];
let finalDifferences: azdata.DiffEntry[] = [];
let finalDifferences: mssql.DiffEntry[] = [];
if (differences) {
differences.forEach(difference => {
if (difference.differenceType === azdata.SchemaDifferenceType.Object) {
if (difference.differenceType === mssql.SchemaDifferenceType.Object) {
if ((difference.sourceValue !== null && difference.sourceValue.length > 0) || (difference.targetValue !== null && difference.targetValue.length > 0)) {
finalDifferences.push(difference); // Add only non-null changes to ensure index does not mismatch between dictionay and UI - #6234
let state: boolean = this.shouldDiffBeIncluded(difference);
@@ -495,7 +496,7 @@ export class SchemaCompareMainWindow {
return nameParts.join('.');
}
private getFormattedScript(diffEntry: azdata.DiffEntry, getSourceScript: boolean): string {
private getFormattedScript(diffEntry: mssql.DiffEntry, getSourceScript: boolean): string {
// if there is no entry, the script has to be \n because an empty string shows up as a difference but \n doesn't
if ((getSourceScript && diffEntry.sourceScript === null)
|| (!getSourceScript && diffEntry.targetScript === null)) {
@@ -506,7 +507,7 @@ export class SchemaCompareMainWindow {
return script;
}
private getAggregatedScript(diffEntry: azdata.DiffEntry, getSourceScript: boolean): string {
private getAggregatedScript(diffEntry: mssql.DiffEntry, getSourceScript: boolean): string {
let script = '';
if (diffEntry !== null) {
let diffEntryScript = getSourceScript ? diffEntry.sourceScript : diffEntry.targetScript;
@@ -880,7 +881,7 @@ export class SchemaCompareMainWindow {
return;
}
if (result.sourceEndpointInfo && result.sourceEndpointInfo.endpointType === azdata.SchemaCompareEndpointType.Database) {
if (result.sourceEndpointInfo && result.sourceEndpointInfo.endpointType === mssql.SchemaCompareEndpointType.Database) {
// only set endpoint info if able to connect to the database
const ownerUri = await verifyConnectionAndGetOwnerUri(result.sourceEndpointInfo);
if (ownerUri) {
@@ -890,7 +891,7 @@ export class SchemaCompareMainWindow {
} else {
// need to do this instead of just setting it to the result.sourceEndpointInfo because some fields are null which will cause an error when sending the compare request
this.sourceEndpointInfo = {
endpointType: azdata.SchemaCompareEndpointType.Dacpac,
endpointType: mssql.SchemaCompareEndpointType.Dacpac,
serverDisplayName: '',
serverName: '',
databaseName: '',
@@ -900,7 +901,7 @@ export class SchemaCompareMainWindow {
};
}
if (result.targetEndpointInfo && result.targetEndpointInfo.endpointType === azdata.SchemaCompareEndpointType.Database) {
if (result.targetEndpointInfo && result.targetEndpointInfo.endpointType === mssql.SchemaCompareEndpointType.Database) {
const ownerUri = await verifyConnectionAndGetOwnerUri(result.targetEndpointInfo);
if (ownerUri) {
this.targetEndpointInfo = result.targetEndpointInfo;
@@ -909,7 +910,7 @@ export class SchemaCompareMainWindow {
} else {
// need to do this instead of just setting it to the result.targetEndpointInfo because some fields are null which will cause an error when sending the compare request
this.targetEndpointInfo = {
endpointType: azdata.SchemaCompareEndpointType.Dacpac,
endpointType: mssql.SchemaCompareEndpointType.Dacpac,
serverDisplayName: '',
serverName: '',
databaseName: '',
@@ -962,8 +963,8 @@ export class SchemaCompareMainWindow {
}
// 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 sourceExcludes: mssql.SchemaCompareObjectId[] = this.convertExcludesToObjectIds(this.originalSourceExcludes);
let targetExcludes: mssql.SchemaCompareObjectId[] = this.convertExcludesToObjectIds(this.originalTargetExcludes);
let startTime = Date.now();
Telemetry.sendTelemetryEvent('SchemaCompareSaveScmp');
@@ -988,9 +989,9 @@ export class SchemaCompareMainWindow {
/**
* 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[] {
private convertExcludesToObjectIds(excludedDiffEntries: Map<string, mssql.DiffEntry>): mssql.SchemaCompareObjectId[] {
let result = [];
excludedDiffEntries.forEach((value: azdata.DiffEntry) => {
excludedDiffEntries.forEach((value: mssql.DiffEntry) => {
result.push({
nameParts: value.sourceValue ? value.sourceValue : value.targetValue,
sqlObjectType: `Microsoft.Data.Tools.Schema.Sql.SchemaModel.${value.name}`
@@ -1002,7 +1003,7 @@ export class SchemaCompareMainWindow {
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) {
if (this.targetEndpointInfo.endpointType === mssql.SchemaCompareEndpointType.Database) {
this.applyButton.enabled = enableButtons;
this.generateScriptButton.enabled = enableButtons;
this.applyButton.title = enableButtons ? applyEnabledMessage : applyNoChangesMessage;
@@ -1010,8 +1011,8 @@ export class SchemaCompareMainWindow {
}
}
private static async getService(providerName: string): Promise<azdata.SchemaCompareServicesProvider> {
let service = azdata.dataprotocol.getProvider<azdata.SchemaCompareServicesProvider>(providerName, azdata.DataProviderType.SchemaCompareServicesProvider);
private static async getService(providerName: string): Promise<mssql.ISchemaCompareService> {
let service = (vscode.extensions.getExtension(mssql.extension.name).exports as mssql.mssql).schemaCompare;
return service;
}