diff --git a/extensions/sql-database-projects/src/controllers/projectController.ts b/extensions/sql-database-projects/src/controllers/projectController.ts index c9c018a297..896bc1eedb 100644 --- a/extensions/sql-database-projects/src/controllers/projectController.ts +++ b/extensions/sql-database-projects/src/controllers/projectController.ts @@ -17,7 +17,7 @@ import type * as mssqlVscode from 'vscode-mssql'; import { promises as fs } from 'fs'; import { PublishDatabaseDialog } from '../dialogs/publishDatabaseDialog'; -import { Project, reservedProjectFolders, FileProjectEntry, SqlProjectReferenceProjectEntry, IDatabaseReferenceProjectEntry } from '../models/project'; +import { Project, reservedProjectFolders } from '../models/project'; import { SqlDatabaseProjectTreeViewProvider } from './databaseProjectTreeViewProvider'; import { FolderNode, FileNode } from '../models/tree/fileFolderTreeItem'; import { IDeploySettings } from '../models/IDeploySettings'; @@ -42,6 +42,7 @@ import { SqlTargetPlatform } from 'sqldbproj'; import { AutorestHelper } from '../tools/autorestHelper'; import { createNewProjectFromDatabaseWithQuickpick } from '../dialogs/createProjectFromDatabaseQuickpick'; import { addDatabaseReferenceQuickpick } from '../dialogs/addDatabaseReferenceQuickpick'; +import { FileProjectEntry, IDatabaseReferenceProjectEntry, SqlProjectReferenceProjectEntry } from '../models/projectEntry'; const maxTableLength = 10; diff --git a/extensions/sql-database-projects/src/dialogs/addDatabaseReferenceDialog.ts b/extensions/sql-database-projects/src/dialogs/addDatabaseReferenceDialog.ts index 4e8896b37c..23ecc6e3e7 100644 --- a/extensions/sql-database-projects/src/dialogs/addDatabaseReferenceDialog.ts +++ b/extensions/sql-database-projects/src/dialogs/addDatabaseReferenceDialog.ts @@ -9,12 +9,13 @@ import * as path from 'path'; import * as constants from '../common/constants'; import * as utils from '../common/utils'; -import { Project, SystemDatabase } from '../models/project'; +import { Project } from '../models/project'; import { cssStyles } from '../common/uiConstants'; import { IconPathHelper } from '../common/iconHelper'; import { ISystemDatabaseReferenceSettings, IDacpacReferenceSettings, IProjectReferenceSettings } from '../models/IDatabaseReferenceSettings'; import { Deferred } from '../common/promise'; import { TelemetryActions, TelemetryReporter, TelemetryViews } from '../common/telemetry'; +import { SystemDatabase } from '../models/projectEntry'; export enum ReferenceType { project, diff --git a/extensions/sql-database-projects/src/models/IDatabaseReferenceSettings.ts b/extensions/sql-database-projects/src/models/IDatabaseReferenceSettings.ts index f2207a8c37..7263fd3996 100644 --- a/extensions/sql-database-projects/src/models/IDatabaseReferenceSettings.ts +++ b/extensions/sql-database-projects/src/models/IDatabaseReferenceSettings.ts @@ -3,8 +3,8 @@ * Licensed under the Source EULA. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ -import { SystemDatabase } from './project'; import { Uri } from 'vscode'; +import { SystemDatabase } from './projectEntry'; export interface IDatabaseReferenceSettings { databaseName?: string; diff --git a/extensions/sql-database-projects/src/models/project.ts b/extensions/sql-database-projects/src/models/project.ts index b0e5aa4847..685eee67e5 100644 --- a/extensions/sql-database-projects/src/models/project.ts +++ b/extensions/sql-database-projects/src/models/project.ts @@ -12,11 +12,12 @@ import * as os from 'os'; import * as templates from '../templates/templates'; import { Uri, window } from 'vscode'; -import { IFileProjectEntry, ISqlProject, SqlTargetPlatform } from 'sqldbproj'; +import { ISqlProject, SqlTargetPlatform } from 'sqldbproj'; import { promises as fs } from 'fs'; import { DataSource } from './dataSources/dataSources'; import { ISystemDatabaseReferenceSettings, IDacpacReferenceSettings, IProjectReferenceSettings } from './IDatabaseReferenceSettings'; import { TelemetryActions, TelemetryReporter, TelemetryViews } from '../common/telemetry'; +import { DacpacReferenceProjectEntry, EntryType, FileProjectEntry, IDatabaseReferenceProjectEntry, ProjectEntry, SqlCmdVariableProjectEntry, SqlProjectReferenceProjectEntry, SystemDatabase, SystemDatabaseReferenceProjectEntry } from './projectEntry'; /** * Class representing a Project, and providing functions for operating on it @@ -1293,155 +1294,4 @@ export class Project implements ISqlProject { } } -/** - * Represents an entry in a project file - */ -export abstract class ProjectEntry { - type: EntryType; - - constructor(type: EntryType) { - this.type = type; - } -} - -export class FileProjectEntry extends ProjectEntry implements IFileProjectEntry { - /** - * Absolute file system URI - */ - fsUri: Uri; - relativePath: string; - sqlObjectType: string | undefined; - - constructor(uri: Uri, relativePath: string, entryType: EntryType, sqlObjectType?: string) { - super(entryType); - this.fsUri = uri; - this.relativePath = relativePath; - this.sqlObjectType = sqlObjectType; - } - - public override toString(): string { - return this.fsUri.path; - } - - public pathForSqlProj(): string { - return utils.convertSlashesForSqlProj(this.fsUri.fsPath); - } -} - -/** - * Represents a database reference entry in a project file - */ - -export interface IDatabaseReferenceProjectEntry extends FileProjectEntry { - databaseName: string; - databaseVariableLiteralValue?: string; - suppressMissingDependenciesErrors: boolean; -} - -export class DacpacReferenceProjectEntry extends FileProjectEntry implements IDatabaseReferenceProjectEntry { - databaseVariableLiteralValue?: string; - databaseSqlCmdVariable?: string; - serverName?: string; - serverSqlCmdVariable?: string; - suppressMissingDependenciesErrors: boolean; - - constructor(settings: IDacpacReferenceSettings) { - super(settings.dacpacFileLocation, '', EntryType.DatabaseReference); - this.databaseSqlCmdVariable = settings.databaseVariable; - this.databaseVariableLiteralValue = settings.databaseName; - this.serverName = settings.serverName; - this.serverSqlCmdVariable = settings.serverVariable; - this.suppressMissingDependenciesErrors = settings.suppressMissingDependenciesErrors; - } - - /** - * File name that gets displayed in the project tree - */ - public get databaseName(): string { - return path.parse(utils.getPlatformSafeFileEntryPath(this.fsUri.fsPath)).name; - } - - public override pathForSqlProj(): string { - // need to remove the leading slash from path for build to work - return utils.convertSlashesForSqlProj(this.fsUri.path.substring(1)); - } -} - -export class SystemDatabaseReferenceProjectEntry extends FileProjectEntry implements IDatabaseReferenceProjectEntry { - constructor(uri: Uri, public ssdtUri: Uri, public databaseVariableLiteralValue: string | undefined, public suppressMissingDependenciesErrors: boolean) { - super(uri, '', EntryType.DatabaseReference); - } - - /** - * File name that gets displayed in the project tree - */ - public get databaseName(): string { - return path.parse(utils.getPlatformSafeFileEntryPath(this.fsUri.fsPath)).name; - } - - public override pathForSqlProj(): string { - // need to remove the leading slash for system database path for build to work on Windows - return utils.convertSlashesForSqlProj(this.fsUri.path.substring(1)); - } - - public ssdtPathForSqlProj(): string { - // need to remove the leading slash for system database path for build to work on Windows - return utils.convertSlashesForSqlProj(this.ssdtUri.path.substring(1)); - } -} - -export class SqlProjectReferenceProjectEntry extends FileProjectEntry implements IDatabaseReferenceProjectEntry { - projectName: string; - projectGuid: string; - databaseVariableLiteralValue?: string; - databaseSqlCmdVariable?: string; - serverName?: string; - serverSqlCmdVariable?: string; - suppressMissingDependenciesErrors: boolean; - - constructor(settings: IProjectReferenceSettings) { - super(settings.projectRelativePath!, '', EntryType.DatabaseReference); - this.projectName = settings.projectName; - this.projectGuid = settings.projectGuid; - this.databaseSqlCmdVariable = settings.databaseVariable; - this.databaseVariableLiteralValue = settings.databaseName; - this.serverName = settings.serverName; - this.serverSqlCmdVariable = settings.serverVariable; - this.suppressMissingDependenciesErrors = settings.suppressMissingDependenciesErrors; - } - - public get databaseName(): string { - return this.projectName; - } - - public override pathForSqlProj(): string { - // need to remove the leading slash from path for build to work on Windows - return utils.convertSlashesForSqlProj(this.fsUri.path.substring(1)); - } -} - -export class SqlCmdVariableProjectEntry extends ProjectEntry { - constructor(public variableName: string, public defaultValue: string) { - super(EntryType.SqlCmdVariable); - } -} - -export enum EntryType { - File, - Folder, - DatabaseReference, - SqlCmdVariable -} - -export enum DatabaseReferenceLocation { - sameDatabase, - differentDatabaseSameServer, - differentDatabaseDifferentServer -} - -export enum SystemDatabase { - master, - msdb -} - export const reservedProjectFolders = ['Properties', 'Data Sources', 'Database References']; diff --git a/extensions/sql-database-projects/src/models/projectEntry.ts b/extensions/sql-database-projects/src/models/projectEntry.ts new file mode 100644 index 0000000000..4ca70a1ff8 --- /dev/null +++ b/extensions/sql-database-projects/src/models/projectEntry.ts @@ -0,0 +1,161 @@ +/*--------------------------------------------------------------------------------------------- + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the Source EULA. See License.txt in the project root for license information. + *--------------------------------------------------------------------------------------------*/ + +import * as path from 'path'; +import * as utils from '../common/utils'; +import { IDacpacReferenceSettings, IProjectReferenceSettings } from './IDatabaseReferenceSettings'; +import { IFileProjectEntry } from 'sqldbproj'; +import { Uri } from 'vscode'; + +/** + * Represents an entry in a project file + */ +export abstract class ProjectEntry { + type: EntryType; + + constructor(type: EntryType) { + this.type = type; + } +} + +export class FileProjectEntry extends ProjectEntry implements IFileProjectEntry { + /** + * Absolute file system URI + */ + fsUri: Uri; + relativePath: string; + sqlObjectType: string | undefined; + + constructor(uri: Uri, relativePath: string, entryType: EntryType, sqlObjectType?: string) { + super(entryType); + this.fsUri = uri; + this.relativePath = relativePath; + this.sqlObjectType = sqlObjectType; + } + + public override toString(): string { + return this.fsUri.path; + } + + public pathForSqlProj(): string { + return utils.convertSlashesForSqlProj(this.fsUri.fsPath); + } +} + +/** + * Represents a database reference entry in a project file + */ + +export interface IDatabaseReferenceProjectEntry extends FileProjectEntry { + databaseName: string; + databaseVariableLiteralValue?: string; + suppressMissingDependenciesErrors: boolean; +} + +export class DacpacReferenceProjectEntry extends FileProjectEntry implements IDatabaseReferenceProjectEntry { + databaseVariableLiteralValue?: string; + databaseSqlCmdVariable?: string; + serverName?: string; + serverSqlCmdVariable?: string; + suppressMissingDependenciesErrors: boolean; + + constructor(settings: IDacpacReferenceSettings) { + super(settings.dacpacFileLocation, '', EntryType.DatabaseReference); + this.databaseSqlCmdVariable = settings.databaseVariable; + this.databaseVariableLiteralValue = settings.databaseName; + this.serverName = settings.serverName; + this.serverSqlCmdVariable = settings.serverVariable; + this.suppressMissingDependenciesErrors = settings.suppressMissingDependenciesErrors; + } + + /** + * File name that gets displayed in the project tree + */ + public get databaseName(): string { + return path.parse(utils.getPlatformSafeFileEntryPath(this.fsUri.fsPath)).name; + } + + public override pathForSqlProj(): string { + // need to remove the leading slash from path for build to work + return utils.convertSlashesForSqlProj(this.fsUri.path.substring(1)); + } +} + +export class SystemDatabaseReferenceProjectEntry extends FileProjectEntry implements IDatabaseReferenceProjectEntry { + constructor(uri: Uri, public ssdtUri: Uri, public databaseVariableLiteralValue: string | undefined, public suppressMissingDependenciesErrors: boolean) { + super(uri, '', EntryType.DatabaseReference); + } + + /** + * File name that gets displayed in the project tree + */ + public get databaseName(): string { + return path.parse(utils.getPlatformSafeFileEntryPath(this.fsUri.fsPath)).name; + } + + public override pathForSqlProj(): string { + // need to remove the leading slash for system database path for build to work on Windows + return utils.convertSlashesForSqlProj(this.fsUri.path.substring(1)); + } + + public ssdtPathForSqlProj(): string { + // need to remove the leading slash for system database path for build to work on Windows + return utils.convertSlashesForSqlProj(this.ssdtUri.path.substring(1)); + } +} + +export class SqlProjectReferenceProjectEntry extends FileProjectEntry implements IDatabaseReferenceProjectEntry { + projectName: string; + projectGuid: string; + databaseVariableLiteralValue?: string; + databaseSqlCmdVariable?: string; + serverName?: string; + serverSqlCmdVariable?: string; + suppressMissingDependenciesErrors: boolean; + + constructor(settings: IProjectReferenceSettings) { + super(settings.projectRelativePath!, '', EntryType.DatabaseReference); + this.projectName = settings.projectName; + this.projectGuid = settings.projectGuid; + this.databaseSqlCmdVariable = settings.databaseVariable; + this.databaseVariableLiteralValue = settings.databaseName; + this.serverName = settings.serverName; + this.serverSqlCmdVariable = settings.serverVariable; + this.suppressMissingDependenciesErrors = settings.suppressMissingDependenciesErrors; + } + + public get databaseName(): string { + return this.projectName; + } + + public override pathForSqlProj(): string { + // need to remove the leading slash from path for build to work on Windows + return utils.convertSlashesForSqlProj(this.fsUri.path.substring(1)); + } +} + +export class SqlCmdVariableProjectEntry extends ProjectEntry { + constructor(public variableName: string, public defaultValue: string) { + super(EntryType.SqlCmdVariable); + } +} + +export enum EntryType { + File, + Folder, + DatabaseReference, + SqlCmdVariable +} + +export enum DatabaseReferenceLocation { + sameDatabase, + differentDatabaseSameServer, + differentDatabaseDifferentServer +} + +export enum SystemDatabase { + master, + msdb +} diff --git a/extensions/sql-database-projects/src/models/tree/databaseReferencesTreeItem.ts b/extensions/sql-database-projects/src/models/tree/databaseReferencesTreeItem.ts index d81abd4c68..e0ee8f9141 100644 --- a/extensions/sql-database-projects/src/models/tree/databaseReferencesTreeItem.ts +++ b/extensions/sql-database-projects/src/models/tree/databaseReferencesTreeItem.ts @@ -10,7 +10,7 @@ import * as constants from '../../common/constants'; import { BaseProjectTreeItem } from './baseTreeItem'; import { ProjectRootTreeItem } from './projectTreeItem'; import { IconPathHelper } from '../../common/iconHelper'; -import { IDatabaseReferenceProjectEntry } from '../../models/project'; +import { IDatabaseReferenceProjectEntry } from '../projectEntry'; /** * Folder for containing references nodes in the tree diff --git a/extensions/sql-database-projects/src/models/tree/projectTreeItem.ts b/extensions/sql-database-projects/src/models/tree/projectTreeItem.ts index 76269eade5..d9013f6f72 100644 --- a/extensions/sql-database-projects/src/models/tree/projectTreeItem.ts +++ b/extensions/sql-database-projects/src/models/tree/projectTreeItem.ts @@ -8,11 +8,12 @@ import * as path from 'path'; import { DataSourcesTreeItem } from './dataSourceTreeItem'; import { BaseProjectTreeItem } from './baseTreeItem'; import * as fileTree from './fileFolderTreeItem'; -import { Project, EntryType, FileProjectEntry } from '../project'; +import { Project } from '../project'; import * as utils from '../../common/utils'; import { DatabaseReferencesTreeItem } from './databaseReferencesTreeItem'; import { DatabaseProjectItemType, RelativeOuterPath, ExternalStreamingJob, sqlprojExtension } from '../../common/constants'; import { IconPathHelper } from '../../common/iconHelper'; +import { EntryType, FileProjectEntry } from '../projectEntry'; /** * TreeNode root that represents an entire project diff --git a/extensions/sql-database-projects/src/test/project.test.ts b/extensions/sql-database-projects/src/test/project.test.ts index b64c299584..2ba63fd292 100644 --- a/extensions/sql-database-projects/src/test/project.test.ts +++ b/extensions/sql-database-projects/src/test/project.test.ts @@ -12,11 +12,12 @@ import * as testUtils from './testUtils'; import * as constants from '../common/constants'; import { promises as fs } from 'fs'; -import { Project, EntryType, SystemDatabase, SystemDatabaseReferenceProjectEntry, SqlProjectReferenceProjectEntry } from '../models/project'; +import { Project } from '../models/project'; import { exists, convertSlashesForSqlProj } from '../common/utils'; import { Uri, window } from 'vscode'; import { IDacpacReferenceSettings, IProjectReferenceSettings, ISystemDatabaseReferenceSettings } from '../models/IDatabaseReferenceSettings'; import { SqlTargetPlatform } from 'sqldbproj'; +import { EntryType, SystemDatabaseReferenceProjectEntry, SqlProjectReferenceProjectEntry, SystemDatabase } from '../models/projectEntry'; let projFilePath: string; diff --git a/extensions/sql-database-projects/src/test/projectController.test.ts b/extensions/sql-database-projects/src/test/projectController.test.ts index a9e65aa3a9..61b68670b7 100644 --- a/extensions/sql-database-projects/src/test/projectController.test.ts +++ b/extensions/sql-database-projects/src/test/projectController.test.ts @@ -21,7 +21,7 @@ import { SqlDatabaseProjectTreeViewProvider } from '../controllers/databaseProje import { ProjectsController } from '../controllers/projectController'; import { promises as fs } from 'fs'; import { createContext, TestContext, mockDacFxResult, mockConnectionProfile } from './testContext'; -import { Project, reservedProjectFolders, SystemDatabase, FileProjectEntry, SystemDatabaseReferenceProjectEntry, EntryType } from '../models/project'; +import { Project, reservedProjectFolders } from '../models/project'; import { PublishDatabaseDialog } from '../dialogs/publishDatabaseDialog'; import { ProjectRootTreeItem } from '../models/tree/projectTreeItem'; import { FolderNode, FileNode } from '../models/tree/fileFolderTreeItem'; @@ -31,6 +31,7 @@ import { IDacpacReferenceSettings } from '../models/IDatabaseReferenceSettings'; import { CreateProjectFromDatabaseDialog } from '../dialogs/createProjectFromDatabaseDialog'; import { ImportDataModel } from '../models/api/import'; import { SqlTargetPlatform } from 'sqldbproj'; +import { SystemDatabaseReferenceProjectEntry, SystemDatabase, EntryType, FileProjectEntry } from '../models/projectEntry'; let testContext: TestContext; diff --git a/extensions/sql-database-projects/src/test/projectTree.test.ts b/extensions/sql-database-projects/src/test/projectTree.test.ts index 119f565eb9..a7cd908195 100644 --- a/extensions/sql-database-projects/src/test/projectTree.test.ts +++ b/extensions/sql-database-projects/src/test/projectTree.test.ts @@ -8,10 +8,11 @@ import * as vscode from 'vscode'; import * as os from 'os'; import * as path from 'path'; -import { Project, EntryType } from '../models/project'; +import { Project } from '../models/project'; import { FolderNode, FileNode, sortFileFolderNodes } from '../models/tree/fileFolderTreeItem'; import { ProjectRootTreeItem } from '../models/tree/projectTreeItem'; import { DatabaseProjectItemType } from '../common/constants'; +import { EntryType } from '../models/projectEntry'; describe('Project Tree tests', function (): void { it('Should correctly order tree nodes by type, then by name', function (): void {