Skip to content

Commit

Permalink
Add vscode support for System database package references for SDK-sty…
Browse files Browse the repository at this point in the history
…le sql projects (#23383)

* changes for supporting system db package references in vscode

* cleanup

* address comments
  • Loading branch information
kisantia authored Jun 14, 2023
1 parent b135a06 commit 42a0622
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -116,16 +116,27 @@ async function addSystemDatabaseReference(project: Project): Promise<ISystemData

const selectedSystemDb = await vscode.window.showQuickPick(
getSystemDbOptions(project),
{ title: constants.systemDatabase, ignoreFocusOut: true, });
{ title: constants.systemDatabase, ignoreFocusOut: true });
if (!selectedSystemDb) {
// User cancelled
return undefined;
}

// 3. Prompt DB name
// 3 Prompt for Reference Type if it's an SDK-style project
const referenceType = await promptReferenceType(project);
if (referenceType === undefined) { // need to check for specifically undefined here because the enum SystemDbReferenceType.ArtifactReference evaluates to 0
// User cancelled
return undefined;
}

// 4. Prompt DB name
const dbName = await promptDbName(selectedSystemDb);
if (!dbName) {
// User cancelled
return undefined;
}

// 4. Prompt suppress unresolved ref errors
// 5. Prompt suppress unresolved ref errors
const suppressErrors = await promptSuppressUnresolvedRefErrors();

TelemetryReporter.createActionEvent(TelemetryViews.ProjectTree, TelemetryActions.addDatabaseReference)
Expand All @@ -136,7 +147,7 @@ async function addSystemDatabaseReference(project: Project): Promise<ISystemData
databaseVariableLiteralValue: dbName,
systemDb: getSystemDatabase(selectedSystemDb),
suppressMissingDependenciesErrors: suppressErrors,
systemDbReferenceType: SystemDbReferenceType.ArtifactReference
systemDbReferenceType: referenceType
};
}

Expand Down Expand Up @@ -376,3 +387,21 @@ async function promptDbServerValues(location: string, defaultDbName: string): Pr
}
return ret;
}

async function promptReferenceType(project: Project): Promise<SystemDbReferenceType | undefined> {
let referenceType = SystemDbReferenceType.ArtifactReference;
if (project.sqlProjStyle === ProjectType.SdkStyle) {
const referenceTypeString = await vscode.window.showQuickPick(
[constants.packageReference, constants.artifactReference],
{ title: constants.referenceTypeRadioButtonsGroupTitle, ignoreFocusOut: true }
);

if (referenceTypeString === undefined) { // need to check for specifically undefined here because the enum SystemDbReferenceType.ArtifactReference evaluates to 0
return undefined;
}

referenceType = referenceTypeString === constants.packageReference ? SystemDbReferenceType.PackageReference : SystemDbReferenceType.ArtifactReference;
}

return referenceType;
}
3 changes: 2 additions & 1 deletion extensions/sql-database-projects/src/models/project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -838,8 +838,9 @@ export class Project implements ISqlProject {
result = await sqlProjService.addSystemDatabaseReference(this.projectFilePath, systemDb, settings.suppressMissingDependenciesErrors, referenceType, settings.databaseVariableLiteralValue);
} else {
systemDb = <unknown>settings.systemDb as vscodeMssql.SystemDatabase;
referenceType = settings.systemDbReferenceType as vscodeMssql.SystemDbReferenceType;
sqlProjService = this.sqlProjService as vscodeMssql.ISqlProjectsService;
result = await sqlProjService.addSystemDatabaseReference(this.projectFilePath, systemDb, settings.suppressMissingDependenciesErrors, settings.databaseVariableLiteralValue);
result = await sqlProjService.addSystemDatabaseReference(this.projectFilePath, systemDb, settings.suppressMissingDependenciesErrors, referenceType, settings.databaseVariableLiteralValue);
}

if (!result.success && result.errorMessage) {
Expand Down
21 changes: 17 additions & 4 deletions extensions/types/vscode-mssql.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -482,9 +482,10 @@ declare module 'vscode-mssql' {
* @param projectUri Absolute path of the project, including .sqlproj
* @param systemDatabase Type of system database
* @param suppressMissingDependencies Whether to suppress missing dependencies
* @param referenceType Type of reference - ArtifactReference or PackageReference
* @param databaseLiteral Literal name used to reference another database in the same server, if not using SQLCMD variables
*/
addSystemDatabaseReference(projectUri: string, systemDatabase: SystemDatabase, suppressMissingDependencies: boolean, databaseLiteral?: string): Promise<ResultStatus>;
addSystemDatabaseReference(projectUri: string, systemDatabase: SystemDatabase, suppressMissingDependencies: boolean, referenceType: SystemDbReferenceType, databaseLiteral?: string): Promise<ResultStatus>;

/**
* Add a nuget package database reference to a project
Expand Down Expand Up @@ -1112,7 +1113,7 @@ declare module 'vscode-mssql' {
packageFilePath: string;
databaseName: string;
upgradeExisting: boolean;
sqlCommandVariableValues?: Map<string, string>;
sqlCommandVariableValues?: Record<string, string>;
deploymentOptions?: DeploymentOptions;
ownerUri: string;
taskExecutionMode: TaskExecutionMode;
Expand All @@ -1121,7 +1122,7 @@ declare module 'vscode-mssql' {
export interface GenerateDeployScriptParams {
packageFilePath: string;
databaseName: string;
sqlCommandVariableValues?: Map<string, string>;
sqlCommandVariableValues?: Record<string, string>;
deploymentOptions?: DeploymentOptions;
ownerUri: string;
taskExecutionMode: TaskExecutionMode;
Expand Down Expand Up @@ -1153,7 +1154,7 @@ declare module 'vscode-mssql' {
profilePath: string;
databaseName: string;
connectionString: string;
sqlCommandVariableValues?: Map<string, string>;
sqlCommandVariableValues?: Record<string, string>;
deploymentOptions?: DeploymentOptions;
}

Expand Down Expand Up @@ -1209,6 +1210,11 @@ declare module 'vscode-mssql' {
* Type of system database
*/
systemDatabase: SystemDatabase;

/**
* Type of reference - ArtifactReference or PackageReference
*/
referenceType: SystemDbReferenceType;
}

export interface AddNugetPackageReferenceParams extends AddUserDatabaseReferenceParams {
Expand Down Expand Up @@ -1249,6 +1255,13 @@ declare module 'vscode-mssql' {
path: string;
}

export interface MoveFolderParams extends FolderParams {
/**
* Path of the folder, typically relative to the .sqlproj file
*/
destinationPath: string;
}

export interface CreateSqlProjectParams extends SqlProjectParams {
/**
* Type of SQL Project: SDK-style or Legacy
Expand Down

0 comments on commit 42a0622

Please sign in to comment.