diff --git a/extensions/sql-database-projects/src/dialogs/publishDatabaseQuickpick.ts b/extensions/sql-database-projects/src/dialogs/publishDatabaseQuickpick.ts index 5c683c3816..e7b4d0d9e8 100644 --- a/extensions/sql-database-projects/src/dialogs/publishDatabaseQuickpick.ts +++ b/extensions/sql-database-projects/src/dialogs/publishDatabaseQuickpick.ts @@ -159,9 +159,7 @@ export async function getPublishDatabaseSettings(project: ISqlProject, promptFor } // 4. Modify sqlcmd vars - // If a publish profile is provided then the values from there will overwrite the ones in the - // project file (if they exist) - let sqlCmdVariables = Object.assign({}, project.sqlCmdVariables, publishProfile?.sqlCmdVariables); + let sqlCmdVariables: Map = getInitialSqlCmdVariables(project, publishProfile); if (sqlCmdVariables.size > 0) { // Continually loop here, allowing the user to modify SQLCMD variables one @@ -170,13 +168,14 @@ export async function getPublishDatabaseSettings(project: ISqlProject, promptFor // as many times as they wish - with an option to reset all the variables // to their starting values being provided as well. while (true) { - const quickPickItems = Object.keys(sqlCmdVariables).map(key => { - return { + let quickPickItems = []; + for (const key of sqlCmdVariables.keys()) { + quickPickItems.push({ label: key, description: sqlCmdVariables.get(key), key: key - } as vscode.QuickPickItem & { key?: string, isResetAllVars?: boolean, isDone?: boolean }; - }); + } as vscode.QuickPickItem & { key?: string, isResetAllVars?: boolean, isDone?: boolean }) + } quickPickItems.push({ label: `$(refresh) ${constants.resetAllVars}`, isResetAllVars: true }); quickPickItems.unshift({ label: `$(check) ${constants.done}`, isDone: true }); const sqlCmd = await vscode.window.showQuickPick( @@ -200,7 +199,7 @@ export async function getPublishDatabaseSettings(project: ISqlProject, promptFor sqlCmdVariables.set(sqlCmd.key, newValue); } } else if (sqlCmd.isResetAllVars) { - sqlCmdVariables = Object.assign({}, project.sqlCmdVariables, publishProfile?.sqlCmdVariables); + sqlCmdVariables = getInitialSqlCmdVariables(project, publishProfile); } else if (sqlCmd.isDone) { break; } @@ -220,6 +219,24 @@ export async function getPublishDatabaseSettings(project: ISqlProject, promptFor return settings; } +/** + * Loads the sqlcmd variables from a sql projects. If a publish profile is provided then the values from there will overwrite the ones in the project file (if they exist) + * @param project + * @param publishProfile + * @returns Map of sqlcmd variables + */ +function getInitialSqlCmdVariables(project: ISqlProject, publishProfile?: PublishProfile): Map { + // create a copy of the sqlcmd variable map so that the original ones don't get overwritten + let sqlCmdVariables = new Map(project.sqlCmdVariables); + if (publishProfile?.sqlCmdVariables) { + for (const [key, value] of publishProfile.sqlCmdVariables) { + sqlCmdVariables.set(key, value); + } + } + + return sqlCmdVariables; +} + export async function launchPublishTargetOption(project: Project): Promise { // Show options to user for deploy to existing server or docker const target = project.getProjectTargetVersion();