Add validation for checking for dacpac being on the same drive (#21434)

* add extra validation for add dacpac reference quickpick

* Add placeholder with message
This commit is contained in:
Kim Santiago
2022-12-16 14:18:26 -08:00
committed by GitHub
parent 710fb0df62
commit 754d70d654
2 changed files with 30 additions and 12 deletions

View File

@@ -46,7 +46,7 @@ export async function addDatabaseReferenceQuickpick(project: Project): Promise<A
case constants.systemDatabase:
return addSystemDatabaseReference(project);
case constants.dacpacText:
return addDacpacReference();
return addDacpacReference(project);
default:
console.log(`Unknown reference type ${referenceType}`);
return undefined;
@@ -130,7 +130,7 @@ async function addSystemDatabaseReference(project: Project): Promise<ISystemData
};
}
async function addDacpacReference(): Promise<IDacpacReferenceSettings | undefined> {
async function addDacpacReference(project: Project): Promise<IDacpacReferenceSettings | undefined> {
// (steps continued from addDatabaseReferenceQuickpick)
// 2. Prompt for location
const location = await promptLocation();
@@ -141,17 +141,34 @@ async function addDacpacReference(): Promise<IDacpacReferenceSettings | undefine
// 3. Prompt for dacpac location
// Show quick pick with just browse option to give user context about what the file dialog is for (since that doesn't always have a title)
const browseSelected = await vscode.window.showQuickPick(
[constants.browseEllipsisWithIcon],
{ title: constants.selectDacpac, ignoreFocusOut: true });
if (!browseSelected) {
return undefined;
}
let dacPacLocation;
while (!dacPacLocation) {
const browseSelected = await vscode.window.showQuickPick(
[constants.browseEllipsisWithIcon],
{
title: constants.selectDacpac,
ignoreFocusOut: true,
placeHolder: constants.dacpacMustBeOnSameDrive
});
if (!browseSelected) {
return undefined;
}
const dacPacLocation = (await promptDacpacLocation())?.[0];
if (!dacPacLocation) {
// User cancelled
return undefined;
dacPacLocation = (await promptDacpacLocation())?.[0];
if (!dacPacLocation) {
// User cancelled
return undefined;
}
// only support adding dacpacs that are on the same drive as the sqlproj
const projectDrive = path.parse(project.projectFilePath).root;
const dacpacDrive = path.parse(dacPacLocation.fsPath).root;
if (projectDrive !== dacpacDrive) {
void vscode.window.showErrorMessage(constants.dacpacNotOnSameDrive(project.projectFilePath));
// set dacPacLocation to undefined so that the browse quickpick will show again
dacPacLocation = undefined;
}
}
// 4. Prompt for db/server values