New UI for deploying SQL project to a new Azure server (#18833)

This commit is contained in:
Leila Lali
2022-04-29 15:39:21 -07:00
committed by GitHub
parent 14a63977c8
commit d95aff1d3c
17 changed files with 1453 additions and 367 deletions

View File

@@ -7,11 +7,14 @@ import * as vscode from 'vscode';
import * as constants from '../common/constants';
import * as utils from '../common/utils';
import * as uiUtils from './utils';
import { AppSettingType, DockerImageInfo, IDeployAppIntegrationProfile, IDeployProfile, ILocalDbSetting } from '../models/deploy/deployProfile';
import { AppSettingType, DockerImageInfo, IDeployAppIntegrationProfile, ISqlDbDeployProfile, ILocalDbDeployProfile, ILocalDbSetting } from '../models/deploy/deployProfile';
import { Project } from '../models/project';
import { getPublishDatabaseSettings } from './publishDatabaseQuickpick';
import * as path from 'path';
import * as fse from 'fs-extra';
import { AzureSqlClient } from '../models/deploy/azureSqlClient';
import { IDeploySettings } from '../models/IDeploySettings';
import { IAccount } from 'vscode-mssql';
/**
* Create flow for Deploying a database using only VS Code-native APIs such as QuickPick
@@ -112,11 +115,166 @@ async function launchEulaQuickPick(imageInfo: DockerImageInfo | undefined): Prom
return false;
}
export async function launchCreateAzureServerQuickPick(project: Project, azureSqlClient: AzureSqlClient): Promise<ISqlDbDeployProfile | undefined> {
const name = uiUtils.getPublishServerName(project.getProjectTargetVersion());
const accounts = await azureSqlClient.getAccounts();
const accountOptions = accounts.map(x => x.displayInfo?.displayName || '');
accountOptions.unshift(constants.azureAddAccount);
let account: IAccount | undefined;
let accountOption = await vscode.window.showQuickPick(
accountOptions,
{ title: constants.azureAccounts, ignoreFocusOut: true });
// Return when user hits escape
if (!accountOption) {
return undefined;
}
if (accountOption === constants.azureAddAccount) {
account = await azureSqlClient.getAccount();
} else {
account = accounts.find(x => x.displayInfo.displayName === accountOption);
}
if (!account) {
return undefined;
}
const sessions = await azureSqlClient.getSessions(account);
const subscriptionName = await vscode.window.showQuickPick(
sessions.map(x => x.subscription.displayName || ''),
{ title: constants.azureSubscription, ignoreFocusOut: true });
// Return when user hits escape
if (!subscriptionName) {
return undefined;
}
const session = sessions.find(x => x.subscription.displayName === subscriptionName);
if (!session?.subscription?.subscriptionId) {
return undefined;
}
const resourceGroups = await azureSqlClient.getResourceGroups(session);
const resourceGroupName = await vscode.window.showQuickPick(
resourceGroups.map(x => x.name || ''),
{ title: constants.resourceGroup, ignoreFocusOut: true });
// Return when user hits escape
if (!resourceGroupName) {
return undefined;
}
const resourceGroup = resourceGroups.find(x => x.name === resourceGroupName);
// Return resource group is invalid
if (!resourceGroup) {
return undefined;
}
let locations = await azureSqlClient.getLocations(session);
if (resourceGroup.location) {
const defaultLocation = locations.find(x => x.name === resourceGroup.location);
if (defaultLocation) {
locations = locations.filter(x => x.name !== defaultLocation.name);
locations.unshift(defaultLocation);
}
}
let locationName = await vscode.window.showQuickPick(
locations.map(x => x.name || ''),
{ title: constants.azureLocation, ignoreFocusOut: true, placeHolder: resourceGroup?.location });
// Return when user hits escape
if (!locationName) {
return undefined;
}
let serverName: string | undefined = '';
serverName = await vscode.window.showInputBox({
title: constants.azureServerName,
ignoreFocusOut: true,
value: serverName,
password: false
}
);
// Return when user hits escape
if (!serverName) {
return undefined;
}
let user: string | undefined = '';
user = await vscode.window.showInputBox({
title: constants.enterUser(name),
ignoreFocusOut: true,
value: user,
password: false
}
);
// Return when user hits escape
if (!user) {
return undefined;
}
let password: string | undefined = '';
password = await vscode.window.showInputBox({
title: constants.enterPassword(name),
ignoreFocusOut: true,
value: password,
validateInput: input => !utils.isValidSQLPassword(input) ? constants.invalidSQLPasswordMessage(name) : undefined,
password: true
}
);
// Return when user hits escape
if (!password) {
return undefined;
}
let confirmPassword: string | undefined = '';
confirmPassword = await vscode.window.showInputBox({
title: constants.confirmPassword(name),
ignoreFocusOut: true,
value: confirmPassword,
validateInput: input => input !== password ? constants.passwordNotMatch(name) : undefined,
password: true
}
);
// Return when user hits escape
if (!confirmPassword) {
return undefined;
}
let settings: IDeploySettings | undefined = await getPublishDatabaseSettings(project, false);
return {
// TODO add tenant
deploySettings: settings, sqlDbSetting: {
tenantId: session.tenantId,
accountId: session.account.key.id,
serverName: serverName,
userName: user,
password: password,
port: 1433,
dbName: '',
session: session,
resourceGroupName: resourceGroup.name || '',
location: locationName
}
};
}
/**
* Create flow for publishing a database to docker container using only VS Code-native APIs such as QuickPick
*/
export async function launchPublishToDockerContainerQuickpick(project: Project): Promise<IDeployProfile | undefined> {
export async function launchPublishToDockerContainerQuickpick(project: Project): Promise<ILocalDbDeployProfile | undefined> {
const name = uiUtils.getPublishServerName(project.getProjectTargetVersion());
let localDbSetting: ILocalDbSetting | undefined;
// Deploy to docker selected

View File

@@ -16,7 +16,7 @@ import { IconPathHelper } from '../common/iconHelper';
import { cssStyles } from '../common/uiConstants';
import { getAgreementDisplayText, getConnectionName, getDockerBaseImages, getPublishServerName } from './utils';
import { TelemetryActions, TelemetryReporter, TelemetryViews } from '../common/telemetry';
import { IDeployProfile } from '../models/deploy/deployProfile';
import { ILocalDbDeployProfile } from '../models/deploy/deployProfile';
import { Deferred } from '../common/promise';
interface DataSourceDropdownValue extends azdataType.CategoryValue {
@@ -62,7 +62,7 @@ export class PublishDatabaseDialog {
private toDispose: vscode.Disposable[] = [];
public publish: ((proj: Project, profile: IDeploySettings) => any) | undefined;
public publishToContainer: ((proj: Project, profile: IDeployProfile) => any) | undefined;
public publishToContainer: ((proj: Project, profile: ILocalDbDeployProfile) => any) | undefined;
public generateScript: ((proj: Project, profile: IDeploySettings) => any) | undefined;
public readPublishProfile: ((profileUri: vscode.Uri) => any) | undefined;
@@ -232,7 +232,7 @@ export class PublishDatabaseDialog {
const dockerBaseImage = this.getBaseDockerImageName();
const baseImages = getDockerBaseImages(this.project.getProjectTargetVersion());
const imageInfo = baseImages.find(x => x.name === dockerBaseImage);
const settings: IDeployProfile = {
const settings: ILocalDbDeployProfile = {
localDbSetting: {
dbName: this.targetDatabaseName,
dockerBaseImage: dockerBaseImage,

View File

@@ -12,6 +12,7 @@ import { getDefaultPublishDeploymentOptions, getVscodeMssqlApi } from '../common
import { IConnectionInfo } from 'vscode-mssql';
import { IDeploySettings } from '../models/IDeploySettings';
import { getPublishServerName } from './utils';
import { SqlTargetPlatform } from 'sqldbproj';
/**
* Create flow for Publishing a database using only VS Code-native APIs such as QuickPick
@@ -209,9 +210,14 @@ export async function getPublishDatabaseSettings(project: Project, promptForConn
export async function launchPublishTargetOption(project: Project): Promise<constants.PublishTargetType | undefined> {
// Show options to user for deploy to existing server or docker
const name = getPublishServerName(project.getProjectTargetVersion());
const target = project.getProjectTargetVersion();
const name = getPublishServerName(target);
const logicalServerName = target === constants.targetPlatformToVersion.get(SqlTargetPlatform.sqlAzure) ? constants.AzureSqlLogicalServerName : constants.SqlServerName;
const options = target === constants.targetPlatformToVersion.get(SqlTargetPlatform.sqlAzure) ?
[constants.publishToDockerContainer(name), constants.publishToNewAzureServer, constants.publishToExistingServer(logicalServerName)] :
[constants.publishToDockerContainer(name), constants.publishToExistingServer(logicalServerName)];
const publishOption = await vscode.window.showQuickPick(
[constants.publishToExistingServer(name), constants.publishToDockerContainer(name)],
options,
{ title: constants.selectPublishOption, ignoreFocusOut: true });
// Return when user hits escape
@@ -224,6 +230,8 @@ export async function launchPublishTargetOption(project: Project): Promise<const
return constants.PublishTargetType.existingServer;
case constants.publishToDockerContainer(name):
return constants.PublishTargetType.docker;
case constants.publishToNewAzureServer:
return constants.PublishTargetType.newAzureServer;
default:
return constants.PublishTargetType.existingServer;
}