mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-17 02:51:36 -05:00
Apply changes from Remote Database to sqlproj - mssql changes (#17655)
* update project from database * update project from database * update project from database * Re-adding schemaComparePublishChanges for temporary backcompat * Adding comment for keeping enum values in sync * Correcting enum value Co-authored-by: Noureldine Yehia <t-nyehia@microsoft.com>
This commit is contained in:
@@ -54,6 +54,10 @@ suite('Schema compare integration test suite @DacFx@', () => {
|
||||
serverName: '',
|
||||
databaseName: '',
|
||||
ownerUri: '',
|
||||
projectFilePath: '',
|
||||
folderStructure: '',
|
||||
targetScripts: [],
|
||||
dataSchemaProvider: '',
|
||||
connectionDetails: undefined
|
||||
};
|
||||
let target: mssql.SchemaCompareEndpointInfo = {
|
||||
@@ -63,6 +67,10 @@ suite('Schema compare integration test suite @DacFx@', () => {
|
||||
serverName: '',
|
||||
databaseName: '',
|
||||
ownerUri: '',
|
||||
projectFilePath: '',
|
||||
folderStructure: '',
|
||||
targetScripts: [],
|
||||
dataSchemaProvider: '',
|
||||
connectionDetails: undefined
|
||||
};
|
||||
|
||||
@@ -114,6 +122,10 @@ suite('Schema compare integration test suite @DacFx@', () => {
|
||||
serverName: server.serverName,
|
||||
databaseName: sourceDB,
|
||||
ownerUri: ownerUri,
|
||||
projectFilePath: '',
|
||||
folderStructure: '',
|
||||
targetScripts: [],
|
||||
dataSchemaProvider: '',
|
||||
connectionDetails: undefined
|
||||
};
|
||||
let target: mssql.SchemaCompareEndpointInfo = {
|
||||
@@ -123,6 +135,10 @@ suite('Schema compare integration test suite @DacFx@', () => {
|
||||
serverName: server.serverName,
|
||||
databaseName: targetDB,
|
||||
ownerUri: ownerUri,
|
||||
projectFilePath: '',
|
||||
folderStructure: '',
|
||||
targetScripts: [],
|
||||
dataSchemaProvider: '',
|
||||
connectionDetails: undefined
|
||||
};
|
||||
|
||||
@@ -179,6 +195,10 @@ suite('Schema compare integration test suite @DacFx@', () => {
|
||||
serverName: '',
|
||||
databaseName: '',
|
||||
ownerUri: ownerUri,
|
||||
projectFilePath: '',
|
||||
folderStructure: '',
|
||||
targetScripts: [],
|
||||
dataSchemaProvider: '',
|
||||
connectionDetails: undefined
|
||||
};
|
||||
let target: mssql.SchemaCompareEndpointInfo = {
|
||||
@@ -188,6 +208,10 @@ suite('Schema compare integration test suite @DacFx@', () => {
|
||||
serverName: server.serverName,
|
||||
databaseName: targetDB,
|
||||
ownerUri: ownerUri,
|
||||
projectFilePath: '',
|
||||
folderStructure: '',
|
||||
targetScripts: [],
|
||||
dataSchemaProvider: '',
|
||||
connectionDetails: undefined
|
||||
};
|
||||
|
||||
@@ -231,6 +255,10 @@ suite('Schema compare integration test suite @DacFx@', () => {
|
||||
serverName: '',
|
||||
databaseName: '',
|
||||
ownerUri: '',
|
||||
projectFilePath: '',
|
||||
folderStructure: '',
|
||||
targetScripts: [],
|
||||
dataSchemaProvider: '',
|
||||
connectionDetails: undefined
|
||||
};
|
||||
let target: mssql.SchemaCompareEndpointInfo = {
|
||||
@@ -240,6 +268,10 @@ suite('Schema compare integration test suite @DacFx@', () => {
|
||||
serverName: '',
|
||||
databaseName: '',
|
||||
ownerUri: '',
|
||||
projectFilePath: '',
|
||||
folderStructure: '',
|
||||
targetScripts: [],
|
||||
dataSchemaProvider: '',
|
||||
connectionDetails: undefined
|
||||
};
|
||||
|
||||
@@ -297,6 +329,10 @@ suite('Schema compare integration test suite @DacFx@', () => {
|
||||
serverName: '',
|
||||
databaseName: '',
|
||||
ownerUri: ownerUri,
|
||||
projectFilePath: '',
|
||||
folderStructure: '',
|
||||
targetScripts: [],
|
||||
dataSchemaProvider: '',
|
||||
connectionDetails: undefined
|
||||
};
|
||||
const target: mssql.SchemaCompareEndpointInfo = {
|
||||
@@ -306,6 +342,10 @@ suite('Schema compare integration test suite @DacFx@', () => {
|
||||
serverName: server.serverName,
|
||||
databaseName: targetDB,
|
||||
ownerUri: ownerUri,
|
||||
projectFilePath: '',
|
||||
folderStructure: '',
|
||||
targetScripts: [],
|
||||
dataSchemaProvider: '',
|
||||
connectionDetails: undefined
|
||||
};
|
||||
|
||||
@@ -323,7 +363,7 @@ suite('Schema compare integration test suite @DacFx@', () => {
|
||||
assertIncludeExcludeResult(includeResult, true, 0, 0);
|
||||
|
||||
//publish the updated changes. Function1 should not be added to the target database
|
||||
const publishChangesResult = await schemaCompareService.schemaComparePublishChanges(schemaCompareResult.operationId, server.serverName, targetDB, azdata.TaskExecutionMode.execute);
|
||||
const publishChangesResult = await schemaCompareService.schemaComparePublishDatabaseChanges(schemaCompareResult.operationId, server.serverName, targetDB, azdata.TaskExecutionMode.execute);
|
||||
assert(publishChangesResult.success === true, `Publish changes should complete successfully. But it failed with error : ${publishChangesResult.errorMessage}`);
|
||||
|
||||
//verify table Table3 is added
|
||||
@@ -372,6 +412,10 @@ suite('Schema compare integration test suite @DacFx@', () => {
|
||||
serverName: '',
|
||||
databaseName: '',
|
||||
ownerUri: ownerUri,
|
||||
projectFilePath: '',
|
||||
folderStructure: '',
|
||||
targetScripts: [],
|
||||
dataSchemaProvider: '',
|
||||
connectionDetails: undefined
|
||||
};
|
||||
const target: mssql.SchemaCompareEndpointInfo = {
|
||||
@@ -381,6 +425,10 @@ suite('Schema compare integration test suite @DacFx@', () => {
|
||||
serverName: server.serverName,
|
||||
databaseName: targetDB,
|
||||
ownerUri: ownerUri,
|
||||
projectFilePath: '',
|
||||
folderStructure: '',
|
||||
targetScripts: [],
|
||||
dataSchemaProvider: '',
|
||||
connectionDetails: undefined
|
||||
};
|
||||
|
||||
@@ -390,7 +438,7 @@ suite('Schema compare integration test suite @DacFx@', () => {
|
||||
assertSchemaCompareResult(schemaCompareResult, operationId, 4);
|
||||
|
||||
//publish all the changes
|
||||
const publishChangesResult = await schemaCompareService.schemaComparePublishChanges(schemaCompareResult.operationId, server.serverName, targetDB, azdata.TaskExecutionMode.execute);
|
||||
const publishChangesResult = await schemaCompareService.schemaComparePublishDatabaseChanges(schemaCompareResult.operationId, server.serverName, targetDB, azdata.TaskExecutionMode.execute);
|
||||
assert(publishChangesResult.success === true, `Publish changes should complete successfully. But it failed with error : ${publishChangesResult.errorMessage}`);
|
||||
|
||||
//verify table Table3 is added
|
||||
@@ -435,6 +483,10 @@ suite('Schema compare integration test suite @DacFx@', () => {
|
||||
serverName: '',
|
||||
databaseName: '',
|
||||
ownerUri: ownerUri,
|
||||
projectFilePath: '',
|
||||
folderStructure: '',
|
||||
targetScripts: [],
|
||||
dataSchemaProvider: '',
|
||||
connectionDetails: undefined
|
||||
};
|
||||
const target: mssql.SchemaCompareEndpointInfo = {
|
||||
@@ -444,6 +496,10 @@ suite('Schema compare integration test suite @DacFx@', () => {
|
||||
serverName: server.serverName,
|
||||
databaseName: targetDB,
|
||||
ownerUri: ownerUri,
|
||||
projectFilePath: '',
|
||||
folderStructure: '',
|
||||
targetScripts: [],
|
||||
dataSchemaProvider: '',
|
||||
connectionDetails: undefined
|
||||
};
|
||||
|
||||
|
||||
@@ -628,13 +628,20 @@ export interface SchemaCompareGenerateScriptParams {
|
||||
taskExecutionMode: TaskExecutionMode;
|
||||
}
|
||||
|
||||
export interface SchemaComparePublishChangesParams {
|
||||
export interface SchemaComparePublishDatabaseChangesParams {
|
||||
operationId: string;
|
||||
targetServerName: string;
|
||||
targetDatabaseName: string;
|
||||
taskExecutionMode: TaskExecutionMode;
|
||||
}
|
||||
|
||||
export interface SchemaComparePublishProjectChangesParams {
|
||||
operationId: string;
|
||||
targetProjectPath: string;
|
||||
targetFolderStructure: mssql.ExtractTarget;
|
||||
taskExecutionMode: TaskExecutionMode;
|
||||
}
|
||||
|
||||
export interface SchemaCompareGetOptionsParams {
|
||||
|
||||
}
|
||||
@@ -673,7 +680,15 @@ export namespace SchemaCompareGenerateScriptRequest {
|
||||
}
|
||||
|
||||
export namespace SchemaComparePublishChangesRequest {
|
||||
export const type = new RequestType<SchemaComparePublishChangesParams, azdata.ResultStatus, void, void>('schemaCompare/publish');
|
||||
export const type = new RequestType<SchemaComparePublishDatabaseChangesParams, azdata.ResultStatus, void, void>('schemaCompare/publish');
|
||||
}
|
||||
|
||||
export namespace SchemaComparePublishDatabaseChangesRequest {
|
||||
export const type = new RequestType<SchemaComparePublishDatabaseChangesParams, azdata.ResultStatus, void, void>('schemaCompare/publishDatabase');
|
||||
}
|
||||
|
||||
export namespace SchemaComparePublishProjectChangesRequest {
|
||||
export const type = new RequestType<SchemaComparePublishProjectChangesParams, mssql.SchemaComparePublishProjectResult, void, void>('schemaCompare/publishProject');
|
||||
}
|
||||
|
||||
export namespace SchemaCompareGetDefaultOptionsRequest {
|
||||
|
||||
18
extensions/mssql/src/mssql.d.ts
vendored
18
extensions/mssql/src/mssql.d.ts
vendored
@@ -122,7 +122,10 @@ export const enum SchemaDifferenceType {
|
||||
|
||||
export const enum SchemaCompareEndpointType {
|
||||
Database = 0,
|
||||
Dacpac = 1
|
||||
Dacpac = 1,
|
||||
Project = 2,
|
||||
// must be kept in-sync with SchemaCompareEndpointType in SQL Tools Service
|
||||
// located at \src\Microsoft.SqlTools.ServiceLayer\SchemaCompare\Contracts\SchemaCompareRequest.cs
|
||||
}
|
||||
|
||||
export interface SchemaCompareEndpointInfo {
|
||||
@@ -134,6 +137,10 @@ export interface SchemaCompareEndpointInfo {
|
||||
ownerUri: string;
|
||||
connectionDetails: azdata.ConnectionInfo;
|
||||
connectionName?: string;
|
||||
projectFilePath: string;
|
||||
targetScripts: string[];
|
||||
folderStructure: string;
|
||||
dataSchemaProvider: string;
|
||||
}
|
||||
|
||||
export interface SchemaCompareObjectId {
|
||||
@@ -307,10 +314,11 @@ export interface SchemaCompareObjectId {
|
||||
}
|
||||
|
||||
export interface ISchemaCompareService {
|
||||
|
||||
schemaCompare(operationId: string, sourceEndpointInfo: SchemaCompareEndpointInfo, targetEndpointInfo: SchemaCompareEndpointInfo, taskExecutionMode: azdata.TaskExecutionMode, deploymentOptions: DeploymentOptions): Thenable<SchemaCompareResult>;
|
||||
schemaCompareGenerateScript(operationId: string, targetServerName: string, targetDatabaseName: string, taskExecutionMode: azdata.TaskExecutionMode): Thenable<azdata.ResultStatus>;
|
||||
schemaComparePublishChanges(operationId: string, targetServerName: string, targetDatabaseName: string, taskExecutionMode: azdata.TaskExecutionMode): Thenable<azdata.ResultStatus>;
|
||||
schemaComparePublishDatabaseChanges(operationId: string, targetServerName: string, targetDatabaseName: string, taskExecutionMode: azdata.TaskExecutionMode): Thenable<azdata.ResultStatus>;
|
||||
schemaComparePublishProjectChanges(operationId: string, targetProjectPath: string, targetFolderStructure: ExtractTarget, taskExecutionMode: azdata.TaskExecutionMode): Thenable<SchemaComparePublishProjectResult>;
|
||||
schemaCompareGetDefaultOptions(): Thenable<SchemaCompareOptionsResult>;
|
||||
schemaCompareIncludeExcludeNode(operationId: string, diffEntry: DiffEntry, IncludeRequest: boolean, taskExecutionMode: azdata.TaskExecutionMode): Thenable<SchemaCompareIncludeExcludeResult>;
|
||||
schemaCompareOpenScmp(filePath: string): Thenable<SchemaCompareOpenScmpResult>;
|
||||
@@ -328,6 +336,12 @@ export interface SchemaCompareOpenScmpResult extends azdata.ResultStatus {
|
||||
excludedTargetElements: SchemaCompareObjectId[];
|
||||
}
|
||||
|
||||
export interface SchemaComparePublishProjectResult extends azdata.ResultStatus {
|
||||
changedFiles: string[];
|
||||
addedFiles: string[];
|
||||
deletedFiles: string[];
|
||||
}
|
||||
|
||||
//#endregion
|
||||
|
||||
//#region --- dacfx
|
||||
|
||||
@@ -55,11 +55,31 @@ export class SchemaCompareService implements mssql.ISchemaCompareService {
|
||||
}
|
||||
|
||||
public schemaComparePublishChanges(operationId: string, targetServerName: string, targetDatabaseName: string, taskExecutionMode: azdata.TaskExecutionMode): Thenable<azdata.ResultStatus> {
|
||||
const params: contracts.SchemaComparePublishChangesParams = { operationId: operationId, targetServerName: targetServerName, targetDatabaseName: targetDatabaseName, taskExecutionMode: taskExecutionMode };
|
||||
return this.client.sendRequest(contracts.SchemaComparePublishChangesRequest.type, params).then(
|
||||
const params: contracts.SchemaComparePublishDatabaseChangesParams = { operationId: operationId, targetServerName: targetServerName, targetDatabaseName: targetDatabaseName, taskExecutionMode: taskExecutionMode };
|
||||
return this.client.sendRequest(contracts.SchemaComparePublishChangesRequest.type, params).then(undefined,
|
||||
e => {
|
||||
this.client.logFailedRequest(contracts.SchemaComparePublishChangesRequest.type, e); return Promise.resolve(undefined);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
public schemaComparePublishDatabaseChanges(operationId: string, targetServerName: string, targetDatabaseName: string, taskExecutionMode: azdata.TaskExecutionMode): Thenable<azdata.ResultStatus> {
|
||||
const params: contracts.SchemaComparePublishDatabaseChangesParams = { operationId: operationId, targetServerName: targetServerName, targetDatabaseName: targetDatabaseName, taskExecutionMode: taskExecutionMode };
|
||||
return this.client.sendRequest(contracts.SchemaComparePublishDatabaseChangesRequest.type, params).then(
|
||||
undefined,
|
||||
e => {
|
||||
this.client.logFailedRequest(contracts.SchemaComparePublishChangesRequest.type, e);
|
||||
this.client.logFailedRequest(contracts.SchemaComparePublishDatabaseChangesRequest.type, e);
|
||||
return Promise.resolve(undefined);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
public schemaComparePublishProjectChanges(operationId: string, targetProjectPath: string, targetFolderStructure: mssql.ExtractTarget, taskExecutionMode: azdata.TaskExecutionMode): Thenable<mssql.SchemaComparePublishProjectResult> {
|
||||
const params: contracts.SchemaComparePublishProjectChangesParams = { operationId: operationId, targetProjectPath: targetProjectPath, targetFolderStructure: targetFolderStructure, taskExecutionMode: taskExecutionMode };
|
||||
return this.client.sendRequest(contracts.SchemaComparePublishProjectChangesRequest.type, params).then(
|
||||
undefined,
|
||||
(e: any) => {
|
||||
this.client.logFailedRequest(contracts.SchemaComparePublishProjectChangesRequest.type, e);
|
||||
return Promise.resolve(undefined);
|
||||
}
|
||||
);
|
||||
|
||||
@@ -97,7 +97,11 @@ export class SchemaCompareDialog {
|
||||
databaseName: '',
|
||||
ownerUri: '',
|
||||
packageFilePath: this.sourceTextBox.value,
|
||||
connectionDetails: undefined
|
||||
connectionDetails: undefined,
|
||||
projectFilePath: '',
|
||||
folderStructure: '',
|
||||
targetScripts: [],
|
||||
dataSchemaProvider: ''
|
||||
};
|
||||
} else {
|
||||
const sourceServerDropdownValue = this.sourceServerDropdown.value as ConnectionDropdownValue;
|
||||
@@ -111,7 +115,11 @@ export class SchemaCompareDialog {
|
||||
ownerUri: ownerUri,
|
||||
packageFilePath: '',
|
||||
connectionDetails: undefined,
|
||||
connectionName: sourceServerDropdownValue.connection.options.connectionName
|
||||
connectionName: sourceServerDropdownValue.connection.options.connectionName,
|
||||
projectFilePath: '',
|
||||
folderStructure: '',
|
||||
targetScripts: [],
|
||||
dataSchemaProvider: ''
|
||||
};
|
||||
}
|
||||
|
||||
@@ -123,7 +131,11 @@ export class SchemaCompareDialog {
|
||||
databaseName: '',
|
||||
ownerUri: '',
|
||||
packageFilePath: this.targetTextBox.value,
|
||||
connectionDetails: undefined
|
||||
connectionDetails: undefined,
|
||||
projectFilePath: '',
|
||||
folderStructure: '',
|
||||
targetScripts: [],
|
||||
dataSchemaProvider: ''
|
||||
};
|
||||
} else {
|
||||
const targetServerDropdownValue = this.targetServerDropdown.value as ConnectionDropdownValue;
|
||||
@@ -137,7 +149,11 @@ export class SchemaCompareDialog {
|
||||
ownerUri: ownerUri,
|
||||
packageFilePath: '',
|
||||
connectionDetails: undefined,
|
||||
connectionName: targetServerDropdownValue.connection.options.connectionName
|
||||
connectionName: targetServerDropdownValue.connection.options.connectionName,
|
||||
projectFilePath: '',
|
||||
folderStructure: '',
|
||||
targetScripts: [],
|
||||
dataSchemaProvider: ''
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -104,7 +104,11 @@ export class SchemaCompareMainWindow {
|
||||
ownerUri: ownerUri,
|
||||
packageFilePath: '',
|
||||
connectionDetails: undefined,
|
||||
connectionName: profile.connectionName
|
||||
connectionName: profile.connectionName,
|
||||
projectFilePath: '',
|
||||
folderStructure: '',
|
||||
targetScripts: [],
|
||||
dataSchemaProvider: ''
|
||||
};
|
||||
} else if (sourceDacpac) {
|
||||
this.sourceEndpointInfo = {
|
||||
@@ -114,7 +118,11 @@ export class SchemaCompareMainWindow {
|
||||
databaseName: '',
|
||||
ownerUri: '',
|
||||
packageFilePath: sourceDacpac,
|
||||
connectionDetails: undefined
|
||||
connectionDetails: undefined,
|
||||
projectFilePath: '',
|
||||
folderStructure: '',
|
||||
targetScripts: [],
|
||||
dataSchemaProvider: ''
|
||||
};
|
||||
}
|
||||
|
||||
@@ -776,7 +784,7 @@ export class SchemaCompareMainWindow {
|
||||
// disable apply and generate script buttons because the results are no longer valid after applying the changes
|
||||
this.setButtonsForRecompare();
|
||||
|
||||
const service = await this.getService();
|
||||
const service: mssql.ISchemaCompareService = await this.getService();
|
||||
const result = await service.schemaComparePublishChanges(this.comparisonResult.operationId, this.targetEndpointInfo.serverName, this.targetEndpointInfo.databaseName, azdata.TaskExecutionMode.execute);
|
||||
if (!result || !result.success) {
|
||||
TelemetryReporter.createErrorEvent(TelemetryViews.SchemaCompareMainWindow, 'SchemaCompareApplyFailed', undefined, getTelemetryErrorType(result.errorMessage))
|
||||
|
||||
@@ -24,6 +24,14 @@ export class SchemaCompareTestService implements mssql.ISchemaCompareService {
|
||||
throw new Error('Method not implemented.');
|
||||
}
|
||||
|
||||
schemaComparePublishDatabaseChanges(operationId: string, targetServerName: string, targetDatabaseName: string, taskExecutionMode: azdata.TaskExecutionMode): Thenable<azdata.ResultStatus> {
|
||||
throw new Error('Method not implemented.');
|
||||
}
|
||||
|
||||
schemaComparePublishProjectChanges(operationId: string, targetProjectPath: string, targetFolderStructure: mssql.ExtractTarget, taskExecutionMode: azdata.TaskExecutionMode): Thenable<mssql.SchemaComparePublishProjectResult> {
|
||||
throw new Error('Method not implemented.');
|
||||
}
|
||||
|
||||
schemaCompareGetDefaultOptions(): Thenable<mssql.SchemaCompareOptionsResult> {
|
||||
let result: mssql.SchemaCompareOptionsResult = {
|
||||
defaultDeploymentOptions: undefined,
|
||||
@@ -42,7 +50,6 @@ export class SchemaCompareTestService implements mssql.ISchemaCompareService {
|
||||
throw new Error('Method not implemented.');
|
||||
}
|
||||
|
||||
|
||||
schemaCompareSaveScmp(sourceEndpointInfo: mssql.SchemaCompareEndpointInfo, targetEndpointInfo: mssql.SchemaCompareEndpointInfo, taskExecutionMode: azdata.TaskExecutionMode, deploymentOptions: mssql.DeploymentOptions, scmpFilePath: string, excludedSourceObjects: mssql.SchemaCompareObjectId[], excludedTargetObjects: mssql.SchemaCompareObjectId[]): Thenable<azdata.ResultStatus> {
|
||||
throw new Error('Method not implemented.');
|
||||
}
|
||||
|
||||
@@ -94,7 +94,11 @@ export const mockDacpacEndpoint: mssql.SchemaCompareEndpointInfo = {
|
||||
databaseName: '',
|
||||
ownerUri: '',
|
||||
packageFilePath: mockFilePath,
|
||||
connectionDetails: undefined
|
||||
connectionDetails: undefined,
|
||||
projectFilePath: '',
|
||||
folderStructure: '',
|
||||
targetScripts: [],
|
||||
dataSchemaProvider: ''
|
||||
};
|
||||
|
||||
export const mockDatabaseEndpoint: mssql.SchemaCompareEndpointInfo = {
|
||||
@@ -104,7 +108,11 @@ export const mockDatabaseEndpoint: mssql.SchemaCompareEndpointInfo = {
|
||||
databaseName: '',
|
||||
ownerUri: '',
|
||||
packageFilePath: '',
|
||||
connectionDetails: undefined
|
||||
connectionDetails: undefined,
|
||||
projectFilePath: '',
|
||||
folderStructure: '',
|
||||
targetScripts: [],
|
||||
dataSchemaProvider: ''
|
||||
};
|
||||
|
||||
export async function shouldThrowSpecificError(block: Function, expectedMessage: string, details?: string) {
|
||||
|
||||
Reference in New Issue
Block a user