Separate connect and listdatabases call for publish (#16391)

* Separate connect and listdatabases call for publish

* add return value
This commit is contained in:
Charles Gagnon
2021-07-22 15:36:16 -07:00
committed by GitHub
parent 88d28b7d51
commit 0509f8f0c3
2 changed files with 34 additions and 6 deletions

View File

@@ -9,6 +9,7 @@ import { Project } from '../models/project';
import { PublishProfile, readPublishProfile } from '../models/publishProfile/publishProfile'; import { PublishProfile, readPublishProfile } from '../models/publishProfile/publishProfile';
import { promptForPublishProfile } from './publishDatabaseDialog'; import { promptForPublishProfile } from './publishDatabaseDialog';
import { getVscodeMssqlApi } from '../common/utils'; import { getVscodeMssqlApi } from '../common/utils';
import { IConnectionInfo } from 'vscode-mssql';
/** /**
* Create flow for Publishing a database using only VS Code-native APIs such as QuickPick * Create flow for Publishing a database using only VS Code-native APIs such as QuickPick
@@ -72,15 +73,19 @@ export async function launchPublishDatabaseQuickpick(project: Project): Promise<
// 2. Select connection // 2. Select connection
const vscodeMssqlApi = await getVscodeMssqlApi(); const vscodeMssqlApi = await getVscodeMssqlApi();
let connectionProfile: IConnectionInfo | undefined = undefined;
let connectionUri: string = '';
let dbs: string[] | undefined = undefined; let dbs: string[] | undefined = undefined;
while (!dbs) { while (!dbs) {
const connectionProfile = await vscodeMssqlApi.promptForConnection(true); connectionProfile = await vscodeMssqlApi.promptForConnection(true);
if (!connectionProfile) { if (!connectionProfile) {
// User cancelled
return; return;
} }
// Get the list of databases now to validate that the connection is valid and re-prompt them if it isn't // Get the list of databases now to validate that the connection is valid and re-prompt them if it isn't
try { try {
dbs = await vscodeMssqlApi.listDatabases(connectionProfile); connectionUri = await vscodeMssqlApi.connect(connectionProfile);
dbs = await vscodeMssqlApi.listDatabases(connectionUri);
} catch (err) { } catch (err) {
// no-op, the mssql extension handles showing the error to the user. We'll just go // no-op, the mssql extension handles showing the error to the user. We'll just go
// back and prompt the user for a connection again // back and prompt the user for a connection again

View File

@@ -26,6 +26,11 @@ declare module 'vscode-mssql' {
*/ */
readonly dacFx: IDacFxService; readonly dacFx: IDacFxService;
/**
* Service for accessing SchemaCompare functionality
*/
readonly schemaCompare: ISchemaCompareService;
/** /**
* Prompts the user to select an existing connection or create a new one, and then returns the result * Prompts the user to select an existing connection or create a new one, and then returns the result
* @param ignoreFocusOut Whether the quickpick prompt ignores focus out (default false) * @param ignoreFocusOut Whether the quickpick prompt ignores focus out (default false)
@@ -33,11 +38,19 @@ declare module 'vscode-mssql' {
promptForConnection(ignoreFocusOut?: boolean): Promise<IConnectionInfo | undefined>; promptForConnection(ignoreFocusOut?: boolean): Promise<IConnectionInfo | undefined>;
/** /**
* Lists the databases for a given connection. An error is thrown and displayed to the user if an * Attempts to create a new connection for the given connection info. An error is thrown and displayed
* error occurs while connecting * to the user if an error occurs while connecting.
* @param connection The connection to list the databases for * @param connectionInfo The connection info
* @returns The URI associated with this connection
*/ */
listDatabases(connection: IConnectionInfo): Promise<string[]>; connect(connectionInfo: IConnectionInfo): Promise<string>;
/**
* Lists the databases for a given connection. Must be given an already-opened connection to succeed.
* @param connectionUri The URI of the connection to list the databases for.
* @returns The list of database names
*/
listDatabases(connectionUri: string): Promise<string[]>;
} }
/** /**
@@ -212,6 +225,10 @@ declare module 'vscode-mssql' {
schemaObjectType = 5 schemaObjectType = 5
} }
export interface ISchemaCompareService {
schemaCompareGetDefaultOptions(): Thenable<SchemaCompareOptionsResult>;
}
export interface IDacFxService { export interface IDacFxService {
exportBacpac(databaseName: string, packageFilePath: string, ownerUri: string, taskExecutionMode: TaskExecutionMode): Thenable<DacFxResult>; exportBacpac(databaseName: string, packageFilePath: string, ownerUri: string, taskExecutionMode: TaskExecutionMode): Thenable<DacFxResult>;
importBacpac(packageFilePath: string, databaseName: string, ownerUri: string, taskExecutionMode: TaskExecutionMode): Thenable<DacFxResult>; importBacpac(packageFilePath: string, databaseName: string, ownerUri: string, taskExecutionMode: TaskExecutionMode): Thenable<DacFxResult>;
@@ -467,4 +484,10 @@ declare module 'vscode-mssql' {
createStreamingJobTsql: string; createStreamingJobTsql: string;
} }
export interface SchemaCompareGetOptionsParams { }
export interface SchemaCompareOptionsResult extends ResultStatus {
defaultDeploymentOptions: DeploymentOptions;
}
} }