mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-17 02:51:36 -05:00
Set target platform for db projects from server metadata: mssql vscode extension (#20607)
* Set target platform for mssql vscode extension- create project from db feature * Addressed comments * Address comment to add EngineEdition information in vscode-mssql.d.ts
This commit is contained in:
@@ -58,6 +58,9 @@ export class MockVscodeMssqlIExtension implements vscodeMssql.IExtension {
|
|||||||
createConnectionDetails(_: vscodeMssql.IConnectionInfo): vscodeMssql.ConnectionDetails {
|
createConnectionDetails(_: vscodeMssql.IConnectionInfo): vscodeMssql.ConnectionDetails {
|
||||||
throw new Error('Method not implemented.');
|
throw new Error('Method not implemented.');
|
||||||
}
|
}
|
||||||
|
getServerInfo(_: vscodeMssql.IConnectionInfo): vscodeMssql.ServerInfo {
|
||||||
|
throw new Error('Method not implemented.');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function createTestUtils(): TestUtils {
|
export function createTestUtils(): TestUtils {
|
||||||
|
|||||||
@@ -714,17 +714,16 @@ export async function fileContainsCreateTableStatement(fullPath: string, project
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets target platform based on the server edition/version
|
* Gets target platform based on the server edition/version
|
||||||
* @param connectionId server connection profile id
|
* @param serverInfo server information
|
||||||
* @returns target platform for the database project
|
* @returns target platform for the database project
|
||||||
*/
|
*/
|
||||||
export async function getTargetPlatformFromServerVersion(connectionId: string): Promise<SqlTargetPlatform | undefined> {
|
export async function getTargetPlatformFromServerVersion(serverInfo: azdataType.ServerInfo | vscodeMssql.ServerInfo): Promise<SqlTargetPlatform | undefined> {
|
||||||
const serverInfo = await getAzdataApi()!.connection.getServerInfo(connectionId);
|
|
||||||
const isCloud = serverInfo.isCloud;
|
const isCloud = serverInfo.isCloud;
|
||||||
|
|
||||||
let targetPlatform;
|
let targetPlatform;
|
||||||
if (isCloud) {
|
if (isCloud) {
|
||||||
const engineEdition = serverInfo.engineEditionId;
|
const engineEdition = serverInfo.engineEditionId;
|
||||||
targetPlatform = engineEdition === getAzdataApi()!.DatabaseEngineEdition.SqlDataWarehouse ? SqlTargetPlatform.sqlDW : SqlTargetPlatform.sqlAzure;
|
targetPlatform = engineEdition === vscodeMssql.DatabaseEngineEdition.SqlDataWarehouse ? SqlTargetPlatform.sqlDW : SqlTargetPlatform.sqlAzure;
|
||||||
} else {
|
} else {
|
||||||
const serverMajorVersion = serverInfo.serverMajorVersion;
|
const serverMajorVersion = serverInfo.serverMajorVersion;
|
||||||
targetPlatform = serverMajorVersion ? constants.onPremServerVersionToTargetPlatform.get(serverMajorVersion) : undefined;
|
targetPlatform = serverMajorVersion ? constants.onPremServerVersionToTargetPlatform.get(serverMajorVersion) : undefined;
|
||||||
|
|||||||
@@ -1420,7 +1420,7 @@ export class ProjectsController {
|
|||||||
}
|
}
|
||||||
const model = await createNewProjectFromDatabaseWithQuickpick(profile as mssqlVscode.IConnectionInfo);
|
const model = await createNewProjectFromDatabaseWithQuickpick(profile as mssqlVscode.IConnectionInfo);
|
||||||
if (model) {
|
if (model) {
|
||||||
await this.createProjectFromDatabaseCallback(model);
|
await this.createProjectFromDatabaseCallback(model, profile as mssqlVscode.IConnectionInfo);
|
||||||
}
|
}
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
@@ -1431,13 +1431,22 @@ export class ProjectsController {
|
|||||||
return new CreateProjectFromDatabaseDialog(profile);
|
return new CreateProjectFromDatabaseDialog(profile);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async createProjectFromDatabaseCallback(model: ImportDataModel, connectionId?: string) {
|
public async createProjectFromDatabaseCallback(model: ImportDataModel, connectionInfo?: string | mssqlVscode.IConnectionInfo) {
|
||||||
try {
|
try {
|
||||||
|
|
||||||
const newProjFolderUri = model.filePath;
|
const newProjFolderUri = model.filePath;
|
||||||
let targetPlatform: SqlTargetPlatform | undefined;
|
let targetPlatform: SqlTargetPlatform | undefined;
|
||||||
if (connectionId) {
|
let serverInfo;
|
||||||
targetPlatform = await utils.getTargetPlatformFromServerVersion(connectionId);
|
if (connectionInfo) {
|
||||||
|
if (typeof connectionInfo === 'string') {
|
||||||
|
serverInfo = await utils.getAzdataApi()!.connection.getServerInfo(connectionInfo);
|
||||||
|
} else {
|
||||||
|
serverInfo = (await utils.getVscodeMssqlApi()).getServerInfo(connectionInfo);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (serverInfo) {
|
||||||
|
targetPlatform = await utils.getTargetPlatformFromServerVersion(serverInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
const newProjFilePath = await this.createNewProject({
|
const newProjFilePath = await this.createNewProject({
|
||||||
|
|||||||
@@ -509,7 +509,7 @@ describe('ProjectsController', function (): void {
|
|||||||
version: '1.0.0.0',
|
version: '1.0.0.0',
|
||||||
extractTarget: mssql.ExtractTarget['schemaObjectType'],
|
extractTarget: mssql.ExtractTarget['schemaObjectType'],
|
||||||
sdkStyle: false
|
sdkStyle: false
|
||||||
});
|
}, undefined);
|
||||||
|
|
||||||
return Promise.resolve(undefined);
|
return Promise.resolve(undefined);
|
||||||
});
|
});
|
||||||
@@ -517,7 +517,7 @@ describe('ProjectsController', function (): void {
|
|||||||
const projController = TypeMoq.Mock.ofType(ProjectsController);
|
const projController = TypeMoq.Mock.ofType(ProjectsController);
|
||||||
projController.callBase = true;
|
projController.callBase = true;
|
||||||
projController.setup(x => x.getCreateProjectFromDatabaseDialog(TypeMoq.It.isAny())).returns(() => createProjectFromDatabaseDialog.object);
|
projController.setup(x => x.getCreateProjectFromDatabaseDialog(TypeMoq.It.isAny())).returns(() => createProjectFromDatabaseDialog.object);
|
||||||
projController.setup(x => x.createProjectFromDatabaseCallback(TypeMoq.It.isAny())).returns(() => {
|
projController.setup(x => x.createProjectFromDatabaseCallback(TypeMoq.It.isAny(), TypeMoq.It.isAny())).returns(() => {
|
||||||
holler = createProjectFromDbHoller;
|
holler = createProjectFromDbHoller;
|
||||||
return Promise.resolve(undefined);
|
return Promise.resolve(undefined);
|
||||||
});
|
});
|
||||||
|
|||||||
79
extensions/types/vscode-mssql.d.ts
vendored
79
extensions/types/vscode-mssql.d.ts
vendored
@@ -114,8 +114,32 @@ declare module 'vscode-mssql' {
|
|||||||
* @returns A promise object for when the request receives a response
|
* @returns A promise object for when the request receives a response
|
||||||
*/
|
*/
|
||||||
sendRequest<P, R, E, R0>(requestType: RequestType<P, R, E, R0>, params?: P): Promise<R>;
|
sendRequest<P, R, E, R0>(requestType: RequestType<P, R, E, R0>, params?: P): Promise<R>;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the server info for a connection
|
||||||
|
* @param connectionInfo connection info of the connection
|
||||||
|
*/
|
||||||
|
getServerInfo(connectionInfo: IConnectionInfo): ServerInfo
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The possible values of the server engine edition
|
||||||
|
* EngineEdition under https://docs.microsoft.com/sql/t-sql/functions/serverproperty-transact-sql is associated with these values
|
||||||
|
*/
|
||||||
|
export const enum DatabaseEngineEdition {
|
||||||
|
Unknown = 0,
|
||||||
|
Personal = 1,
|
||||||
|
Standard = 2,
|
||||||
|
Enterprise = 3,
|
||||||
|
Express = 4,
|
||||||
|
SqlDatabase = 5,
|
||||||
|
SqlDataWarehouse = 6,
|
||||||
|
SqlStretchDatabase = 7,
|
||||||
|
SqlManagedInstance = 8,
|
||||||
|
SqlOnDemand = 11
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Information about a database connection
|
* Information about a database connection
|
||||||
*/
|
*/
|
||||||
@@ -289,6 +313,61 @@ declare module 'vscode-mssql' {
|
|||||||
connectionString: string | undefined;
|
connectionString: string | undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Information about a SQL Server instance.
|
||||||
|
*/
|
||||||
|
export interface ServerInfo {
|
||||||
|
/**
|
||||||
|
* The major version of the SQL Server instance.
|
||||||
|
*/
|
||||||
|
serverMajorVersion: number;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The minor version of the SQL Server instance.
|
||||||
|
*/
|
||||||
|
serverMinorVersion: number;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The build of the SQL Server instance.
|
||||||
|
*/
|
||||||
|
serverReleaseVersion: number;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The ID of the engine edition of the SQL Server instance.
|
||||||
|
*/
|
||||||
|
engineEditionId: number;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* String containing the full server version text.
|
||||||
|
*/
|
||||||
|
serverVersion: string;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* String describing the product level of the server.
|
||||||
|
*/
|
||||||
|
serverLevel: string;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The edition of the SQL Server instance.
|
||||||
|
*/
|
||||||
|
serverEdition: string;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Whether the SQL Server instance is running in the cloud (Azure) or not.
|
||||||
|
*/
|
||||||
|
isCloud: boolean;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The version of Azure that the SQL Server instance is running on, if applicable.
|
||||||
|
*/
|
||||||
|
azureVersion: number;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The Operating System version string of the machine running the SQL Server instance.
|
||||||
|
*/
|
||||||
|
osVersion: string;
|
||||||
|
}
|
||||||
|
|
||||||
export const enum ExtractTarget {
|
export const enum ExtractTarget {
|
||||||
dacpac = 0,
|
dacpac = 0,
|
||||||
file = 1,
|
file = 1,
|
||||||
|
|||||||
Reference in New Issue
Block a user