mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-17 02:51:36 -05:00
Set target platform for database project from the server metadata (#20558)
* Set target platform for database project from the server metadata * Addressed comments
This commit is contained in:
@@ -594,6 +594,15 @@ export const targetPlatformToVersion: Map<string, string> = new Map<string, stri
|
|||||||
[SqlTargetPlatform.sqlDW, 'Dw']
|
[SqlTargetPlatform.sqlDW, 'Dw']
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
export const onPremServerVersionToTargetPlatform: Map<number, SqlTargetPlatform> = new Map<number, SqlTargetPlatform>([
|
||||||
|
[11, SqlTargetPlatform.sqlServer2012],
|
||||||
|
[12, SqlTargetPlatform.sqlServer2014],
|
||||||
|
[13, SqlTargetPlatform.sqlServer2016],
|
||||||
|
[14, SqlTargetPlatform.sqlServer2017],
|
||||||
|
[15, SqlTargetPlatform.sqlServer2019],
|
||||||
|
[16, SqlTargetPlatform.sqlServer2022]
|
||||||
|
]);
|
||||||
|
|
||||||
// DW is special since the system dacpac folder has a different name from the target platform
|
// DW is special since the system dacpac folder has a different name from the target platform
|
||||||
export const AzureDwFolder = 'AzureDw';
|
export const AzureDwFolder = 'AzureDw';
|
||||||
|
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ import * as vscodeMssql from 'vscode-mssql';
|
|||||||
import * as fse from 'fs-extra';
|
import * as fse from 'fs-extra';
|
||||||
import * as which from 'which';
|
import * as which from 'which';
|
||||||
import { promises as fs } from 'fs';
|
import { promises as fs } from 'fs';
|
||||||
import { ISqlProject } from 'sqldbproj';
|
import { ISqlProject, SqlTargetPlatform } from 'sqldbproj';
|
||||||
|
|
||||||
export interface ValidationResult {
|
export interface ValidationResult {
|
||||||
errorMessage: string;
|
errorMessage: string;
|
||||||
@@ -711,3 +711,24 @@ export async function fileContainsCreateTableStatement(fullPath: string, project
|
|||||||
|
|
||||||
return containsCreateTableStatement;
|
return containsCreateTableStatement;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets target platform based on the server edition/version
|
||||||
|
* @param connectionId server connection profile id
|
||||||
|
* @returns target platform for the database project
|
||||||
|
*/
|
||||||
|
export async function getTargetPlatformFromServerVersion(connectionId: string): Promise<SqlTargetPlatform | undefined> {
|
||||||
|
const serverInfo = await getAzdataApi()!.connection.getServerInfo(connectionId);
|
||||||
|
const isCloud = serverInfo.isCloud;
|
||||||
|
|
||||||
|
let targetPlatform;
|
||||||
|
if (isCloud) {
|
||||||
|
const engineEdition = serverInfo.engineEditionId;
|
||||||
|
targetPlatform = engineEdition === getAzdataApi()!.DatabaseEngineEdition.SqlDataWarehouse ? SqlTargetPlatform.sqlDW : SqlTargetPlatform.sqlAzure;
|
||||||
|
} else {
|
||||||
|
const serverMajorVersion = serverInfo.serverMajorVersion;
|
||||||
|
targetPlatform = serverMajorVersion ? constants.onPremServerVersionToTargetPlatform.get(serverMajorVersion) : undefined;
|
||||||
|
}
|
||||||
|
|
||||||
|
return targetPlatform;
|
||||||
|
}
|
||||||
|
|||||||
@@ -1404,7 +1404,7 @@ export class ProjectsController {
|
|||||||
if (utils.getAzdataApi()) {
|
if (utils.getAzdataApi()) {
|
||||||
let createProjectFromDatabaseDialog = this.getCreateProjectFromDatabaseDialog(profile as azdataType.IConnectionProfile);
|
let createProjectFromDatabaseDialog = this.getCreateProjectFromDatabaseDialog(profile as azdataType.IConnectionProfile);
|
||||||
|
|
||||||
createProjectFromDatabaseDialog.createProjectFromDatabaseCallback = async (model) => await this.createProjectFromDatabaseCallback(model);
|
createProjectFromDatabaseDialog.createProjectFromDatabaseCallback = async (model, connectionId) => await this.createProjectFromDatabaseCallback(model, connectionId);
|
||||||
|
|
||||||
await createProjectFromDatabaseDialog.openDialog();
|
await createProjectFromDatabaseDialog.openDialog();
|
||||||
|
|
||||||
@@ -1431,16 +1431,21 @@ export class ProjectsController {
|
|||||||
return new CreateProjectFromDatabaseDialog(profile);
|
return new CreateProjectFromDatabaseDialog(profile);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async createProjectFromDatabaseCallback(model: ImportDataModel) {
|
public async createProjectFromDatabaseCallback(model: ImportDataModel, connectionId?: string) {
|
||||||
try {
|
try {
|
||||||
|
|
||||||
const newProjFolderUri = model.filePath;
|
const newProjFolderUri = model.filePath;
|
||||||
|
let targetPlatform: SqlTargetPlatform | undefined;
|
||||||
|
if (connectionId) {
|
||||||
|
targetPlatform = await utils.getTargetPlatformFromServerVersion(connectionId);
|
||||||
|
}
|
||||||
|
|
||||||
const newProjFilePath = await this.createNewProject({
|
const newProjFilePath = await this.createNewProject({
|
||||||
newProjName: model.projName,
|
newProjName: model.projName,
|
||||||
folderUri: vscode.Uri.file(newProjFolderUri),
|
folderUri: vscode.Uri.file(newProjFolderUri),
|
||||||
projectTypeId: model.sdkStyle ? constants.emptySqlDatabaseSdkProjectTypeId : constants.emptySqlDatabaseProjectTypeId,
|
projectTypeId: model.sdkStyle ? constants.emptySqlDatabaseSdkProjectTypeId : constants.emptySqlDatabaseProjectTypeId,
|
||||||
sdkStyle: model.sdkStyle
|
sdkStyle: model.sdkStyle,
|
||||||
|
targetPlatform: targetPlatform
|
||||||
});
|
});
|
||||||
|
|
||||||
model.filePath = path.dirname(newProjFilePath);
|
model.filePath = path.dirname(newProjFilePath);
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ export class CreateProjectFromDatabaseDialog {
|
|||||||
private toDispose: vscode.Disposable[] = [];
|
private toDispose: vscode.Disposable[] = [];
|
||||||
private initDialogComplete: Deferred = new Deferred();
|
private initDialogComplete: Deferred = new Deferred();
|
||||||
|
|
||||||
public createProjectFromDatabaseCallback: ((model: ImportDataModel) => any) | undefined;
|
public createProjectFromDatabaseCallback: ((model: ImportDataModel, connectionId?: string) => any) | undefined;
|
||||||
|
|
||||||
constructor(private profile: azdataType.IConnectionProfile | undefined) {
|
constructor(private profile: azdataType.IConnectionProfile | undefined) {
|
||||||
this.dialog = getAzdataApi()!.window.createModelViewDialog(constants.createProjectFromDatabaseDialogName, 'createProjectFromDatabaseDialog');
|
this.dialog = getAzdataApi()!.window.createModelViewDialog(constants.createProjectFromDatabaseDialogName, 'createProjectFromDatabaseDialog');
|
||||||
@@ -411,7 +411,7 @@ export class CreateProjectFromDatabaseDialog {
|
|||||||
};
|
};
|
||||||
|
|
||||||
azdataApi!.window.closeDialog(this.dialog);
|
azdataApi!.window.closeDialog(this.dialog);
|
||||||
await this.createProjectFromDatabaseCallback!(model);
|
await this.createProjectFromDatabaseCallback!(model, this.connectionId!);
|
||||||
|
|
||||||
this.dispose();
|
this.dispose();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user