mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-01-26 17:23:15 -05:00
Required changes to make sql projects extension work with vscode (#22847)
* Update CreateProject api * More updates * Fix a few comments * Address comments * Remove package.json changes * Fix error * Fix testUtil
This commit is contained in:
12
extensions/sql-database-projects/src/common/typeHelper.ts
Normal file
12
extensions/sql-database-projects/src/common/typeHelper.ts
Normal file
@@ -0,0 +1,12 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import * as mssql from 'mssql';
|
||||
import * as vscodeMssql from 'vscode-mssql';
|
||||
|
||||
export type ProjectType = mssql.ProjectType | vscodeMssql.ProjectType;
|
||||
export type GetScriptsResult = mssql.GetScriptsResult | vscodeMssql.GetScriptsResult;
|
||||
export type GetFoldersResult = mssql.GetFoldersResult | vscodeMssql.GetFoldersResult;
|
||||
export type SystemDatabase = mssql.SystemDatabase | vscodeMssql.SystemDatabase;
|
||||
@@ -16,6 +16,7 @@ import * as fse from 'fs-extra';
|
||||
import * as which from 'which';
|
||||
import { promises as fs } from 'fs';
|
||||
import { ISqlProject, SqlTargetPlatform } from 'sqldbproj';
|
||||
import { SystemDatabase } from './typeHelper';
|
||||
|
||||
export interface ValidationResult {
|
||||
errorMessage: string;
|
||||
@@ -157,14 +158,22 @@ export function convertSlashesForSqlProj(filePath: string): string {
|
||||
* @param systemDb
|
||||
* @returns
|
||||
*/
|
||||
export function systemDatabaseToString(systemDb: mssql.SystemDatabase): string {
|
||||
if (systemDb === mssql.SystemDatabase.Master) {
|
||||
export function systemDatabaseToString(systemDb: SystemDatabase): string {
|
||||
if (systemDb === mssql.SystemDatabase.Master || systemDb === vscodeMssql.SystemDatabase.Master) {
|
||||
return constants.master;
|
||||
} else {
|
||||
return constants.msdb;
|
||||
}
|
||||
}
|
||||
|
||||
export function getSystemDatabase(name: string): SystemDatabase {
|
||||
if (getAzdataApi()) {
|
||||
return name === constants.master ? mssql.SystemDatabase.Master : mssql.SystemDatabase.MSDB;
|
||||
} else {
|
||||
return name === constants.master ? vscodeMssql.SystemDatabase.Master : vscodeMssql.SystemDatabase.MSDB;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Read SQLCMD variables from xmlDoc and return them
|
||||
* @param xmlDoc xml doc to read SQLCMD variables from. Format must be the same that sqlproj and publish profiles use
|
||||
@@ -315,15 +324,14 @@ export async function getSchemaCompareService(): Promise<ISchemaCompareService>
|
||||
}
|
||||
}
|
||||
|
||||
export async function getSqlProjectsService(): Promise<mssql.ISqlProjectsService> {
|
||||
export async function getSqlProjectsService(): Promise<ISqlProjectsService> {
|
||||
if (getAzdataApi()) {
|
||||
const ext = vscode.extensions.getExtension(mssql.extension.name) as vscode.Extension<mssql.IExtension>;
|
||||
const api = await ext.activate();
|
||||
return api.sqlProjects;
|
||||
} else {
|
||||
throw new Error(constants.errorNotSupportedInVsCode('SqlProjectService'));
|
||||
// const api = await getVscodeMssqlApi();
|
||||
// return api.sqlProjects;
|
||||
const api = await getVscodeMssqlApi();
|
||||
return api.sqlProjects;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -202,9 +202,8 @@ export class ProjectsController {
|
||||
const projectStyle = creationParams.sdkStyle ? mssql.ProjectType.SdkStyle : mssql.ProjectType.LegacyStyle;
|
||||
await (sqlProjectsService as mssql.ISqlProjectsService).createProject(newProjFilePath, projectStyle, targetPlatform);
|
||||
} else {
|
||||
throw new Error(constants.errorNotSupportedInVsCode('createProject'));
|
||||
//const projectStyle = creationParams.sdkStyle ? mssqlVscode.ProjectType.SdkStyle : mssqlVscode.ProjectType.LegacyStyle;
|
||||
//await (sqlProjectsService as mssqlVscode.ISqlProjectsService).createProject(newProjFilePath, projectStyle, targetPlatform);
|
||||
const projectStyle = creationParams.sdkStyle ? mssqlVscode.ProjectType.SdkStyle : mssqlVscode.ProjectType.LegacyStyle;
|
||||
await (sqlProjectsService as mssqlVscode.ISqlProjectsService).createProject(newProjFilePath, projectStyle, targetPlatform);
|
||||
}
|
||||
|
||||
await this.addTemplateFiles(newProjFilePath, creationParams.projectTypeId);
|
||||
|
||||
@@ -15,8 +15,8 @@ import { IconPathHelper } from '../common/iconHelper';
|
||||
import { ISystemDatabaseReferenceSettings, IDacpacReferenceSettings, IProjectReferenceSettings, INugetPackageReferenceSettings } from '../models/IDatabaseReferenceSettings';
|
||||
import { Deferred } from '../common/promise';
|
||||
import { TelemetryActions, TelemetryReporter, TelemetryViews } from '../common/telemetry';
|
||||
import { ProjectType, SystemDatabase } from 'mssql';
|
||||
import { DbServerValues, ensureSetOrDefined, populateResultWithVars } from './utils';
|
||||
import { ProjectType } from 'mssql';
|
||||
|
||||
export enum ReferenceType {
|
||||
project,
|
||||
@@ -160,7 +160,7 @@ export class AddDatabaseReferenceDialog {
|
||||
if (this.currentReferenceType === ReferenceType.systemDb) {
|
||||
const systemDbRef: ISystemDatabaseReferenceSettings = {
|
||||
databaseVariableLiteralValue: <string>this.databaseNameTextbox?.value,
|
||||
systemDb: getSystemDatabase(<string>this.systemDatabaseDropdown?.value),
|
||||
systemDb: utils.getSystemDatabase(<string>this.systemDatabaseDropdown?.value),
|
||||
suppressMissingDependenciesErrors: <boolean>this.suppressMissingDependenciesErrorsCheckbox?.checked
|
||||
};
|
||||
|
||||
@@ -734,10 +734,6 @@ export function getSystemDbOptions(project: Project): string[] {
|
||||
return [constants.master, constants.msdb];
|
||||
}
|
||||
|
||||
export function getSystemDatabase(name: string): SystemDatabase {
|
||||
return name === constants.master ? SystemDatabase.Master : SystemDatabase.MSDB;
|
||||
}
|
||||
|
||||
export async function promptDacpacLocation(): Promise<vscode.Uri[] | undefined> {
|
||||
return await vscode.window.showOpenDialog(
|
||||
{
|
||||
|
||||
@@ -6,12 +6,12 @@
|
||||
import path = require('path');
|
||||
import * as vscode from 'vscode';
|
||||
import * as constants from '../common/constants';
|
||||
import { getSqlProjectsInWorkspace, validateSqlCmdVariableName } from '../common/utils';
|
||||
import { getSqlProjectsInWorkspace, getSystemDatabase, validateSqlCmdVariableName } from '../common/utils';
|
||||
import { DbServerValues, populateResultWithVars } from './utils';
|
||||
import { AddDatabaseReferenceSettings } from '../controllers/projectController';
|
||||
import { IDacpacReferenceSettings, IProjectReferenceSettings, ISystemDatabaseReferenceSettings } from '../models/IDatabaseReferenceSettings';
|
||||
import { Project } from '../models/project';
|
||||
import { getSystemDatabase, getSystemDbOptions, promptDacpacLocation } from './addDatabaseReferenceDialog';
|
||||
import { getSystemDbOptions, promptDacpacLocation } from './addDatabaseReferenceDialog';
|
||||
import { TelemetryActions, TelemetryReporter, TelemetryViews } from '../common/telemetry';
|
||||
|
||||
|
||||
|
||||
@@ -3,8 +3,8 @@
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import { SystemDatabase } from 'mssql';
|
||||
import { Uri } from 'vscode';
|
||||
import { SystemDatabase } from '../common/typeHelper';
|
||||
|
||||
export interface IDatabaseReferenceSettings {
|
||||
databaseVariableLiteralValue?: string;
|
||||
|
||||
@@ -9,6 +9,7 @@ import * as utils from '../common/utils';
|
||||
import type * as azdataType from 'azdata';
|
||||
import * as vscode from 'vscode';
|
||||
import * as mssql from 'mssql';
|
||||
import * as vscodeMssql from 'vscode-mssql';
|
||||
|
||||
import { promises as fs } from 'fs';
|
||||
import { Uri, window } from 'vscode';
|
||||
@@ -20,7 +21,8 @@ import { DacpacReferenceProjectEntry, FileProjectEntry, NugetPackageReferencePro
|
||||
import { ResultStatus } from 'azdata';
|
||||
import { BaseProjectTreeItem } from './tree/baseTreeItem';
|
||||
import { NoneNode, PostDeployNode, PreDeployNode, PublishProfileNode, SqlObjectFileNode } from './tree/fileFolderTreeItem';
|
||||
import { GetFoldersResult, GetScriptsResult, ProjectType, SystemDatabase } from 'mssql';
|
||||
import { ProjectType, GetScriptsResult, GetFoldersResult } from '../common/typeHelper';
|
||||
|
||||
|
||||
/**
|
||||
* Represents the configuration based on the Configuration property in the sqlproj
|
||||
@@ -35,7 +37,7 @@ enum Configuration {
|
||||
* Class representing a Project, and providing functions for operating on it
|
||||
*/
|
||||
export class Project implements ISqlProject {
|
||||
private sqlProjService!: mssql.ISqlProjectsService;
|
||||
private sqlProjService!: utils.ISqlProjectsService;
|
||||
|
||||
private _projectFilePath: string;
|
||||
private _projectFileName: string;
|
||||
@@ -48,7 +50,7 @@ export class Project implements ISqlProject {
|
||||
private _preDeployScripts: FileProjectEntry[] = [];
|
||||
private _postDeployScripts: FileProjectEntry[] = [];
|
||||
private _noneDeployScripts: FileProjectEntry[] = [];
|
||||
private _sqlProjStyle: ProjectType = ProjectType.SdkStyle;
|
||||
private _sqlProjStyle: ProjectType;
|
||||
private _isCrossPlatformCompatible: boolean = false;
|
||||
private _outputPath: string = '';
|
||||
private _configuration: Configuration = Configuration.Debug;
|
||||
@@ -118,7 +120,11 @@ export class Project implements ISqlProject {
|
||||
}
|
||||
|
||||
public get sqlProjStyleName(): string {
|
||||
return this.sqlProjStyle === ProjectType.SdkStyle ? 'SdkStyle' : 'LegacyStyle';
|
||||
if (utils.getAzdataApi()) {
|
||||
return this.sqlProjStyle === mssql.ProjectType.SdkStyle ? 'SdkStyle' : 'LegacyStyle';
|
||||
} else {
|
||||
return this.sqlProjStyle === vscodeMssql.ProjectType.SdkStyle ? 'SdkStyle' : 'LegacyStyle';
|
||||
}
|
||||
}
|
||||
|
||||
public get isCrossPlatformCompatible(): boolean {
|
||||
@@ -142,6 +148,12 @@ export class Project implements ISqlProject {
|
||||
constructor(projectFilePath: string) {
|
||||
this._projectFilePath = projectFilePath;
|
||||
this._projectFileName = path.basename(projectFilePath, '.sqlproj');
|
||||
if (utils.getAzdataApi()) {
|
||||
this._sqlProjStyle = mssql.ProjectType.SdkStyle;
|
||||
} else {
|
||||
this._sqlProjStyle = vscodeMssql.ProjectType.SdkStyle
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -228,7 +240,14 @@ export class Project implements ISqlProject {
|
||||
//#region Reader helpers
|
||||
|
||||
private async readProjectProperties(): Promise<void> {
|
||||
const result = await this.sqlProjService.getProjectProperties(this.projectFilePath);
|
||||
let sqlProjService;
|
||||
if (utils.getAzdataApi()) {
|
||||
sqlProjService = this.sqlProjService as mssql.ISqlProjectsService;
|
||||
} else {
|
||||
sqlProjService = this.sqlProjService as vscodeMssql.ISqlProjectsService;
|
||||
}
|
||||
|
||||
const result = await sqlProjService.getProjectProperties(this.projectFilePath);
|
||||
this.throwIfFailed(result);
|
||||
|
||||
this._projectGuid = result.projectGuid;
|
||||
@@ -367,7 +386,14 @@ export class Project implements ISqlProject {
|
||||
}
|
||||
|
||||
private async readNoneItems(): Promise<void> {
|
||||
var result: GetScriptsResult = await this.sqlProjService.getNoneItems(this.projectFilePath);
|
||||
let sqlProjService;
|
||||
if (utils.getAzdataApi()) {
|
||||
sqlProjService = (await utils.getSqlProjectsService()) as mssql.ISqlProjectsService;
|
||||
} else {
|
||||
sqlProjService = (await utils.getSqlProjectsService()) as vscodeMssql.ISqlProjectsService;
|
||||
}
|
||||
|
||||
var result: GetScriptsResult = await sqlProjService.getNoneItems(this.projectFilePath);
|
||||
this.throwIfFailed(result);
|
||||
|
||||
const noneItemEntries: FileProjectEntry[] = [];
|
||||
@@ -423,8 +449,14 @@ export class Project implements ISqlProject {
|
||||
}
|
||||
|
||||
for (const systemDbReference of databaseReferencesResult.systemDatabaseReferences) {
|
||||
let systemDb;
|
||||
if (utils.getAzdataApi()) {
|
||||
systemDb = systemDbReference.systemDb === mssql.SystemDatabase.Master ? constants.master : constants.msdb;
|
||||
} else {
|
||||
systemDb = systemDbReference.systemDb === vscodeMssql.SystemDatabase.Master ? constants.master : constants.msdb;
|
||||
}
|
||||
this._databaseReferences.push(new SystemDatabaseReferenceProjectEntry(
|
||||
systemDbReference.systemDb === SystemDatabase.Master ? constants.master : constants.msdb,
|
||||
systemDb,
|
||||
systemDbReference.databaseVariableLiteralName,
|
||||
systemDbReference.suppressMissingDependencies));
|
||||
}
|
||||
@@ -769,8 +801,18 @@ export class Project implements ISqlProject {
|
||||
throw new Error(constants.databaseReferenceAlreadyExists);
|
||||
}
|
||||
|
||||
const systemDb = <unknown>settings.systemDb as SystemDatabase;
|
||||
const result = await this.sqlProjService.addSystemDatabaseReference(this.projectFilePath, systemDb, settings.suppressMissingDependenciesErrors, settings.databaseVariableLiteralValue);
|
||||
let systemDb;
|
||||
let result;
|
||||
let sqlProjService;
|
||||
if (utils.getAzdataApi()) {
|
||||
systemDb = <unknown>settings.systemDb as mssql.SystemDatabase;
|
||||
sqlProjService = this.sqlProjService as mssql.ISqlProjectsService;
|
||||
result = await sqlProjService.addSystemDatabaseReference(this.projectFilePath, systemDb, settings.suppressMissingDependenciesErrors, settings.databaseVariableLiteralValue);
|
||||
} else {
|
||||
systemDb = <unknown>settings.systemDb as vscodeMssql.SystemDatabase;
|
||||
sqlProjService = this.sqlProjService as vscodeMssql.ISqlProjectsService;
|
||||
result = await sqlProjService.addSystemDatabaseReference(this.projectFilePath, systemDb, settings.suppressMissingDependenciesErrors, settings.databaseVariableLiteralValue);
|
||||
}
|
||||
|
||||
if (!result.success && result.errorMessage) {
|
||||
throw new Error(constants.errorAddingDatabaseReference(utils.systemDatabaseToString(settings.systemDb), result.errorMessage));
|
||||
|
||||
@@ -9,6 +9,8 @@ import { BaseProjectTreeItem } from './baseTreeItem';
|
||||
import * as fileTree from './fileFolderTreeItem';
|
||||
import { Project } from '../project';
|
||||
import * as utils from '../../common/utils';
|
||||
import * as mssql from 'mssql';
|
||||
import * as vscodeMssql from 'vscode-mssql';
|
||||
import { DatabaseReferencesTreeItem } from './databaseReferencesTreeItem';
|
||||
import { DatabaseProjectItemType, RelativeOuterPath, ExternalStreamingJob, sqlprojExtension, CollapseProjectNodesKey, errorPrefix } from '../../common/constants';
|
||||
import { IconPathHelper } from '../../common/iconHelper';
|
||||
@@ -16,7 +18,6 @@ import { FileProjectEntry } from '../projectEntry';
|
||||
import { EntryType } from 'sqldbproj';
|
||||
import { DBProjectConfigurationKey } from '../../tools/netcoreTool';
|
||||
import { SqlCmdVariablesTreeItem } from './sqlcmdVariableTreeItem';
|
||||
import { ProjectType } from 'mssql';
|
||||
|
||||
/**
|
||||
* TreeNode root that represents an entire project
|
||||
@@ -60,7 +61,13 @@ export class ProjectRootTreeItem extends BaseProjectTreeItem {
|
||||
}
|
||||
|
||||
public get type(): DatabaseProjectItemType {
|
||||
return this.project.sqlProjStyle === ProjectType.SdkStyle ? DatabaseProjectItemType.project : DatabaseProjectItemType.legacyProject;
|
||||
let projectType;
|
||||
if (utils.getAzdataApi()) {
|
||||
projectType = this.project.sqlProjStyle === mssql.ProjectType.SdkStyle ? DatabaseProjectItemType.project : DatabaseProjectItemType.legacyProject;
|
||||
} else {
|
||||
projectType = this.project.sqlProjStyle === vscodeMssql.ProjectType.SdkStyle ? DatabaseProjectItemType.project : DatabaseProjectItemType.legacyProject;
|
||||
}
|
||||
return projectType;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -13,8 +13,9 @@ import should = require('should');
|
||||
import { AssertionError } from 'assert';
|
||||
import { Project } from '../models/project';
|
||||
import { Uri } from 'vscode';
|
||||
import { exists, getSqlProjectsService } from '../common/utils';
|
||||
import { ProjectType } from 'mssql';
|
||||
import { exists, getAzdataApi, getSqlProjectsService } from '../common/utils';
|
||||
import * as mssql from 'mssql';
|
||||
import * as vscodeMssql from 'vscode-mssql';
|
||||
|
||||
export async function shouldThrowSpecificError(block: Function, expectedMessage: string, details?: string) {
|
||||
let succeeded = false;
|
||||
@@ -33,7 +34,7 @@ export async function shouldThrowSpecificError(block: Function, expectedMessage:
|
||||
|
||||
export async function createTestSqlProject(test: Mocha.Runnable | undefined): Promise<Project> {
|
||||
const projPath = await getTestProjectPath(test);
|
||||
await (await getSqlProjectsService()).createProject(projPath, ProjectType.SdkStyle);
|
||||
await (await getSqlProjectsService() as mssql.ISqlProjectsService).createProject(projPath, mssql.ProjectType.SdkStyle);
|
||||
return await Project.openProject(projPath);
|
||||
}
|
||||
|
||||
|
||||
@@ -12,7 +12,9 @@ import * as extractZip from 'extract-zip';
|
||||
import * as constants from '../common/constants';
|
||||
import { HttpClient } from '../common/httpClient';
|
||||
import { DBProjectConfigurationKey } from './netcoreTool';
|
||||
import { ProjectType } from 'mssql';
|
||||
import { ProjectType } from '../common/typeHelper';
|
||||
import * as mssql from 'mssql';
|
||||
import * as vscodeMssql from 'vscode-mssql';
|
||||
|
||||
const buildDirectory = 'BuildDirectory';
|
||||
const sdkName = 'Microsoft.Build.Sql';
|
||||
@@ -136,10 +138,18 @@ export class BuildHelper {
|
||||
// Right now SystemDacpacsLocation and NETCoreTargetsPath get set to the same thing, but separating them out for if we move
|
||||
// the system dacpacs somewhere else and also so that the variable name makes more sense if building from the commandline,
|
||||
// since SDK style projects don't to specify the targets path, just where the system dacpacs are
|
||||
if (sqlProjStyle === ProjectType.SdkStyle) {
|
||||
return ` build ${projectPath} /p:NetCoreBuild=true /p:SystemDacpacsLocation=${buildDirPath}`;
|
||||
if (utils.getAzdataApi()) {
|
||||
if (sqlProjStyle === mssql.ProjectType.SdkStyle) {
|
||||
return ` build ${projectPath} /p:NetCoreBuild=true /p:SystemDacpacsLocation=${buildDirPath}`;
|
||||
} else {
|
||||
return ` build ${projectPath} /p:NetCoreBuild=true /p:NETCoreTargetsPath=${buildDirPath} /p:SystemDacpacsLocation=${buildDirPath}`;
|
||||
}
|
||||
} else {
|
||||
return ` build ${projectPath} /p:NetCoreBuild=true /p:NETCoreTargetsPath=${buildDirPath} /p:SystemDacpacsLocation=${buildDirPath}`;
|
||||
if (sqlProjStyle === vscodeMssql.ProjectType.SdkStyle) {
|
||||
return ` build ${projectPath} /p:NetCoreBuild=true /p:SystemDacpacsLocation=${buildDirPath}`;
|
||||
} else {
|
||||
return ` build ${projectPath} /p:NetCoreBuild=true /p:NETCoreTargetsPath=${buildDirPath} /p:SystemDacpacsLocation=${buildDirPath}`;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user