fix sqlcmd variables not getting loaded correctly in vscode (#23103) (#23108)

This commit is contained in:
Kim Santiago
2023-05-11 19:31:34 -07:00
committed by GitHub
parent 343d878457
commit 0cfaf69647

View File

@@ -159,9 +159,7 @@ export async function getPublishDatabaseSettings(project: ISqlProject, promptFor
} }
// 4. Modify sqlcmd vars // 4. Modify sqlcmd vars
// If a publish profile is provided then the values from there will overwrite the ones in the let sqlCmdVariables: Map<string, string> = getInitialSqlCmdVariables(project, publishProfile);
// project file (if they exist)
let sqlCmdVariables = Object.assign({}, project.sqlCmdVariables, publishProfile?.sqlCmdVariables);
if (sqlCmdVariables.size > 0) { if (sqlCmdVariables.size > 0) {
// Continually loop here, allowing the user to modify SQLCMD variables one // 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 // as many times as they wish - with an option to reset all the variables
// to their starting values being provided as well. // to their starting values being provided as well.
while (true) { while (true) {
const quickPickItems = Object.keys(sqlCmdVariables).map(key => { let quickPickItems = [];
return { for (const key of sqlCmdVariables.keys()) {
quickPickItems.push({
label: key, label: key,
description: sqlCmdVariables.get(key), description: sqlCmdVariables.get(key),
key: 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.push({ label: `$(refresh) ${constants.resetAllVars}`, isResetAllVars: true });
quickPickItems.unshift({ label: `$(check) ${constants.done}`, isDone: true }); quickPickItems.unshift({ label: `$(check) ${constants.done}`, isDone: true });
const sqlCmd = await vscode.window.showQuickPick( const sqlCmd = await vscode.window.showQuickPick(
@@ -200,7 +199,7 @@ export async function getPublishDatabaseSettings(project: ISqlProject, promptFor
sqlCmdVariables.set(sqlCmd.key, newValue); sqlCmdVariables.set(sqlCmd.key, newValue);
} }
} else if (sqlCmd.isResetAllVars) { } else if (sqlCmd.isResetAllVars) {
sqlCmdVariables = Object.assign({}, project.sqlCmdVariables, publishProfile?.sqlCmdVariables); sqlCmdVariables = getInitialSqlCmdVariables(project, publishProfile);
} else if (sqlCmd.isDone) { } else if (sqlCmd.isDone) {
break; break;
} }
@@ -220,6 +219,24 @@ export async function getPublishDatabaseSettings(project: ISqlProject, promptFor
return settings; 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<string, string> {
// 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<constants.PublishTargetType | undefined> { export async function launchPublishTargetOption(project: Project): Promise<constants.PublishTargetType | undefined> {
// Show options to user for deploy to existing server or docker // Show options to user for deploy to existing server or docker
const target = project.getProjectTargetVersion(); const target = project.getProjectTargetVersion();