Add sql proj schema compare for dacpac (#10388)

* add support for schema compare to specify source dacpac

* add build and dacpac produced from build

* check if dacpac exists

* add tests

* move exists check code to utils

* fix test run failing
This commit is contained in:
Kim Santiago
2020-05-15 13:03:08 -07:00
committed by GitHub
parent ef4ab4a59f
commit b83279c24c
7 changed files with 97 additions and 1 deletions

View File

@@ -30,7 +30,7 @@ export default class MainController implements vscode.Disposable {
}
private initializeSchemaCompareDialog(): void {
azdata.tasks.registerTask('schemaCompare.start', (profile: azdata.IConnectionProfile) => new SchemaCompareMainWindow(null, this.extensionContext).start(profile));
vscode.commands.registerCommand('schemaCompare.start', (context: any) => new SchemaCompareMainWindow(null, this.extensionContext).start(context));
}
public dispose(): void {

View File

@@ -77,9 +77,14 @@ export class SchemaCompareMainWindow {
this.editor = azdata.workspace.createModelViewEditor(loc.SchemaCompareLabel, { retainContextWhenHidden: true, supportsSave: true, resourceName: schemaCompareResourceName });
}
// schema compare can get started with three contexts for the source:
// 1. undefined
// 2. connection profile
// 3. dacpac
public async start(context: any) {
// if schema compare was launched from a db, set that as the source
let profile = context ? <azdata.IConnectionProfile>context.connectionProfile : undefined;
let sourceDacpac = context as string;
if (profile) {
let ownerUri = await azdata.connection.getUriForConnection((profile.id));
this.sourceEndpointInfo = {
@@ -91,6 +96,16 @@ export class SchemaCompareMainWindow {
packageFilePath: '',
connectionDetails: undefined
};
} else if (sourceDacpac) {
this.sourceEndpointInfo = {
endpointType: mssql.SchemaCompareEndpointType.Dacpac,
serverDisplayName: '',
serverName: '',
databaseName: '',
ownerUri: '',
packageFilePath: sourceDacpac,
connectionDetails: undefined
};
}
this.editor.registerContent(async view => {

View File

@@ -93,4 +93,46 @@ describe('SchemaCompareResult.start', function (): void {
should(result.getComparisonResult() !== undefined);
should(result.getComparisonResult().operationId === 'Test Operation Id');
});
it('Should start with the source as undefined', async function (): Promise<void> {
let sc = new SchemaCompareTestService();
let result = new SchemaCompareMainWindow(sc, mockExtensionContext.object);
await result.start(undefined);
let promise = new Promise(resolve => setTimeout(resolve, 5000)); // to ensure comparison result view is initialized
await promise;
should.equal(result.sourceEndpointInfo, undefined);
should.equal(result.targetEndpointInfo, undefined);
});
it('Should start with the source as database', async function (): Promise<void> {
let sc = new SchemaCompareTestService();
let result = new SchemaCompareMainWindow(sc, mockExtensionContext.object);
await result.start({connectionProfile: mockConnectionProfile});
let promise = new Promise(resolve => setTimeout(resolve, 5000)); // to ensure comparison result view is initialized
await promise;
should.notEqual(result.sourceEndpointInfo, undefined);
should.equal(result.sourceEndpointInfo.endpointType, mssql.SchemaCompareEndpointType.Database);
should.equal(result.sourceEndpointInfo.serverName, mockConnectionProfile.serverName);
should.equal(result.sourceEndpointInfo.databaseName, mockConnectionProfile.databaseName);
should.equal(result.targetEndpointInfo, undefined);
});
it('Should start with the source as dacpac.', async function (): Promise<void> {
let sc = new SchemaCompareTestService();
let result = new SchemaCompareMainWindow(sc, mockExtensionContext.object);
const dacpacPath = 'C:\\users\\test\\test.dacpac';
await result.start(dacpacPath);
let promise = new Promise(resolve => setTimeout(resolve, 5000)); // to ensure comparison result view is initialized
await promise;
should.notEqual(result.sourceEndpointInfo, undefined);
should.equal(result.sourceEndpointInfo.endpointType, mssql.SchemaCompareEndpointType.Dacpac);
should.equal(result.sourceEndpointInfo.packageFilePath, dacpacPath);
should.equal(result.targetEndpointInfo, undefined);
});
});