Handle no azdata API in sql db proj extension gracefully (#15873)

* Update db proj ext to handle not having azdata API available

* Fixes

* Fix compile
This commit is contained in:
Charles Gagnon
2021-06-22 23:34:01 -07:00
committed by GitHub
parent c636e24d03
commit 4707c1601c
12 changed files with 192 additions and 175 deletions

View File

@@ -3,7 +3,7 @@
* Licensed under the Source EULA. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import * as azdata from 'azdata';
import type * as azdataType from 'azdata';
import * as vscode from 'vscode';
import * as templates from '../templates/templates';
import * as path from 'path';
@@ -49,7 +49,7 @@ export default class MainController implements vscode.Disposable {
vscode.commands.registerCommand('sqlDatabaseProjects.build', async (node: WorkspaceTreeItem) => { await this.projectsController.buildProject(node); });
vscode.commands.registerCommand('sqlDatabaseProjects.publish', async (node: WorkspaceTreeItem) => { await this.projectsController.publishProject(node); });
vscode.commands.registerCommand('sqlDatabaseProjects.schemaCompare', async (node: WorkspaceTreeItem) => { await this.projectsController.schemaCompare(node); });
vscode.commands.registerCommand('sqlDatabaseProjects.createProjectFromDatabase', async (profile: azdata.IConnectionProfile) => { await this.projectsController.createProjectFromDatabase(profile); });
vscode.commands.registerCommand('sqlDatabaseProjects.createProjectFromDatabase', async (profile: azdataType.IConnectionProfile) => { await this.projectsController.createProjectFromDatabase(profile); });
vscode.commands.registerCommand('sqlDatabaseProjects.newScript', async (node: WorkspaceTreeItem) => { await this.projectsController.addItemPromptFromNode(node, templates.script); });
vscode.commands.registerCommand('sqlDatabaseProjects.newPreDeploymentScript', async (node: WorkspaceTreeItem) => { await this.projectsController.addItemPromptFromNode(node, templates.preDeployScript); });

View File

@@ -11,7 +11,7 @@ import * as utils from '../common/utils';
import * as UUID from 'vscode-languageclient/lib/utils/uuid';
import * as templates from '../templates/templates';
import * as vscode from 'vscode';
import * as azdata from 'azdata';
import type * as azdataType from 'azdata';
import * as dataworkspace from 'dataworkspace';
import { promises as fs } from 'fs';
@@ -57,7 +57,7 @@ export class ProjectsController {
for (let i = this.publishInfo.length - 1; i >= 0; i--) {
if (this.publishInfo[i].projectFile === projectFile) {
let icon: azdata.IconPath;
let icon: azdataType.IconPath;
let text: string;
if (this.publishInfo[i].status === Status.success) {
icon = IconPathHelper.success;
@@ -88,7 +88,7 @@ export class ProjectsController {
for (let i = this.buildInfo.length - 1; i >= 0; i--) {
if (this.buildInfo[i].projectFile === projectFile) {
let icon: azdata.IconPath;
let icon: azdataType.IconPath;
let text: string;
if (this.buildInfo[i].status === Status.success) {
icon = IconPathHelper.success;
@@ -286,11 +286,11 @@ export class ProjectsController {
try {
if ((<IPublishSettings>settings).upgradeExisting) {
telemetryProps.publishAction = 'deploy';
result = await dacFxService.deployDacpac(tempPath, settings.databaseName, (<IPublishSettings>settings).upgradeExisting, settings.connectionUri, azdata.TaskExecutionMode.execute, settings.sqlCmdVariables, settings.deploymentOptions);
result = await dacFxService.deployDacpac(tempPath, settings.databaseName, (<IPublishSettings>settings).upgradeExisting, settings.connectionUri, utils.getAzdataApi()!.TaskExecutionMode.execute, settings.sqlCmdVariables, settings.deploymentOptions);
}
else {
telemetryProps.publishAction = 'generateScript';
result = await dacFxService.generateDeployScript(tempPath, settings.databaseName, settings.connectionUri, azdata.TaskExecutionMode.script, settings.sqlCmdVariables, settings.deploymentOptions);
result = await dacFxService.generateDeployScript(tempPath, settings.databaseName, settings.connectionUri, utils.getAzdataApi()!.TaskExecutionMode.script, settings.sqlCmdVariables, settings.deploymentOptions);
}
} catch (err) {
const actionEndTime = new Date().getTime();
@@ -842,7 +842,7 @@ export class ProjectsController {
* Creates a new SQL database project from the existing database,
* prompting the user for a name, file path location and extract target
*/
public async createProjectFromDatabase(context: azdata.IConnectionProfile | any): Promise<CreateProjectFromDatabaseDialog> {
public async createProjectFromDatabase(context: azdataType.IConnectionProfile | any): Promise<CreateProjectFromDatabaseDialog> {
const profile = this.getConnectionProfileFromContext(context);
let createProjectFromDatabaseDialog = this.getCreateProjectFromDatabaseDialog(profile);
@@ -853,7 +853,7 @@ export class ProjectsController {
return createProjectFromDatabaseDialog;
}
public getCreateProjectFromDatabaseDialog(profile: azdata.IConnectionProfile | undefined): CreateProjectFromDatabaseDialog {
public getCreateProjectFromDatabaseDialog(profile: azdataType.IConnectionProfile | undefined): CreateProjectFromDatabaseDialog {
return new CreateProjectFromDatabaseDialog(profile);
}
@@ -895,7 +895,7 @@ export class ProjectsController {
}
}
private getConnectionProfileFromContext(context: azdata.IConnectionProfile | any): azdata.IConnectionProfile | undefined {
private getConnectionProfileFromContext(context: azdataType.IConnectionProfile | any): azdataType.IConnectionProfile | undefined {
if (!context) {
return undefined;
}
@@ -909,9 +909,9 @@ export class ProjectsController {
let ext = vscode.extensions.getExtension(mssql.extension.name)!;
const service = (await ext.activate() as mssql.IExtension).dacFx;
const ownerUri = await azdata.connection.getUriForConnection(model.serverId);
const ownerUri = await utils.getAzdataApi()!.connection.getUriForConnection(model.serverId);
await service.createProjectFromDatabase(model.database, model.filePath, model.projName, model.version, ownerUri, model.extractTarget, azdata.TaskExecutionMode.execute);
await service.createProjectFromDatabase(model.database, model.filePath, model.projName, model.version, ownerUri, model.extractTarget, utils.getAzdataApi()!.TaskExecutionMode.execute);
// TODO: Check for success; throw error
}