mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-01-16 09:35:36 -05:00
Data workspace projects changes (#13466)
* Fix project context menu actions (#12541) * delete works again * make fewer changes * update all sql db project commands * cleanup * Remove old projects view (#12563) * remove old projects view from file explorer view * fix tests failing * remove projects in open folder opening up in old view * Update db reference dialog to show projects in the workspace (#12580) * update database reference dialog to show projects in the workspace in the project dropdown * remove workspace stuff from sql projects extension * undo change * add class that implements IExtension * undo a change * update DataWorkspaceExtension to take workspaceService as a parameter * add type * Update sql database project commands (#12595) * remove sql proj's open and create new project from comman palette * hook up create project from database to data workspace * rename the remaining import databases to create project from database * remove open, new, and close commands * expose addProjectsToWorkspace() in IExtension instead of calling command * Addressing comments * fix failing sql project tests (#12651) * update SSDT projects opened in projects viewlet (#12669) * fix action not refreshing the tree issue (#12692) * fix adding project references in new projects viewlet (#12688) * Remove old projects tree provider (#12702) * Remove old projects tree provider and fix tests * formatting * update refreshProjectsTree() to accept workspaceTreeItem() * Cleanup ProjectsController (#12718) * remove openProject from ProjectController and some cleanup * rename * add project and open project dialogs (#12729) * empty dialogs * wip * new project dialog implementation * revert gitattributes * open project dialog * implement add project * remove icon helper * refactor * revert script change * adjust views * more updates * make data-workspace a builtin extension * show the view only when project provider is detected (#12819) * only show the view when proj provider is available * update * fix sql project tests after merge (#12793) * Update dialogs to be closer to mockups (#12879) * small UI changes to dialogs * center radio card group text * Create workspace if needed when opening/new project (#12930) * empty dialogs * wip * new project dialog implementation * revert gitattributes * open project dialog * implement add project * remove icon helper * refactor * revert script change * create workspace * initial changes * create new workspace working * fix tests * cleanup * remove showWorkspaceRequiredNotification() * Add test for no workspace open * update blue buttons * move loading temp project to activate() instead of workspaceService constructor * move workspace creation warning message to before project is created * pass uri to createWorkspace * add tests Co-authored-by: Alan Ren <alanren@microsoft.com> * Additional create workspace changes (#13004) * Dialogs workspace updates (#13010) * adding workspace text boxes * match new project dialog to mockups * Add validation error message for workspace file * add enterWorkspace api * add warning message for opening workspace * cleanup * update commands to remove project so they're more generic * remove 'empty' from string * Move default project location setting to data workspace extension (#13022) * remove project location setting and notification from sql database projects extension * add default project location setting to data workspace extension * fix typo * Add back project name incrementing * other merge fixes * fix strings from other PR * default to last opened directory instead of home directory if no specified default location * A few small updates (#13092) * fix build error * update title for inputboxes * add missing file * Add tests for data workspace dialogs (#13324) * add tests for dialogs * create helper functions * New project dialog workspace inputbox fixes (#13407) * workspace inputbox fixes * fix folder icons * Update package.jsons and readme (#13451) * update package.jsons * update readme * add workspace information to open existing dialog (#13455) Co-authored-by: Alan Ren <alanren@microsoft.com>
This commit is contained in:
@@ -23,12 +23,13 @@ export const MicrosoftDatatoolsSchemaSqlSql = 'Microsoft.Data.Tools.Schema.Sql.S
|
||||
export const databaseSchemaProvider = 'DatabaseSchemaProvider';
|
||||
|
||||
// Project Provider
|
||||
export const projectTypeDisplayName = localize('projectTypeDisplayName', 'Database Project');
|
||||
export const sqlDatabaseProjectTypeId = 'sqldbproj';
|
||||
export const projectTypeDisplayName = localize('projectTypeDisplayName', "SQL Database");
|
||||
export const projectTypeDescription = localize('projectTypeDescription', "Design, edit, and publish schemas for SQL databases");
|
||||
|
||||
// commands
|
||||
export const revealFileInOsCommand = 'revealFileInOS';
|
||||
export const schemaCompareStartCommand = 'schemaCompare.start';
|
||||
export const sqlDatabaseProjectsViewFocusCommand = 'sqlDatabaseProjectsView.focus';
|
||||
export const vscodeOpenCommand = 'vscode.open';
|
||||
|
||||
// UI Strings
|
||||
@@ -54,10 +55,6 @@ export const objectType = localize('objectType', "Object Type");
|
||||
export const schema = localize('schema', "Schema");
|
||||
export const schemaObjectType = localize('schemaObjectType', "Schema/Object Type");
|
||||
export const defaultProjectNameStarter = localize('defaultProjectNameStarter', "DatabaseProject");
|
||||
export const newDefaultProjectSaveLocation = localize('newDefaultProjectSaveLocation', "Would you like to update the default location to save new database projects?");
|
||||
export const invalidDefaultProjectSaveLocation = localize('invalidDefaultProjectSaveLocation', "Default location to save new database projects is invalid. Would you like to update it?");
|
||||
export const openWorkspaceSettings = localize('openWorkspaceSettings', "Yes, open Settings");
|
||||
export const doNotPromptAgain = localize('doNotPromptAgain', "Don't ask again");
|
||||
export const reloadProject = localize('reloadProject', "Would you like to reload your database project?");
|
||||
export function newObjectNamePrompt(objectType: string) { return localize('newObjectNamePrompt', 'New {0} name:', objectType); }
|
||||
export function deleteConfirmation(toDelete: string) { return localize('deleteConfirmation', "Are you sure you want to delete {0}?", toDelete); }
|
||||
@@ -95,7 +92,7 @@ export const defaultUser = localize('default', "default");
|
||||
export const addDatabaseReferenceDialogName = localize('addDatabaseReferencedialogName', "Add database reference");
|
||||
export const addDatabaseReferenceOkButtonText = localize('addDatabaseReferenceOkButtonText', "Add reference");
|
||||
export const referenceRadioButtonsGroupTitle = localize('referenceRadioButtonsGroupTitle', "Type");
|
||||
export const projectRadioButtonTitle = localize('projectRadioButtonTitle', "Database project in folder");
|
||||
export const projectRadioButtonTitle = localize('projectRadioButtonTitle', "Project");
|
||||
export const systemDatabaseRadioButtonTitle = localize('systemDatabaseRadioButtonTitle', "System database");
|
||||
export const dacpacText = localize('dacpacText', "Data-tier application (.dacpac)");
|
||||
export const dacpacPlaceholder = localize('dacpacPlaceholder', "Select .dacpac");
|
||||
@@ -259,11 +256,6 @@ export const activeDirectoryInteractive = 'active directory interactive';
|
||||
export const userIdSetting = 'User ID';
|
||||
export const passwordSetting = 'Password';
|
||||
|
||||
// Workspace settings for saving new database projects
|
||||
export const dbProjectConfigurationKey = 'sqlDatabaseProjects';
|
||||
export const projectSaveLocationKey = 'defaultProjectSaveLocation';
|
||||
export const showUpdatePromptKey = 'showUpdateSaveLocationPrompt';
|
||||
|
||||
// Authentication types
|
||||
export const integratedAuth = 'Integrated';
|
||||
export const azureMfaAuth = 'AzureMFA';
|
||||
|
||||
@@ -13,6 +13,7 @@ export interface IconPath {
|
||||
export class IconPathHelper {
|
||||
private static extensionContext: vscode.ExtensionContext;
|
||||
public static databaseProject: IconPath;
|
||||
public static colorfulSqlProject: IconPath;
|
||||
|
||||
public static dataSourceGroup: IconPath;
|
||||
public static dataSourceSql: IconPath;
|
||||
@@ -31,6 +32,7 @@ export class IconPathHelper {
|
||||
IconPathHelper.extensionContext = extensionContext;
|
||||
|
||||
IconPathHelper.databaseProject = IconPathHelper.makeIcon('databaseProject');
|
||||
IconPathHelper.colorfulSqlProject = IconPathHelper.makeIcon('colorfulSqlProject', true);
|
||||
|
||||
IconPathHelper.dataSourceGroup = IconPathHelper.makeIcon('dataSourceGroup');
|
||||
IconPathHelper.dataSourceSql = IconPathHelper.makeIcon('dataSource-sql');
|
||||
|
||||
@@ -8,6 +8,7 @@ import * as os from 'os';
|
||||
import * as constants from './constants';
|
||||
import * as path from 'path';
|
||||
import * as glob from 'fast-glob';
|
||||
import * as dataworkspace from 'dataworkspace';
|
||||
import * as mssql from '../../../mssql';
|
||||
import { promises as fs } from 'fs';
|
||||
|
||||
@@ -217,7 +218,7 @@ export function isValidSqlCmdVariableName(name: string | undefined): boolean {
|
||||
return true;
|
||||
}
|
||||
|
||||
/*
|
||||
/**
|
||||
* Recursively gets all the sqlproj files at any depth in a folder
|
||||
* @param folderPath
|
||||
*/
|
||||
@@ -231,6 +232,19 @@ export async function getSqlProjectFilesInFolder(folderPath: string): Promise<st
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all the projects in the workspace that are sqlproj
|
||||
*/
|
||||
export function getSqlProjectsInWorkspace(): vscode.Uri[] {
|
||||
const api = getDataWorkspaceExtensionApi();
|
||||
return api.getProjectsInWorkspace().filter((p: vscode.Uri) => path.extname(p.fsPath) === constants.sqlprojExtension);
|
||||
}
|
||||
|
||||
export function getDataWorkspaceExtensionApi(): dataworkspace.IExtension {
|
||||
const extension = vscode.extensions.getExtension(dataworkspace.extension.name)!;
|
||||
return extension.exports;
|
||||
}
|
||||
|
||||
/*
|
||||
* Returns the default deployment options from DacFx
|
||||
*/
|
||||
export async function GetDefaultDeploymentOptions(): Promise<mssql.DeploymentOptions> {
|
||||
|
||||
@@ -28,6 +28,10 @@ export class SqlDatabaseProjectTreeViewProvider implements vscode.TreeDataProvid
|
||||
this.roots = [];
|
||||
}
|
||||
|
||||
public notifyTreeDataChanged() {
|
||||
this._onDidChangeTreeData.fire(undefined);
|
||||
}
|
||||
|
||||
public getTreeItem(element: BaseProjectTreeItem): vscode.TreeItem {
|
||||
return element.treeItem;
|
||||
}
|
||||
|
||||
@@ -6,33 +6,23 @@
|
||||
import * as azdata from 'azdata';
|
||||
import * as vscode from 'vscode';
|
||||
import * as templates from '../templates/templates';
|
||||
import * as constants from '../common/constants';
|
||||
import * as path from 'path';
|
||||
import * as newProjectTool from '../tools/newProjectTool';
|
||||
|
||||
import { SqlDatabaseProjectTreeViewProvider } from './databaseProjectTreeViewProvider';
|
||||
import { getErrorMessage, getSqlProjectFilesInFolder } from '../common/utils';
|
||||
import { ProjectsController } from './projectController';
|
||||
import { BaseProjectTreeItem } from '../models/tree/baseTreeItem';
|
||||
import { NetCoreTool } from '../tools/netcoreTool';
|
||||
import { Project } from '../models/project';
|
||||
import { ExternalStreamingJobFileNode, FileNode, FolderNode } from '../models/tree/fileFolderTreeItem';
|
||||
import { IconPathHelper } from '../common/iconHelper';
|
||||
import { IProjectProvider } from 'dataworkspace';
|
||||
import { IProjectProvider, WorkspaceTreeItem } from 'dataworkspace';
|
||||
import { SqlDatabaseProjectProvider } from '../projectProvider/projectProvider';
|
||||
|
||||
const SQL_DATABASE_PROJECTS_VIEW_ID = 'sqlDatabaseProjectsView';
|
||||
|
||||
/**
|
||||
* The main controller class that initializes the extension
|
||||
*/
|
||||
export default class MainController implements vscode.Disposable {
|
||||
protected dbProjectTreeViewProvider: SqlDatabaseProjectTreeViewProvider = new SqlDatabaseProjectTreeViewProvider();
|
||||
protected projectsController: ProjectsController;
|
||||
protected netcoreTool: NetCoreTool;
|
||||
|
||||
public constructor(private context: vscode.ExtensionContext) {
|
||||
this.projectsController = new ProjectsController(this.dbProjectTreeViewProvider);
|
||||
this.projectsController = new ProjectsController();
|
||||
this.netcoreTool = new NetCoreTool();
|
||||
}
|
||||
|
||||
@@ -49,147 +39,42 @@ export default class MainController implements vscode.Disposable {
|
||||
|
||||
public async activate(): Promise<IProjectProvider> {
|
||||
await this.initializeDatabaseProjects();
|
||||
return new SqlDatabaseProjectProvider();
|
||||
return new SqlDatabaseProjectProvider(this.projectsController);
|
||||
}
|
||||
|
||||
private async initializeDatabaseProjects(): Promise<void> {
|
||||
// init commands
|
||||
vscode.commands.registerCommand('sqlDatabaseProjects.new', async () => { await this.createNewProject(); });
|
||||
vscode.commands.registerCommand('sqlDatabaseProjects.open', async () => { await this.openProjectFromFile(); });
|
||||
vscode.commands.registerCommand('sqlDatabaseProjects.close', (node: BaseProjectTreeItem) => { this.projectsController.closeProject(node); });
|
||||
vscode.commands.registerCommand('sqlDatabaseProjects.properties', async (node: BaseProjectTreeItem) => { await vscode.window.showErrorMessage(`Properties not yet implemented: ${node.uri.path}`); }); // TODO
|
||||
vscode.commands.registerCommand('sqlDatabaseProjects.properties', async (node: WorkspaceTreeItem) => { await vscode.window.showErrorMessage(`Properties not yet implemented: ${node.element.uri.path}`); }); // TODO
|
||||
|
||||
vscode.commands.registerCommand('sqlDatabaseProjects.build', async (node: BaseProjectTreeItem) => { await this.projectsController.buildProject(node); });
|
||||
vscode.commands.registerCommand('sqlDatabaseProjects.publish', async (node: BaseProjectTreeItem) => { await this.projectsController.publishProject(node); });
|
||||
vscode.commands.registerCommand('sqlDatabaseProjects.schemaCompare', async (node: BaseProjectTreeItem) => { await this.projectsController.schemaCompare(node); });
|
||||
vscode.commands.registerCommand('sqlDatabaseProjects.importDatabase', async (profile: azdata.IConnectionProfile) => { await this.projectsController.importNewDatabaseProject(profile); });
|
||||
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.newScript', async (node: BaseProjectTreeItem) => { await this.projectsController.addItemPromptFromNode(node, templates.script); });
|
||||
vscode.commands.registerCommand('sqlDatabaseProjects.newPreDeploymentScript', async (node: BaseProjectTreeItem) => { await this.projectsController.addItemPromptFromNode(node, templates.preDeployScript); });
|
||||
vscode.commands.registerCommand('sqlDatabaseProjects.newPostDeploymentScript', async (node: BaseProjectTreeItem) => { await this.projectsController.addItemPromptFromNode(node, templates.postDeployScript); });
|
||||
vscode.commands.registerCommand('sqlDatabaseProjects.newTable', async (node: BaseProjectTreeItem) => { await this.projectsController.addItemPromptFromNode(node, templates.table); });
|
||||
vscode.commands.registerCommand('sqlDatabaseProjects.newView', async (node: BaseProjectTreeItem) => { await this.projectsController.addItemPromptFromNode(node, templates.view); });
|
||||
vscode.commands.registerCommand('sqlDatabaseProjects.newStoredProcedure', async (node: BaseProjectTreeItem) => { await this.projectsController.addItemPromptFromNode(node, templates.storedProcedure); });
|
||||
vscode.commands.registerCommand('sqlDatabaseProjects.newExternalStreamingJob', async (node: BaseProjectTreeItem) => { await this.projectsController.addItemPromptFromNode(node, templates.externalStreamingJob); });
|
||||
vscode.commands.registerCommand('sqlDatabaseProjects.newItem', async (node: BaseProjectTreeItem) => { await this.projectsController.addItemPromptFromNode(node); });
|
||||
vscode.commands.registerCommand('sqlDatabaseProjects.newFolder', async (node: BaseProjectTreeItem) => { await this.projectsController.addFolderPrompt(node); });
|
||||
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); });
|
||||
vscode.commands.registerCommand('sqlDatabaseProjects.newPostDeploymentScript', async (node: WorkspaceTreeItem) => { await this.projectsController.addItemPromptFromNode(node, templates.postDeployScript); });
|
||||
vscode.commands.registerCommand('sqlDatabaseProjects.newTable', async (node: WorkspaceTreeItem) => { await this.projectsController.addItemPromptFromNode(node, templates.table); });
|
||||
vscode.commands.registerCommand('sqlDatabaseProjects.newView', async (node: WorkspaceTreeItem) => { await this.projectsController.addItemPromptFromNode(node, templates.view); });
|
||||
vscode.commands.registerCommand('sqlDatabaseProjects.newStoredProcedure', async (node: WorkspaceTreeItem) => { await this.projectsController.addItemPromptFromNode(node, templates.storedProcedure); });
|
||||
vscode.commands.registerCommand('sqlDatabaseProjects.newExternalStreamingJob', async (node: WorkspaceTreeItem) => { await this.projectsController.addItemPromptFromNode(node, templates.externalStreamingJob); });
|
||||
vscode.commands.registerCommand('sqlDatabaseProjects.newItem', async (node: WorkspaceTreeItem) => { await this.projectsController.addItemPromptFromNode(node); });
|
||||
vscode.commands.registerCommand('sqlDatabaseProjects.newFolder', async (node: WorkspaceTreeItem) => { await this.projectsController.addFolderPrompt(node); });
|
||||
|
||||
vscode.commands.registerCommand('sqlDatabaseProjects.addDatabaseReference', async (node: BaseProjectTreeItem) => { await this.projectsController.addDatabaseReference(node); });
|
||||
vscode.commands.registerCommand('sqlDatabaseProjects.openContainingFolder', async (node: BaseProjectTreeItem) => { await this.projectsController.openContainingFolder(node); });
|
||||
vscode.commands.registerCommand('sqlDatabaseProjects.editProjectFile', async (node: BaseProjectTreeItem) => { await this.projectsController.editProjectFile(node); });
|
||||
vscode.commands.registerCommand('sqlDatabaseProjects.delete', async (node: BaseProjectTreeItem) => { await this.projectsController.delete(node); });
|
||||
vscode.commands.registerCommand('sqlDatabaseProjects.exclude', async (node: FileNode | FolderNode) => { await this.projectsController.exclude(node); });
|
||||
vscode.commands.registerCommand('sqlDatabaseProjects.changeTargetPlatform', async (node: BaseProjectTreeItem) => { await this.projectsController.changeTargetPlatform(node); });
|
||||
vscode.commands.registerCommand('sqlDatabaseProjects.validateExternalStreamingJob', async (node: ExternalStreamingJobFileNode) => { await this.projectsController.validateExternalStreamingJob(node); });
|
||||
vscode.commands.registerCommand('sqlDatabaseProjects.addDatabaseReference', async (node: WorkspaceTreeItem) => { await this.projectsController.addDatabaseReference(node); });
|
||||
vscode.commands.registerCommand('sqlDatabaseProjects.openContainingFolder', async (node: WorkspaceTreeItem) => { await this.projectsController.openContainingFolder(node); });
|
||||
vscode.commands.registerCommand('sqlDatabaseProjects.editProjectFile', async (node: WorkspaceTreeItem) => { await this.projectsController.editProjectFile(node); });
|
||||
vscode.commands.registerCommand('sqlDatabaseProjects.delete', async (node: WorkspaceTreeItem) => { await this.projectsController.delete(node); });
|
||||
vscode.commands.registerCommand('sqlDatabaseProjects.exclude', async (node: WorkspaceTreeItem) => { await this.projectsController.exclude(node); });
|
||||
vscode.commands.registerCommand('sqlDatabaseProjects.changeTargetPlatform', async (node: WorkspaceTreeItem) => { await this.projectsController.changeTargetPlatform(node); });
|
||||
vscode.commands.registerCommand('sqlDatabaseProjects.validateExternalStreamingJob', async (node: WorkspaceTreeItem) => { await this.projectsController.validateExternalStreamingJob(node); });
|
||||
|
||||
IconPathHelper.setExtensionContext(this.extensionContext);
|
||||
|
||||
// init view
|
||||
const treeView = vscode.window.createTreeView(SQL_DATABASE_PROJECTS_VIEW_ID, {
|
||||
treeDataProvider: this.dbProjectTreeViewProvider,
|
||||
showCollapseAll: true
|
||||
});
|
||||
this.dbProjectTreeViewProvider.setTreeView(treeView);
|
||||
|
||||
this.extensionContext.subscriptions.push(treeView);
|
||||
|
||||
await templates.loadTemplates(path.join(this.context.extensionPath, 'resources', 'templates'));
|
||||
|
||||
// ensure .net core is installed
|
||||
await this.netcoreTool.findOrInstallNetCore();
|
||||
|
||||
// set the user settings around saving new projects to default value
|
||||
await newProjectTool.initializeSaveLocationSetting();
|
||||
|
||||
// load any sql projects that are open in workspace folder
|
||||
await this.loadProjectsInWorkspace();
|
||||
}
|
||||
|
||||
public async loadProjectsInWorkspace(): Promise<void> {
|
||||
const workspaceFolders = vscode.workspace.workspaceFolders;
|
||||
if (workspaceFolders?.length) {
|
||||
await Promise.all(workspaceFolders.map(async (workspaceFolder) => {
|
||||
await this.loadProjectsInFolder(workspaceFolder.uri.fsPath);
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
public async loadProjectsInFolder(folderPath: string): Promise<void> {
|
||||
const results = await getSqlProjectFilesInFolder(folderPath);
|
||||
|
||||
for (let f in results) {
|
||||
// open the project, but don't switch focus to the file explorer viewlet
|
||||
await this.projectsController.openProject(vscode.Uri.file(results[f]), false);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Prompts the user to select a .sqlproj file to open
|
||||
* TODO: define behavior once projects are automatically opened from workspace
|
||||
*/
|
||||
public async openProjectFromFile(): Promise<void> {
|
||||
try {
|
||||
let filter: { [key: string]: string[] } = {};
|
||||
|
||||
filter[constants.sqlDatabaseProject] = ['sqlproj'];
|
||||
|
||||
let files: vscode.Uri[] | undefined = await vscode.window.showOpenDialog({ filters: filter });
|
||||
|
||||
if (files) {
|
||||
for (const file of files) {
|
||||
await this.projectsController.openProject(file);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (err) {
|
||||
vscode.window.showErrorMessage(getErrorMessage(err));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new SQL database project from a template, prompting the user for a name and location
|
||||
*/
|
||||
public async createNewProject(): Promise<Project | undefined> {
|
||||
try {
|
||||
let newProjName = await vscode.window.showInputBox({
|
||||
prompt: constants.newDatabaseProjectName,
|
||||
value: newProjectTool.defaultProjectNameNewProj()
|
||||
});
|
||||
|
||||
newProjName = newProjName?.trim();
|
||||
|
||||
if (!newProjName) {
|
||||
// TODO: is this case considered an intentional cancellation (shouldn't warn) or an error case (should warn)?
|
||||
vscode.window.showErrorMessage(constants.projectNameRequired);
|
||||
return undefined;
|
||||
}
|
||||
|
||||
let selectionResult = await vscode.window.showOpenDialog({
|
||||
canSelectFiles: false,
|
||||
canSelectFolders: true,
|
||||
canSelectMany: false,
|
||||
defaultUri: newProjectTool.defaultProjectSaveLocation()
|
||||
});
|
||||
|
||||
if (!selectionResult) {
|
||||
vscode.window.showErrorMessage(constants.projectLocationRequired);
|
||||
return undefined;
|
||||
}
|
||||
|
||||
// TODO: what if the selected folder is outside the workspace?
|
||||
|
||||
const newProjFolderUri = (selectionResult as vscode.Uri[])[0];
|
||||
const newProjFilePath = await this.projectsController.createNewProject(<string>newProjName, newProjFolderUri, true);
|
||||
const proj = await this.projectsController.openProject(vscode.Uri.file(newProjFilePath));
|
||||
|
||||
newProjectTool.updateSaveLocationSetting();
|
||||
|
||||
return proj;
|
||||
}
|
||||
catch (err) {
|
||||
vscode.window.showErrorMessage(getErrorMessage(err));
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
|
||||
public dispose(): void {
|
||||
|
||||
@@ -4,7 +4,6 @@
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import * as constants from '../common/constants';
|
||||
import * as dataSources from '../models/dataSources/dataSources';
|
||||
import * as mssql from '../../../mssql';
|
||||
import * as os from 'os';
|
||||
import * as path from 'path';
|
||||
@@ -14,12 +13,13 @@ import * as templates from '../templates/templates';
|
||||
import * as newProjectTool from '../tools/newProjectTool';
|
||||
import * as vscode from 'vscode';
|
||||
import * as azdata from 'azdata';
|
||||
import * as dataworkspace from 'dataworkspace';
|
||||
|
||||
import { promises as fs } from 'fs';
|
||||
import { PublishDatabaseDialog } from '../dialogs/publishDatabaseDialog';
|
||||
import { Project, reservedProjectFolders, FileProjectEntry, SqlProjectReferenceProjectEntry, IDatabaseReferenceProjectEntry } from '../models/project';
|
||||
import { SqlDatabaseProjectTreeViewProvider } from './databaseProjectTreeViewProvider';
|
||||
import { FolderNode, FileNode, ExternalStreamingJobFileNode } from '../models/tree/fileFolderTreeItem';
|
||||
import { FolderNode, FileNode } from '../models/tree/fileFolderTreeItem';
|
||||
import { IPublishSettings, IGenerateScriptSettings } from '../models/IPublishSettings';
|
||||
import { BaseProjectTreeItem } from '../models/tree/baseTreeItem';
|
||||
import { ProjectRootTreeItem } from '../models/tree/projectTreeItem';
|
||||
@@ -30,97 +30,24 @@ import { PublishProfile, load } from '../models/publishProfile/publishProfile';
|
||||
import { AddDatabaseReferenceDialog } from '../dialogs/addDatabaseReferenceDialog';
|
||||
import { ISystemDatabaseReferenceSettings, IDacpacReferenceSettings, IProjectReferenceSettings } from '../models/IDatabaseReferenceSettings';
|
||||
import { DatabaseReferenceTreeItem } from '../models/tree/databaseReferencesTreeItem';
|
||||
import { WorkspaceTreeItem } from 'dataworkspace';
|
||||
|
||||
/**
|
||||
* Controller for managing project lifecycle
|
||||
*/
|
||||
export class ProjectsController {
|
||||
private projectTreeViewProvider: SqlDatabaseProjectTreeViewProvider;
|
||||
private netCoreTool: NetCoreTool;
|
||||
private buildHelper: BuildHelper;
|
||||
|
||||
projects: Project[] = [];
|
||||
projFileWatchers = new Map<string, vscode.FileSystemWatcher>();
|
||||
|
||||
constructor(projTreeViewProvider: SqlDatabaseProjectTreeViewProvider) {
|
||||
this.projectTreeViewProvider = projTreeViewProvider;
|
||||
constructor() {
|
||||
this.netCoreTool = new NetCoreTool();
|
||||
this.buildHelper = new BuildHelper();
|
||||
}
|
||||
|
||||
public refreshProjectsTree() {
|
||||
this.projectTreeViewProvider.load(this.projects);
|
||||
}
|
||||
|
||||
public async openProject(projectFile: vscode.Uri, focusProject: boolean = true, isReferencedProject: boolean = false): Promise<Project> {
|
||||
for (const proj of this.projects) {
|
||||
if (proj.projectFilePath === projectFile.fsPath) {
|
||||
if (!isReferencedProject) {
|
||||
vscode.window.showInformationMessage(constants.projectAlreadyOpened(projectFile.fsPath));
|
||||
return proj;
|
||||
} else {
|
||||
throw new Error(constants.projectAlreadyOpened(projectFile.fsPath));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let newProject: Project;
|
||||
|
||||
try {
|
||||
// Read project file
|
||||
newProject = await Project.openProject(projectFile.fsPath);
|
||||
this.projects.push(newProject);
|
||||
|
||||
// open any reference projects (don't need to worry about circular dependencies because those aren't allowed)
|
||||
const referencedProjects = newProject.databaseReferences.filter(r => r instanceof SqlProjectReferenceProjectEntry);
|
||||
for (const proj of referencedProjects) {
|
||||
const projUri = vscode.Uri.file(path.join(newProject.projectFolderPath, proj.fsUri.fsPath));
|
||||
try {
|
||||
await this.openProject(projUri, false, true);
|
||||
} catch (e) {
|
||||
}
|
||||
}
|
||||
|
||||
// Update for round tripping as needed
|
||||
await this.updateProjectForRoundTrip(newProject);
|
||||
|
||||
// Read datasources.json (if present)
|
||||
const dataSourcesFilePath = path.join(path.dirname(projectFile.fsPath), constants.dataSourcesFileName);
|
||||
|
||||
try {
|
||||
newProject.dataSources = await dataSources.load(dataSourcesFilePath);
|
||||
}
|
||||
catch (err) {
|
||||
if (err instanceof dataSources.NoDataSourcesFileError) {
|
||||
// TODO: prompt to create new datasources.json; for now, swallow
|
||||
}
|
||||
else {
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
|
||||
this.refreshProjectsTree();
|
||||
|
||||
if (focusProject) {
|
||||
await this.focusProject(newProject);
|
||||
}
|
||||
}
|
||||
catch (err) {
|
||||
// if the project didnt load - remove it from the list of open projects
|
||||
this.projects = this.projects.filter((e) => { return e !== newProject; });
|
||||
|
||||
throw err;
|
||||
}
|
||||
|
||||
return newProject!;
|
||||
}
|
||||
|
||||
public async focusProject(project?: Project): Promise<void> {
|
||||
if (project && this.projects.includes(project)) {
|
||||
await this.projectTreeViewProvider.focus(project);
|
||||
await vscode.commands.executeCommand(constants.sqlDatabaseProjectsViewFocusCommand);
|
||||
}
|
||||
public refreshProjectsTree(workspaceTreeItem: dataworkspace.WorkspaceTreeItem): void {
|
||||
(workspaceTreeItem.treeDataProvider as SqlDatabaseProjectTreeViewProvider).notifyTreeDataChanged();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -166,31 +93,19 @@ export class ProjectsController {
|
||||
return newProjFilePath;
|
||||
}
|
||||
|
||||
public closeProject(treeNode: BaseProjectTreeItem) {
|
||||
const project = this.getProjectFromContext(treeNode);
|
||||
this.projects = this.projects.filter((e) => { return e !== project; });
|
||||
|
||||
if (this.projFileWatchers.has(project.projectFilePath)) {
|
||||
this.projFileWatchers.get(project.projectFilePath)!.dispose();
|
||||
this.projFileWatchers.delete(project.projectFilePath);
|
||||
}
|
||||
|
||||
this.refreshProjectsTree();
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds a project, producing a dacpac
|
||||
* @param treeNode a treeItem in a project's hierarchy, to be used to obtain a Project
|
||||
* @returns path of the built dacpac
|
||||
*/
|
||||
public async buildProject(treeNode: BaseProjectTreeItem): Promise<string>;
|
||||
public async buildProject(treeNode: dataworkspace.WorkspaceTreeItem): Promise<string>;
|
||||
/**
|
||||
* Builds a project, producing a dacpac
|
||||
* @param project Project to be built
|
||||
* @returns path of the built dacpac
|
||||
*/
|
||||
public async buildProject(project: Project): Promise<string>;
|
||||
public async buildProject(context: Project | BaseProjectTreeItem | WorkspaceTreeItem): Promise<string | undefined> {
|
||||
public async buildProject(context: Project | dataworkspace.WorkspaceTreeItem): Promise<string> {
|
||||
const project: Project = this.getProjectFromContext(context);
|
||||
|
||||
// Check mssql extension for project dlls (tracking issue #10273)
|
||||
@@ -208,7 +123,7 @@ export class ProjectsController {
|
||||
}
|
||||
catch (err) {
|
||||
vscode.window.showErrorMessage(constants.projBuildFailed(utils.getErrorMessage(err)));
|
||||
return undefined;
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
@@ -216,18 +131,18 @@ export class ProjectsController {
|
||||
* Builds and publishes a project
|
||||
* @param treeNode a treeItem in a project's hierarchy, to be used to obtain a Project
|
||||
*/
|
||||
public publishProject(treeNode: BaseProjectTreeItem): PublishDatabaseDialog;
|
||||
public publishProject(treeNode: dataworkspace.WorkspaceTreeItem): PublishDatabaseDialog;
|
||||
/**
|
||||
* Builds and publishes a project
|
||||
* @param project Project to be built and published
|
||||
*/
|
||||
public publishProject(project: Project): PublishDatabaseDialog;
|
||||
public publishProject(context: Project | BaseProjectTreeItem): PublishDatabaseDialog {
|
||||
public publishProject(context: Project | dataworkspace.WorkspaceTreeItem): PublishDatabaseDialog {
|
||||
const project: Project = this.getProjectFromContext(context);
|
||||
let publishDatabaseDialog = this.getPublishDialog(project);
|
||||
|
||||
publishDatabaseDialog.publish = async (proj, prof) => await this.executionCallback(proj, prof);
|
||||
publishDatabaseDialog.generateScript = async (proj, prof) => await this.executionCallback(proj, prof);
|
||||
publishDatabaseDialog.publish = async (proj, prof) => await this.publishProjectCallback(proj, prof);
|
||||
publishDatabaseDialog.generateScript = async (proj, prof) => await this.publishProjectCallback(proj, prof);
|
||||
publishDatabaseDialog.readPublishProfile = async (profileUri) => await this.readPublishProfileCallback(profileUri);
|
||||
|
||||
publishDatabaseDialog.openDialog();
|
||||
@@ -235,7 +150,7 @@ export class ProjectsController {
|
||||
return publishDatabaseDialog;
|
||||
}
|
||||
|
||||
public async executionCallback(project: Project, settings: IPublishSettings | IGenerateScriptSettings): Promise<mssql.DacFxResult | undefined> {
|
||||
public async publishProjectCallback(project: Project, settings: IPublishSettings | IGenerateScriptSettings): Promise<mssql.DacFxResult | undefined> {
|
||||
const dacpacPath = await this.buildProject(project);
|
||||
|
||||
if (!dacpacPath) {
|
||||
@@ -268,7 +183,7 @@ export class ProjectsController {
|
||||
}
|
||||
}
|
||||
|
||||
public async schemaCompare(treeNode: BaseProjectTreeItem): Promise<void> {
|
||||
public async schemaCompare(treeNode: dataworkspace.WorkspaceTreeItem): Promise<void> {
|
||||
// check if schema compare extension is installed
|
||||
if (vscode.extensions.getExtension(constants.schemaCompareExtensionId)) {
|
||||
// build project
|
||||
@@ -285,9 +200,9 @@ export class ProjectsController {
|
||||
}
|
||||
}
|
||||
|
||||
public async addFolderPrompt(treeNode: BaseProjectTreeItem) {
|
||||
public async addFolderPrompt(treeNode: dataworkspace.WorkspaceTreeItem): Promise<void> {
|
||||
const project = this.getProjectFromContext(treeNode);
|
||||
const relativePathToParent = this.getRelativePath(treeNode);
|
||||
const relativePathToParent = this.getRelativePath(treeNode.element);
|
||||
const absolutePathToParent = path.join(project.projectFolderPath, relativePathToParent);
|
||||
const newFolderName = await this.promptForNewObjectName(new templates.ProjectScriptType(templates.folder, constants.folderFriendlyName, ''),
|
||||
project, absolutePathToParent);
|
||||
@@ -308,7 +223,7 @@ export class ProjectsController {
|
||||
}
|
||||
|
||||
await project.addFolderItem(relativeFolderPath);
|
||||
this.refreshProjectsTree();
|
||||
this.refreshProjectsTree(treeNode);
|
||||
} catch (err) {
|
||||
vscode.window.showErrorMessage(utils.getErrorMessage(err));
|
||||
}
|
||||
@@ -320,11 +235,11 @@ export class ProjectsController {
|
||||
return sameName && sameLocation;
|
||||
}
|
||||
|
||||
public async addItemPromptFromNode(treeNode: BaseProjectTreeItem, itemTypeName?: string) {
|
||||
await this.addItemPrompt(this.getProjectFromContext(treeNode), this.getRelativePath(treeNode), itemTypeName);
|
||||
public async addItemPromptFromNode(treeNode: dataworkspace.WorkspaceTreeItem, itemTypeName?: string): Promise<void> {
|
||||
await this.addItemPrompt(this.getProjectFromContext(treeNode), this.getRelativePath(treeNode.element), itemTypeName, treeNode.treeDataProvider as SqlDatabaseProjectTreeViewProvider);
|
||||
}
|
||||
|
||||
public async addItemPrompt(project: Project, relativePath: string, itemTypeName?: string) {
|
||||
public async addItemPrompt(project: Project, relativePath: string, itemTypeName?: string, treeDataProvider?: SqlDatabaseProjectTreeViewProvider): Promise<void> {
|
||||
if (!itemTypeName) {
|
||||
const items: vscode.QuickPickItem[] = [];
|
||||
|
||||
@@ -366,37 +281,38 @@ export class ProjectsController {
|
||||
const newEntry = await project.addScriptItem(relativeFilePath, newFileText, itemType.type);
|
||||
|
||||
await vscode.commands.executeCommand(constants.vscodeOpenCommand, newEntry.fsUri);
|
||||
|
||||
this.refreshProjectsTree();
|
||||
treeDataProvider?.notifyTreeDataChanged();
|
||||
} catch (err) {
|
||||
vscode.window.showErrorMessage(utils.getErrorMessage(err));
|
||||
}
|
||||
}
|
||||
|
||||
public async exclude(context: FileNode | FolderNode): Promise<void> {
|
||||
const project = this.getProjectFromContext(context);
|
||||
public async exclude(context: dataworkspace.WorkspaceTreeItem): Promise<void> {
|
||||
const node = context.element as BaseProjectTreeItem;
|
||||
const project = this.getProjectFromContext(node);
|
||||
|
||||
const fileEntry = this.getFileProjectEntry(project, context);
|
||||
const fileEntry = this.getFileProjectEntry(project, node);
|
||||
|
||||
if (fileEntry) {
|
||||
await project.exclude(fileEntry);
|
||||
} else {
|
||||
vscode.window.showErrorMessage(constants.unableToPerformAction(constants.excludeAction, context.uri.path));
|
||||
vscode.window.showErrorMessage(constants.unableToPerformAction(constants.excludeAction, node.uri.path));
|
||||
}
|
||||
|
||||
this.refreshProjectsTree();
|
||||
this.refreshProjectsTree(context);
|
||||
}
|
||||
|
||||
public async delete(context: BaseProjectTreeItem): Promise<void> {
|
||||
const project = this.getProjectFromContext(context);
|
||||
public async delete(context: dataworkspace.WorkspaceTreeItem): Promise<void> {
|
||||
const node = context.element as BaseProjectTreeItem;
|
||||
const project = this.getProjectFromContext(node);
|
||||
|
||||
let confirmationPrompt;
|
||||
if (context instanceof DatabaseReferenceTreeItem) {
|
||||
confirmationPrompt = constants.deleteReferenceConfirmation(context.friendlyName);
|
||||
} else if (context instanceof FolderNode) {
|
||||
confirmationPrompt = constants.deleteConfirmationContents(context.friendlyName);
|
||||
if (node instanceof DatabaseReferenceTreeItem) {
|
||||
confirmationPrompt = constants.deleteReferenceConfirmation(node.friendlyName);
|
||||
} else if (node instanceof FolderNode) {
|
||||
confirmationPrompt = constants.deleteConfirmationContents(node.friendlyName);
|
||||
} else {
|
||||
confirmationPrompt = constants.deleteConfirmation(context.friendlyName);
|
||||
confirmationPrompt = constants.deleteConfirmation(node.friendlyName);
|
||||
}
|
||||
|
||||
const response = await vscode.window.showWarningMessage(confirmationPrompt, { modal: true }, constants.yesString);
|
||||
@@ -407,15 +323,15 @@ export class ProjectsController {
|
||||
|
||||
let success = false;
|
||||
|
||||
if (context instanceof DatabaseReferenceTreeItem) {
|
||||
const databaseReference = this.getDatabaseReference(project, context);
|
||||
if (node instanceof DatabaseReferenceTreeItem) {
|
||||
const databaseReference = this.getDatabaseReference(project, node);
|
||||
|
||||
if (databaseReference) {
|
||||
await project.deleteDatabaseReference(databaseReference);
|
||||
success = true;
|
||||
}
|
||||
} else if (context instanceof FileNode || FolderNode) {
|
||||
const fileEntry = this.getFileProjectEntry(project, context);
|
||||
} else if (node instanceof FileNode || FolderNode) {
|
||||
const fileEntry = this.getFileProjectEntry(project, node);
|
||||
|
||||
if (fileEntry) {
|
||||
await project.deleteFileFolder(fileEntry);
|
||||
@@ -424,9 +340,9 @@ export class ProjectsController {
|
||||
}
|
||||
|
||||
if (success) {
|
||||
this.refreshProjectsTree();
|
||||
this.refreshProjectsTree(context);
|
||||
} else {
|
||||
vscode.window.showErrorMessage(constants.unableToPerformAction(constants.deleteAction, context.uri.path));
|
||||
vscode.window.showErrorMessage(constants.unableToPerformAction(constants.deleteAction, node.uri.path));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -457,7 +373,7 @@ export class ProjectsController {
|
||||
* Opens the folder containing the project
|
||||
* @param context a treeItem in a project's hierarchy, to be used to obtain a Project
|
||||
*/
|
||||
public async openContainingFolder(context: BaseProjectTreeItem): Promise<void> {
|
||||
public async openContainingFolder(context: dataworkspace.WorkspaceTreeItem): Promise<void> {
|
||||
const project = this.getProjectFromContext(context);
|
||||
await vscode.commands.executeCommand(constants.revealFileInOsCommand, vscode.Uri.file(project.projectFilePath));
|
||||
}
|
||||
@@ -467,7 +383,7 @@ export class ProjectsController {
|
||||
* reload their project.
|
||||
* @param context a treeItem in a project's hierarchy, to be used to obtain a Project
|
||||
*/
|
||||
public async editProjectFile(context: BaseProjectTreeItem): Promise<void> {
|
||||
public async editProjectFile(context: dataworkspace.WorkspaceTreeItem): Promise<void> {
|
||||
const project = this.getProjectFromContext(context);
|
||||
|
||||
try {
|
||||
@@ -475,11 +391,11 @@ export class ProjectsController {
|
||||
const projFileWatcher: vscode.FileSystemWatcher = vscode.workspace.createFileSystemWatcher(project.projectFilePath);
|
||||
this.projFileWatchers.set(project.projectFilePath, projFileWatcher);
|
||||
|
||||
projFileWatcher.onDidChange(async (projectFileUri: vscode.Uri) => {
|
||||
projFileWatcher.onDidChange(async () => {
|
||||
const result = await vscode.window.showInformationMessage(constants.reloadProject, constants.yesString, constants.noString);
|
||||
|
||||
if (result === constants.yesString) {
|
||||
this.reloadProject(projectFileUri);
|
||||
this.reloadProject(context);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -500,12 +416,12 @@ export class ProjectsController {
|
||||
* Reloads the given project. Throws an error if given project is not a valid open project.
|
||||
* @param projectFileUri the uri of the project to be reloaded
|
||||
*/
|
||||
public async reloadProject(projectFileUri: vscode.Uri) {
|
||||
const project = this.projects.find((e) => e.projectFilePath === projectFileUri.fsPath);
|
||||
public async reloadProject(context: dataworkspace.WorkspaceTreeItem): Promise<void> {
|
||||
const project = this.getProjectFromContext(context);
|
||||
if (project) {
|
||||
// won't open any newly referenced projects, but otherwise matches the behavior of reopening the project
|
||||
await project.readProjFile();
|
||||
this.refreshProjectsTree();
|
||||
this.refreshProjectsTree(context);
|
||||
} else {
|
||||
throw new Error(constants.invalidProjectReload);
|
||||
}
|
||||
@@ -515,7 +431,7 @@ export class ProjectsController {
|
||||
* Changes the project's DSP to the selected target platform
|
||||
* @param context a treeItem in a project's hierarchy, to be used to obtain a Project
|
||||
*/
|
||||
public async changeTargetPlatform(context: Project | BaseProjectTreeItem): Promise<void> {
|
||||
public async changeTargetPlatform(context: Project | dataworkspace.WorkspaceTreeItem): Promise<void> {
|
||||
const project = this.getProjectFromContext(context);
|
||||
const selectedTargetPlatform = (await vscode.window.showQuickPick((Array.from(constants.targetPlatformToVersion.keys())).map(version => { return { label: version }; }),
|
||||
{
|
||||
@@ -533,23 +449,24 @@ export class ProjectsController {
|
||||
* Adds a database reference to the project
|
||||
* @param context a treeItem in a project's hierarchy, to be used to obtain a Project
|
||||
*/
|
||||
public async addDatabaseReference(context: Project | BaseProjectTreeItem): Promise<AddDatabaseReferenceDialog> {
|
||||
public async addDatabaseReference(context: Project | dataworkspace.WorkspaceTreeItem): Promise<AddDatabaseReferenceDialog> {
|
||||
const project = this.getProjectFromContext(context);
|
||||
|
||||
const addDatabaseReferenceDialog = this.getAddDatabaseReferenceDialog(project);
|
||||
addDatabaseReferenceDialog.addReference = async (proj, prof) => await this.addDatabaseReferenceCallback(proj, prof);
|
||||
addDatabaseReferenceDialog.addReference = async (proj, prof) => await this.addDatabaseReferenceCallback(proj, prof, context as dataworkspace.WorkspaceTreeItem);
|
||||
|
||||
addDatabaseReferenceDialog.openDialog();
|
||||
|
||||
return addDatabaseReferenceDialog;
|
||||
}
|
||||
|
||||
public async addDatabaseReferenceCallback(project: Project, settings: ISystemDatabaseReferenceSettings | IDacpacReferenceSettings | IProjectReferenceSettings): Promise<void> {
|
||||
public async addDatabaseReferenceCallback(project: Project, settings: ISystemDatabaseReferenceSettings | IDacpacReferenceSettings | IProjectReferenceSettings, context: dataworkspace.WorkspaceTreeItem): Promise<void> {
|
||||
try {
|
||||
if ((<IProjectReferenceSettings>settings).projectName !== undefined) {
|
||||
// get project path and guid
|
||||
const projectReferenceSettings = settings as IProjectReferenceSettings;
|
||||
const referencedProject = this.projects.find(p => p.projectFileName === projectReferenceSettings.projectName);
|
||||
const workspaceProjects = await utils.getSqlProjectsInWorkspace();
|
||||
const referencedProject = await Project.openProject(workspaceProjects.filter(p => path.parse(p.fsPath).name === projectReferenceSettings.projectName)[0].fsPath);
|
||||
const relativePath = path.relative(project.projectFolderPath, referencedProject?.projectFilePath!);
|
||||
projectReferenceSettings.projectRelativePath = vscode.Uri.file(relativePath);
|
||||
projectReferenceSettings.projectGuid = referencedProject?.projectGuid!;
|
||||
@@ -571,23 +488,64 @@ export class ProjectsController {
|
||||
await project.addDatabaseReference(<IDacpacReferenceSettings>settings);
|
||||
}
|
||||
|
||||
this.refreshProjectsTree();
|
||||
this.refreshProjectsTree(context);
|
||||
} catch (err) {
|
||||
vscode.window.showErrorMessage(utils.getErrorMessage(err));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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<void> {
|
||||
|
||||
public async validateExternalStreamingJob(node: ExternalStreamingJobFileNode): Promise<mssql.ValidateStreamingJobResult> {
|
||||
// TODO: Refactor code
|
||||
try {
|
||||
const workspaceApi = utils.getDataWorkspaceExtensionApi();
|
||||
|
||||
const model: ImportDataModel | undefined = await this.getModelFromContext(context);
|
||||
|
||||
if (!model) {
|
||||
return; // cancelled by user
|
||||
}
|
||||
model.projName = await this.getProjectName(model.database);
|
||||
let newProjFolderUri = (await this.getFolderLocation()).fsPath;
|
||||
model.extractTarget = await this.getExtractTarget();
|
||||
model.version = '1.0.0.0';
|
||||
|
||||
const newProjFilePath = await this.createNewProject(model.projName, vscode.Uri.file(newProjFolderUri), true);
|
||||
model.filePath = path.dirname(newProjFilePath);
|
||||
|
||||
if (model.extractTarget === mssql.ExtractTarget.file) {
|
||||
model.filePath = path.join(model.filePath, model.projName + '.sql'); // File extractTarget specifies the exact file rather than the containing folder
|
||||
}
|
||||
|
||||
const project = await Project.openProject(newProjFilePath);
|
||||
await this.createProjectFromDatabaseApiCall(model); // Call ExtractAPI in DacFx Service
|
||||
let fileFolderList: string[] = model.extractTarget === mssql.ExtractTarget.file ? [model.filePath] : await this.generateList(model.filePath); // Create a list of all the files and directories to be added to project
|
||||
|
||||
await project.addToProject(fileFolderList); // Add generated file structure to the project
|
||||
|
||||
// add project to workspace
|
||||
workspaceApi.showProjectsView();
|
||||
await workspaceApi.addProjectsToWorkspace([vscode.Uri.file(newProjFilePath)]);
|
||||
}
|
||||
catch (err) {
|
||||
vscode.window.showErrorMessage(utils.getErrorMessage(err));
|
||||
}
|
||||
}
|
||||
|
||||
public async validateExternalStreamingJob(node: dataworkspace.WorkspaceTreeItem): Promise<mssql.ValidateStreamingJobResult> {
|
||||
const project: Project = this.getProjectFromContext(node);
|
||||
|
||||
let dacpacPath: string = project.dacpacOutputPath;
|
||||
|
||||
if (!await utils.exists(dacpacPath)) {
|
||||
dacpacPath = await this.buildProject(node);
|
||||
dacpacPath = await this.buildProject(project);
|
||||
}
|
||||
|
||||
const streamingJobDefinition: string = (await fs.readFile(node.fileSystemUri.fsPath)).toString();
|
||||
const streamingJobDefinition: string = (await fs.readFile(node.element.fileSystemUri.fsPath)).toString();
|
||||
|
||||
const dacFxService = await this.getDaxFxService();
|
||||
const result: mssql.ValidateStreamingJobResult = await dacFxService.validateStreamingJob(dacpacPath, streamingJobDefinition);
|
||||
@@ -631,9 +589,9 @@ export class ProjectsController {
|
||||
}
|
||||
}
|
||||
|
||||
private getProjectFromContext(context: Project | BaseProjectTreeItem | WorkspaceTreeItem): Project {
|
||||
private getProjectFromContext(context: Project | BaseProjectTreeItem | dataworkspace.WorkspaceTreeItem): Project {
|
||||
if ('element' in context) {
|
||||
return context.element.project;
|
||||
return context.element.root.project;
|
||||
}
|
||||
|
||||
if (context instanceof Project) {
|
||||
@@ -642,8 +600,7 @@ export class ProjectsController {
|
||||
|
||||
if (context.root instanceof ProjectRootTreeItem) {
|
||||
return (<ProjectRootTreeItem>context.root).project;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
throw new Error(constants.unexpectedProjectContext(context.uri.path));
|
||||
}
|
||||
}
|
||||
@@ -692,45 +649,6 @@ export class ProjectsController {
|
||||
return treeNode instanceof FolderNode ? utils.trimUri(treeNode.root.uri, treeNode.uri) : '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Imports a new SQL database project from the existing database,
|
||||
* prompting the user for a name, file path location and extract target
|
||||
*/
|
||||
public async importNewDatabaseProject(context: azdata.IConnectionProfile | any): Promise<void> {
|
||||
|
||||
// TODO: Refactor code
|
||||
try {
|
||||
const model: ImportDataModel | undefined = await this.getModelFromContext(context);
|
||||
|
||||
if (!model) {
|
||||
return; // cancelled by user
|
||||
}
|
||||
model.projName = await this.getProjectName(model.database);
|
||||
let newProjFolderUri = (await this.getFolderLocation()).fsPath;
|
||||
model.extractTarget = await this.getExtractTarget();
|
||||
model.version = '1.0.0.0';
|
||||
|
||||
newProjectTool.updateSaveLocationSetting();
|
||||
|
||||
const newProjFilePath = await this.createNewProject(model.projName, vscode.Uri.file(newProjFolderUri), true);
|
||||
model.filePath = path.dirname(newProjFilePath);
|
||||
|
||||
if (model.extractTarget === mssql.ExtractTarget.file) {
|
||||
model.filePath = path.join(model.filePath, model.projName + '.sql'); // File extractTarget specifies the exact file rather than the containing folder
|
||||
}
|
||||
|
||||
const project = await Project.openProject(newProjFilePath);
|
||||
await this.importApiCall(model); // Call ExtractAPI in DacFx Service
|
||||
let fileFolderList: string[] = model.extractTarget === mssql.ExtractTarget.file ? [model.filePath] : await this.generateList(model.filePath); // Create a list of all the files and directories to be added to project
|
||||
|
||||
await project.addToProject(fileFolderList); // Add generated file structure to the project
|
||||
await this.openProject(vscode.Uri.file(newProjFilePath));
|
||||
}
|
||||
catch (err) {
|
||||
vscode.window.showErrorMessage(utils.getErrorMessage(err));
|
||||
}
|
||||
}
|
||||
|
||||
public async getModelFromContext(context: any): Promise<ImportDataModel | undefined> {
|
||||
let model = <ImportDataModel>{};
|
||||
|
||||
@@ -861,13 +779,13 @@ export class ProjectsController {
|
||||
return projUri;
|
||||
}
|
||||
|
||||
public async importApiCall(model: ImportDataModel): Promise<void> {
|
||||
public async createProjectFromDatabaseApiCall(model: ImportDataModel): Promise<void> {
|
||||
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);
|
||||
|
||||
await service.importDatabaseProject(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, azdata.TaskExecutionMode.execute);
|
||||
|
||||
// TODO: Check for success; throw error
|
||||
}
|
||||
|
||||
@@ -261,26 +261,12 @@ export class AddDatabaseReferenceDialog {
|
||||
this.setDefaultDatabaseValues();
|
||||
});
|
||||
|
||||
// get projects in workspace
|
||||
const workspaceFolders = vscode.workspace.workspaceFolders;
|
||||
if (workspaceFolders?.length) {
|
||||
let projectFiles = await utils.getSqlProjectFilesInFolder(workspaceFolders[0].uri.fsPath);
|
||||
// get projects in workspace and filter to only sql projects
|
||||
let projectFiles: vscode.Uri[] = utils.getSqlProjectsInWorkspace();
|
||||
|
||||
// check if current project is in same open folder (should only be able to add a reference to another project in
|
||||
// the folder if the current project is also in the folder)
|
||||
if (projectFiles.find(p => p === utils.getPlatformSafeFileEntryPath(this.project.projectFilePath))) {
|
||||
// filter out current project
|
||||
projectFiles = projectFiles.filter(p => p !== utils.getPlatformSafeFileEntryPath(this.project.projectFilePath));
|
||||
|
||||
projectFiles.forEach(p => {
|
||||
projectFiles[projectFiles.indexOf(p)] = path.parse(p).name;
|
||||
});
|
||||
|
||||
this.projectDropdown.values = projectFiles;
|
||||
} else {
|
||||
this.projectDropdown.values = [];
|
||||
}
|
||||
}
|
||||
// filter out current project
|
||||
projectFiles = projectFiles.filter(p => p.fsPath !== this.project.projectFilePath);
|
||||
this.projectDropdown.values = projectFiles.map(p => path.parse(p.fsPath).name);
|
||||
|
||||
return {
|
||||
component: this.projectDropdown,
|
||||
|
||||
@@ -510,7 +510,7 @@ export class PublishDatabaseDialog {
|
||||
|
||||
private async updateConnectionComponents(connectionTextboxValue: string, connectionId: string) {
|
||||
this.targetConnectionTextBox!.value = connectionTextboxValue;
|
||||
this.targetConnectionTextBox!.placeHolder = connectionTextboxValue;
|
||||
this.targetConnectionTextBox!.updateProperty('title', connectionTextboxValue);
|
||||
|
||||
// populate database dropdown with the databases for this connection
|
||||
if (connectionId) {
|
||||
@@ -583,7 +583,7 @@ export class PublishDatabaseDialog {
|
||||
|
||||
// show file path in text box and hover text
|
||||
this.loadProfileTextBox!.value = fileUris[0].fsPath;
|
||||
this.loadProfileTextBox!.placeHolder = fileUris[0].fsPath;
|
||||
this.loadProfileTextBox!.updateProperty('title', fileUris[0].fsPath);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@@ -5,7 +5,6 @@
|
||||
|
||||
import { promises as fs } from 'fs';
|
||||
import * as constants from '../../common/constants';
|
||||
import { SqlConnectionDataSource } from './sqlConnectionStringSource';
|
||||
|
||||
/**
|
||||
* Abstract class for a datasource in a project
|
||||
@@ -53,11 +52,11 @@ export async function load(dataSourcesFilePath: string): Promise<DataSource[]> {
|
||||
// TODO: do we have a construct for parsing version numbers?
|
||||
switch (rawJsonContents.version) {
|
||||
case '0.0.0':
|
||||
const dataSources: DataSourceFileJson = rawJsonContents as DataSourceFileJson;
|
||||
// const dataSources: DataSourceFileJson = rawJsonContents as DataSourceFileJson;
|
||||
|
||||
for (const source of dataSources.datasources) {
|
||||
output.push(createDataSource(source));
|
||||
}
|
||||
// for (const source of dataSources.datasources) {
|
||||
// output.push(createDataSource(source));
|
||||
// }
|
||||
|
||||
break;
|
||||
default:
|
||||
@@ -70,11 +69,12 @@ export async function load(dataSourcesFilePath: string): Promise<DataSource[]> {
|
||||
/**
|
||||
* Creates DataSource object from JSON
|
||||
*/
|
||||
function createDataSource(json: DataSourceJson): DataSource {
|
||||
switch (json.type) {
|
||||
case SqlConnectionDataSource.type:
|
||||
return SqlConnectionDataSource.fromJson(json);
|
||||
default:
|
||||
throw new Error(constants.unknownDataSourceType + json.type);
|
||||
}
|
||||
}
|
||||
// Commenting this out because circular dependency with SqlConnectionDataSource was causing extension to not activate
|
||||
// function createDataSource(json: DataSourceJson): DataSource {
|
||||
// switch (json.type) {
|
||||
// case SqlConnectionDataSource.type:
|
||||
// return SqlConnectionDataSource.fromJson(json);
|
||||
// default:
|
||||
// throw new Error(constants.unknownDataSourceType + json.type);
|
||||
// }
|
||||
// }
|
||||
|
||||
@@ -53,6 +53,7 @@ export class Project {
|
||||
public static async openProject(projectFilePath: string): Promise<Project> {
|
||||
const proj = new Project(projectFilePath);
|
||||
await proj.readProjFile();
|
||||
await proj.updateProjectForRoundTrip();
|
||||
|
||||
return proj;
|
||||
}
|
||||
@@ -60,7 +61,7 @@ export class Project {
|
||||
/**
|
||||
* Reads the project setting and contents from the file
|
||||
*/
|
||||
public async readProjFile() {
|
||||
public async readProjFile(): Promise<void> {
|
||||
this.resetProject();
|
||||
|
||||
const projFileText = await fs.readFile(this.projectFilePath);
|
||||
@@ -178,7 +179,7 @@ export class Project {
|
||||
}
|
||||
}
|
||||
|
||||
private resetProject() {
|
||||
private resetProject(): void {
|
||||
this.files = [];
|
||||
this.importedTargets = [];
|
||||
this.databaseReferences = [];
|
||||
@@ -189,11 +190,27 @@ export class Project {
|
||||
this.projFileXmlDoc = undefined;
|
||||
}
|
||||
|
||||
public async updateProjectForRoundTrip() {
|
||||
await fs.copyFile(this.projectFilePath, this.projectFilePath + '_backup');
|
||||
await this.updateImportToSupportRoundTrip();
|
||||
await this.updatePackageReferenceInProjFile();
|
||||
await this.updateAfterCleanTargetInProjFile();
|
||||
public async updateProjectForRoundTrip(): Promise<void> {
|
||||
if (this.importedTargets.includes(constants.NetCoreTargets) && !this.containsSSDTOnlySystemDatabaseReferences()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!this.importedTargets.includes(constants.NetCoreTargets)) {
|
||||
const result = await window.showWarningMessage(constants.updateProjectForRoundTrip, constants.yesString, constants.noString);
|
||||
if (result === constants.yesString) {
|
||||
await fs.copyFile(this.projectFilePath, this.projectFilePath + '_backup');
|
||||
await this.updateImportToSupportRoundTrip();
|
||||
await this.updatePackageReferenceInProjFile();
|
||||
await this.updateAfterCleanTargetInProjFile();
|
||||
await this.updateSystemDatabaseReferencesInProjFile();
|
||||
}
|
||||
} else if (this.containsSSDTOnlySystemDatabaseReferences()) {
|
||||
const result = await window.showWarningMessage(constants.updateProjectDatabaseReferencesForRoundTrip, constants.yesString, constants.noString);
|
||||
if (result === constants.yesString) {
|
||||
await fs.copyFile(this.projectFilePath, this.projectFilePath + '_backup');
|
||||
await this.updateSystemDatabaseReferencesInProjFile();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private async updateImportToSupportRoundTrip(): Promise<void> {
|
||||
@@ -460,7 +477,7 @@ export class Project {
|
||||
* @param name name of the variable
|
||||
* @param defaultValue
|
||||
*/
|
||||
public async addSqlCmdVariable(name: string, defaultValue: string) {
|
||||
public async addSqlCmdVariable(name: string, defaultValue: string): Promise<void> {
|
||||
const sqlCmdVariableEntry = new SqlCmdVariableProjectEntry(name, defaultValue);
|
||||
await this.addToProjFile(sqlCmdVariableEntry);
|
||||
}
|
||||
@@ -851,7 +868,7 @@ export class Project {
|
||||
await this.serializeToProjFile(this.projFileXmlDoc);
|
||||
}
|
||||
|
||||
private async removeFromProjFile(entries: ProjectEntry | ProjectEntry[]) {
|
||||
private async removeFromProjFile(entries: ProjectEntry | ProjectEntry[]): Promise<void> {
|
||||
if (entries instanceof ProjectEntry) {
|
||||
entries = [entries];
|
||||
}
|
||||
@@ -876,7 +893,7 @@ export class Project {
|
||||
await this.serializeToProjFile(this.projFileXmlDoc);
|
||||
}
|
||||
|
||||
private async serializeToProjFile(projFileContents: any) {
|
||||
private async serializeToProjFile(projFileContents: any): Promise<void> {
|
||||
let xml = new xmldom.XMLSerializer().serializeToString(projFileContents);
|
||||
xml = xmlFormat(xml, <any>{ collapseContent: true, indentation: ' ', lineSeparator: os.EOL }); // TODO: replace <any>
|
||||
|
||||
|
||||
@@ -5,14 +5,19 @@
|
||||
|
||||
import * as dataworkspace from 'dataworkspace';
|
||||
import * as vscode from 'vscode';
|
||||
import { sqlprojExtension, projectTypeDisplayName } from '../common/constants';
|
||||
import { sqlprojExtension, projectTypeDisplayName, projectTypeDescription, sqlDatabaseProjectTypeId } from '../common/constants';
|
||||
import { IconPathHelper } from '../common/iconHelper';
|
||||
import { SqlDatabaseProjectTreeViewProvider } from '../controllers/databaseProjectTreeViewProvider';
|
||||
import { ProjectsController } from '../controllers/projectController';
|
||||
import { Project } from '../models/project';
|
||||
import { BaseProjectTreeItem } from '../models/tree/baseTreeItem';
|
||||
|
||||
export class SqlDatabaseProjectProvider implements dataworkspace.IProjectProvider {
|
||||
|
||||
constructor(private projectController: ProjectsController) {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the project tree data provider
|
||||
* @param projectFile The project file Uri
|
||||
@@ -39,9 +44,22 @@ export class SqlDatabaseProjectProvider implements dataworkspace.IProjectProvide
|
||||
*/
|
||||
get supportedProjectTypes(): dataworkspace.IProjectType[] {
|
||||
return [{
|
||||
id: sqlDatabaseProjectTypeId,
|
||||
projectFileExtension: sqlprojExtension.replace(/\./g, ''),
|
||||
displayName: projectTypeDisplayName,
|
||||
icon: IconPathHelper.databaseProject
|
||||
description: projectTypeDescription,
|
||||
icon: IconPathHelper.colorfulSqlProject
|
||||
}];
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a project
|
||||
* @param name name of the project
|
||||
* @param location the parent directory
|
||||
* @returns Uri of the newly created project file
|
||||
*/
|
||||
async createProject(name: string, location: vscode.Uri): Promise<vscode.Uri> {
|
||||
const projectFile = await this.projectController.createNewProject(name, location, true);
|
||||
return vscode.Uri.file(projectFile);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,6 +5,10 @@
|
||||
|
||||
import * as should from 'should';
|
||||
import * as path from 'path';
|
||||
import * as sinon from 'sinon';
|
||||
import * as vscode from 'vscode';
|
||||
import * as TypeMoq from 'typemoq';
|
||||
import * as dataworkspace from 'dataworkspace';
|
||||
import * as baselines from '../baselines/baselines';
|
||||
import * as templates from '../../templates/templates';
|
||||
import * as testUtils from '../testUtils';
|
||||
@@ -17,6 +21,16 @@ describe('Add Database Reference Dialog', () => {
|
||||
await baselines.loadBaselines();
|
||||
});
|
||||
|
||||
beforeEach(function (): void {
|
||||
const dataWorkspaceMock = TypeMoq.Mock.ofType<dataworkspace.IExtension>();
|
||||
dataWorkspaceMock.setup(x => x.getProjectsInWorkspace()).returns(() => []);
|
||||
sinon.stub(vscode.extensions, 'getExtension').returns(<any>{ exports: dataWorkspaceMock.object });
|
||||
});
|
||||
|
||||
afterEach(function (): void {
|
||||
sinon.restore();
|
||||
});
|
||||
|
||||
it('Should open dialog successfully', async function (): Promise<void> {
|
||||
const project = await testUtils.createTestProject(baselines.newProjectFileBaseline);
|
||||
const dialog = new AddDatabaseReferenceDialog(project);
|
||||
|
||||
@@ -14,7 +14,6 @@ import * as TypeMoq from 'typemoq';
|
||||
|
||||
import { PublishDatabaseDialog } from '../../dialogs/publishDatabaseDialog';
|
||||
import { Project } from '../../models/project';
|
||||
import { SqlDatabaseProjectTreeViewProvider } from '../../controllers/databaseProjectTreeViewProvider';
|
||||
import { ProjectsController } from '../../controllers/projectController';
|
||||
import { IPublishSettings, IGenerateScriptSettings } from '../../models/IPublishSettings';
|
||||
|
||||
@@ -25,7 +24,7 @@ describe.skip('Publish Database Dialog', () => {
|
||||
});
|
||||
|
||||
it('Should open dialog successfully ', async function (): Promise<void> {
|
||||
const projController = new ProjectsController(new SqlDatabaseProjectTreeViewProvider());
|
||||
const projController = new ProjectsController();
|
||||
const projFileDir = path.join(os.tmpdir(), `TestProject_${new Date().getTime()}`);
|
||||
|
||||
const projFilePath = await projController.createNewProject('TestProjectName', vscode.Uri.file(projFileDir), true, 'BA5EBA11-C0DE-5EA7-ACED-BABB1E70A575');
|
||||
@@ -36,7 +35,7 @@ describe.skip('Publish Database Dialog', () => {
|
||||
});
|
||||
|
||||
it('Should create default database name correctly ', async function (): Promise<void> {
|
||||
const projController = new ProjectsController(new SqlDatabaseProjectTreeViewProvider());
|
||||
const projController = new ProjectsController();
|
||||
const projFolder = `TestProject_${new Date().getTime()}`;
|
||||
const projFileDir = path.join(os.tmpdir(), projFolder);
|
||||
|
||||
|
||||
@@ -5,15 +5,11 @@
|
||||
|
||||
import * as should from 'should';
|
||||
import * as path from 'path';
|
||||
import * as os from 'os';
|
||||
import * as vscode from 'vscode';
|
||||
import * as sinon from 'sinon';
|
||||
import * as baselines from './baselines/baselines';
|
||||
import * as templates from '../templates/templates';
|
||||
import * as constants from '../common/constants';
|
||||
import { createContext, TestContext } from './testContext';
|
||||
import MainController from '../controllers/mainController';
|
||||
import { generateTestFolderPath, createTestProject } from './testUtils';
|
||||
|
||||
let testContext: TestContext;
|
||||
|
||||
@@ -28,42 +24,6 @@ describe('MainController: main controller operations', function (): void {
|
||||
sinon.restore();
|
||||
});
|
||||
|
||||
it('Should create new project through MainController', async function (): Promise<void> {
|
||||
const projFileDir = path.join(os.tmpdir(), `TestProject_${new Date().getTime()}`);
|
||||
|
||||
sinon.stub(vscode.window, 'showInputBox').resolves('MyProjectName');
|
||||
sinon.stub(vscode.window, 'showOpenDialog').resolves([vscode.Uri.file(projFileDir)]);
|
||||
sinon.replaceGetter(vscode.workspace, 'workspaceFolders', () => undefined);
|
||||
|
||||
const controller = new MainController(testContext.context);
|
||||
const proj = await controller.createNewProject();
|
||||
|
||||
should(proj).not.equal(undefined);
|
||||
});
|
||||
|
||||
it('Should show error when no project name', async function (): Promise<void> {
|
||||
for (const name of ['', ' ', undefined]) {
|
||||
const stub = sinon.stub(vscode.window, 'showInputBox').resolves(name);
|
||||
const spy = sinon.spy(vscode.window, 'showErrorMessage');
|
||||
const controller = new MainController(testContext.context);
|
||||
await controller.createNewProject();
|
||||
should(spy.calledOnce).be.true('showErrorMessage should have been called exactly once');
|
||||
should(spy.calledWith(constants.projectNameRequired)).be.true(`showErrorMessage not called with expected message '${constants.projectNameRequired}' Actual '${spy.getCall(0).args[0]}'`);
|
||||
stub.restore();
|
||||
spy.restore();
|
||||
}
|
||||
});
|
||||
|
||||
it('Should show error when no location name', async function (): Promise<void> {
|
||||
sinon.stub(vscode.window, 'showInputBox').resolves('MyProjectName');
|
||||
sinon.stub(vscode.window, 'showOpenDialog').resolves(undefined);
|
||||
const spy = sinon.spy(vscode.window, 'showErrorMessage');
|
||||
const controller = new MainController(testContext.context);
|
||||
await controller.createNewProject();
|
||||
should(spy.calledOnce).be.true('showErrorMessage should be called exactly once');
|
||||
should(spy.calledWith(constants.projectLocationRequired)).be.true(`showErrorMessage not called with expected message '${constants.projectLocationRequired}' Actual '${spy.getCall(0).args[0]}'`);
|
||||
});
|
||||
|
||||
it('Should create new instance without error', async function (): Promise<void> {
|
||||
should.doesNotThrow(() => new MainController(testContext.context), 'Creating controller should not throw an error');
|
||||
});
|
||||
@@ -75,27 +35,4 @@ describe('MainController: main controller operations', function (): void {
|
||||
should.doesNotThrow(() => controller.activate(), 'activate() should not throw an error');
|
||||
should.doesNotThrow(() => controller.dispose(), 'dispose() should not throw an error');
|
||||
});
|
||||
|
||||
it('Should load projects in workspace', async function (): Promise<void> {
|
||||
const rootFolderPath = await generateTestFolderPath();
|
||||
const project = await createTestProject(baselines.openProjectFileBaseline, rootFolderPath);
|
||||
const nestedFolder = path.join(rootFolderPath, 'nestedProject');
|
||||
const nestedProject = await createTestProject(baselines.openProjectFileBaseline, nestedFolder);
|
||||
|
||||
const workspaceFolder: vscode.WorkspaceFolder = {
|
||||
uri: vscode.Uri.file(rootFolderPath),
|
||||
name: '',
|
||||
index: 0
|
||||
};
|
||||
sinon.replaceGetter(vscode.workspace, 'workspaceFolders', () => [workspaceFolder]);
|
||||
|
||||
const controller = new MainController(testContext.context);
|
||||
should(controller.projController.projects.length).equal(0);
|
||||
|
||||
await controller.loadProjectsInWorkspace();
|
||||
|
||||
should(controller.projController.projects.length).equal(2);
|
||||
should(controller.projController.projects[0].projectFolderPath).equal(project.projectFolderPath);
|
||||
should(controller.projController.projects[1].projectFolderPath).equal(nestedProject.projectFolderPath);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -5,31 +5,41 @@
|
||||
|
||||
import * as vscode from 'vscode';
|
||||
import * as should from 'should';
|
||||
import * as TypeMoq from 'typemoq';
|
||||
import * as sinon from 'sinon';
|
||||
import * as dataworkspace from 'dataworkspace';
|
||||
import * as newProjectTool from '../tools/newProjectTool';
|
||||
import * as constants from '../common/constants';
|
||||
import { generateTestFolderPath, createTestFile } from './testUtils';
|
||||
|
||||
let previousSetting : string;
|
||||
let testFolderPath : string;
|
||||
|
||||
describe('NewProjectTool: New project tool tests', function (): void {
|
||||
const projectConfigurationKey = 'projects';
|
||||
const projectSaveLocationKey= 'defaultProjectSaveLocation';
|
||||
|
||||
beforeEach(async function () {
|
||||
previousSetting = await vscode.workspace.getConfiguration(constants.dbProjectConfigurationKey)[constants.projectSaveLocationKey];
|
||||
previousSetting = await vscode.workspace.getConfiguration(projectConfigurationKey)[projectSaveLocationKey];
|
||||
testFolderPath = await generateTestFolderPath();
|
||||
|
||||
const dataWorkspaceMock = TypeMoq.Mock.ofType<dataworkspace.IExtension>();
|
||||
dataWorkspaceMock.setup(x => x.defaultProjectSaveLocation).returns(() => vscode.Uri.file(testFolderPath));
|
||||
sinon.stub(vscode.extensions, 'getExtension').returns(<any>{ exports: dataWorkspaceMock.object});
|
||||
});
|
||||
|
||||
afterEach(async function () {
|
||||
await vscode.workspace.getConfiguration(constants.dbProjectConfigurationKey).update(constants.projectSaveLocationKey, previousSetting, true);
|
||||
await vscode.workspace.getConfiguration(projectConfigurationKey).update(projectSaveLocationKey, previousSetting, true);
|
||||
sinon.restore();
|
||||
});
|
||||
|
||||
it('Should generate correct default project names', async function (): Promise<void> {
|
||||
await vscode.workspace.getConfiguration(constants.dbProjectConfigurationKey).update(constants.projectSaveLocationKey, testFolderPath, true);
|
||||
await vscode.workspace.getConfiguration(projectConfigurationKey).update(projectSaveLocationKey, testFolderPath, true);
|
||||
should(newProjectTool.defaultProjectNameNewProj()).equal('DatabaseProject1');
|
||||
should(newProjectTool.defaultProjectNameFromDb('master')).equal('DatabaseProjectmaster');
|
||||
});
|
||||
|
||||
it('Should auto-increment default project names for new projects', async function (): Promise<void> {
|
||||
await vscode.workspace.getConfiguration(constants.dbProjectConfigurationKey).update(constants.projectSaveLocationKey, testFolderPath, true);
|
||||
await vscode.workspace.getConfiguration(projectConfigurationKey).update(projectSaveLocationKey, testFolderPath, true);
|
||||
should(newProjectTool.defaultProjectNameNewProj()).equal('DatabaseProject1');
|
||||
|
||||
await createTestFile('', 'DatabaseProject1', testFolderPath);
|
||||
@@ -40,7 +50,7 @@ describe('NewProjectTool: New project tool tests', function (): void {
|
||||
});
|
||||
|
||||
it('Should auto-increment default project names for import projects', async function (): Promise<void> {
|
||||
await vscode.workspace.getConfiguration(constants.dbProjectConfigurationKey).update(constants.projectSaveLocationKey, testFolderPath, true);
|
||||
await vscode.workspace.getConfiguration(projectConfigurationKey).update(projectSaveLocationKey, testFolderPath, true);
|
||||
should(newProjectTool.defaultProjectNameFromDb("master")).equal('DatabaseProjectmaster');
|
||||
|
||||
await createTestFile('', 'DatabaseProjectmaster', testFolderPath);
|
||||
|
||||
@@ -91,6 +91,8 @@ describe('Project: sqlproj content operations', function (): void {
|
||||
should(project.postDeployScripts.find(f => f.type === EntryType.File && f.relativePath === 'Script.PostDeployment1.sql')).not.equal(undefined, 'File Script.PostDeployment1.sql not read');
|
||||
should(project.preDeployScripts.find(f => f.type === EntryType.File && f.relativePath === 'Script.PreDeployment2.sql')).not.equal(undefined, 'File Script.PostDeployment2.sql not read');
|
||||
should(project.noneDeployScripts.find(f => f.type === EntryType.File && f.relativePath === 'Tables\\Script.PostDeployment1.sql')).not.equal(undefined, 'File Tables\\Script.PostDeployment1.sql not read');
|
||||
|
||||
sinon.restore();
|
||||
});
|
||||
|
||||
it('Should add Folder and Build entries to sqlproj', async function (): Promise<void> {
|
||||
@@ -580,43 +582,58 @@ describe('Project: round trip updates', function (): void {
|
||||
});
|
||||
|
||||
it('Should update SSDT project to work in ADS', async function (): Promise<void> {
|
||||
await testUpdateInRoundTrip(baselines.SSDTProjectFileBaseline, baselines.SSDTProjectAfterUpdateBaseline, true, true);
|
||||
await testUpdateInRoundTrip(baselines.SSDTProjectFileBaseline, baselines.SSDTProjectAfterUpdateBaseline);
|
||||
});
|
||||
|
||||
it('Should update SSDT project with new system database references', async function (): Promise<void> {
|
||||
await testUpdateInRoundTrip(baselines.SSDTUpdatedProjectBaseline, baselines.SSDTUpdatedProjectAfterSystemDbUpdateBaseline, false, true);
|
||||
await testUpdateInRoundTrip(baselines.SSDTUpdatedProjectBaseline, baselines.SSDTUpdatedProjectAfterSystemDbUpdateBaseline);
|
||||
});
|
||||
|
||||
it('Should update SSDT project to work in ADS handling pre-exsiting targets', async function (): Promise<void> {
|
||||
await testUpdateInRoundTrip(baselines.SSDTProjectBaselineWithCleanTarget, baselines.SSDTProjectBaselineWithCleanTargetAfterUpdate, true, false);
|
||||
await testUpdateInRoundTrip(baselines.SSDTProjectBaselineWithCleanTarget, baselines.SSDTProjectBaselineWithCleanTargetAfterUpdate);
|
||||
});
|
||||
|
||||
it('Should not update project and no backup file should be created when update to project is rejected', async function (): Promise<void> {
|
||||
sinon.stub(window, 'showWarningMessage').returns(<any>Promise.resolve(constants.noString));
|
||||
// setup test files
|
||||
const folderPath = await testUtils.generateTestFolderPath();
|
||||
const sqlProjPath = await testUtils.createTestSqlProjFile(baselines.SSDTProjectFileBaseline, folderPath);
|
||||
await testUtils.createTestDataSources(baselines.openDataSourcesBaseline, folderPath);
|
||||
|
||||
const project = await Project.openProject(Uri.file(sqlProjPath).fsPath);
|
||||
|
||||
should(await exists(sqlProjPath + '_backup')).equal(false); // backup file should not be generated
|
||||
should(project.importedTargets.length).equal(2); // additional target should not be added by updateProjectForRoundTrip method
|
||||
|
||||
sinon.restore();
|
||||
});
|
||||
|
||||
it('Should not show warning message for non-SSDT projects that have the additional information for Build', async function (): Promise<void> {
|
||||
// setup test files
|
||||
const folderPath = await testUtils.generateTestFolderPath();
|
||||
const sqlProjPath = await testUtils.createTestSqlProjFile(baselines.openProjectFileBaseline, folderPath);
|
||||
await testUtils.createTestDataSources(baselines.openDataSourcesBaseline, folderPath);
|
||||
|
||||
const project = await Project.openProject(Uri.file(sqlProjPath).fsPath); // no error thrown
|
||||
|
||||
should(project.importedTargets.length).equal(3); // additional target should exist by default
|
||||
});
|
||||
});
|
||||
|
||||
async function testUpdateInRoundTrip(fileBeforeupdate: string, fileAfterUpdate: string, testTargets: boolean, testReferences: boolean): Promise<void> {
|
||||
async function testUpdateInRoundTrip(fileBeforeupdate: string, fileAfterUpdate: string): Promise<void> {
|
||||
const stub = sinon.stub(window, 'showWarningMessage').returns(<any>Promise.resolve(constants.yesString));
|
||||
|
||||
projFilePath = await testUtils.createTestSqlProjFile(fileBeforeupdate);
|
||||
const project = await Project.openProject(projFilePath);
|
||||
const project = await Project.openProject(projFilePath); // project gets updated if needed in openProject()
|
||||
|
||||
if (testTargets) {
|
||||
await testUpdateTargetsImportsRoundTrip(project);
|
||||
}
|
||||
|
||||
if (testReferences) {
|
||||
await testAddReferencesInRoundTrip(project);
|
||||
}
|
||||
should(await exists(projFilePath + '_backup')).equal(true, 'Backup file should have been generated before the project was updated');
|
||||
should(project.importedTargets.length).equal(3); // additional target added by updateProjectForRoundTrip method
|
||||
|
||||
let projFileText = (await fs.readFile(projFilePath)).toString();
|
||||
should(projFileText).equal(fileAfterUpdate.trim());
|
||||
|
||||
should(stub.calledOnce).be.true('showWarningMessage should have been called exactly once');
|
||||
sinon.restore();
|
||||
}
|
||||
|
||||
async function testUpdateTargetsImportsRoundTrip(project: Project): Promise<void> {
|
||||
should(project.importedTargets.length).equal(2);
|
||||
await project.updateProjectForRoundTrip();
|
||||
should(await exists(projFilePath + '_backup')).equal(true); // backup file should be generated before the project is updated
|
||||
should(project.importedTargets.length).equal(3); // additional target added by updateProjectForRoundTrip method
|
||||
}
|
||||
|
||||
async function testAddReferencesInRoundTrip(project: Project): Promise<void> {
|
||||
// updating system db refs is separate from updating for roundtrip because new db refs could be added even after project is updated for roundtrip
|
||||
should(project.containsSSDTOnlySystemDatabaseReferences()).equal(true);
|
||||
await project.updateSystemDatabaseReferencesInProjFile();
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@ import * as azdata from 'azdata';
|
||||
import * as vscode from 'vscode';
|
||||
import * as TypeMoq from 'typemoq';
|
||||
import * as sinon from 'sinon';
|
||||
import * as dataworkspace from 'dataworkspace';
|
||||
import * as baselines from './baselines/baselines';
|
||||
import * as templates from '../templates/templates';
|
||||
import * as testUtils from './testUtils';
|
||||
@@ -65,7 +66,7 @@ describe('ProjectsController', function (): void {
|
||||
describe('project controller operations', function (): void {
|
||||
describe('Project file operations and prompting', function (): void {
|
||||
it('Should create new sqlproj file with correct values', async function (): Promise<void> {
|
||||
const projController = new ProjectsController(new SqlDatabaseProjectTreeViewProvider());
|
||||
const projController = new ProjectsController();
|
||||
const projFileDir = path.join(os.tmpdir(), `TestProject_${new Date().getTime()}`);
|
||||
|
||||
const projFilePath = await projController.createNewProject('TestProjectName', vscode.Uri.file(projFileDir), false, 'BA5EBA11-C0DE-5EA7-ACED-BABB1E70A575');
|
||||
@@ -75,54 +76,11 @@ describe('ProjectsController', function (): void {
|
||||
should(projFileText).equal(baselines.newProjectFileBaseline);
|
||||
});
|
||||
|
||||
it('Should load Project and associated DataSources', async function (): Promise<void> {
|
||||
// setup test files
|
||||
const folderPath = await testUtils.generateTestFolderPath();
|
||||
const sqlProjPath = await testUtils.createTestSqlProjFile(baselines.openProjectFileBaseline, folderPath);
|
||||
await testUtils.createTestDataSources(baselines.openDataSourcesBaseline, folderPath);
|
||||
|
||||
const projController = new ProjectsController(new SqlDatabaseProjectTreeViewProvider());
|
||||
|
||||
const project = await projController.openProject(vscode.Uri.file(sqlProjPath));
|
||||
|
||||
should(project.files.length).equal(10); // detailed sqlproj tests in their own test file
|
||||
should(project.dataSources.length).equal(3); // detailed datasources tests in their own test file
|
||||
});
|
||||
|
||||
it('Should load both project and referenced project', async function (): Promise<void> {
|
||||
// setup test projects
|
||||
const folderPath = await testUtils.generateTestFolderPath();
|
||||
await fs.mkdir(path.join(folderPath, 'proj1'));
|
||||
await fs.mkdir(path.join(folderPath, 'ReferencedProject'));
|
||||
|
||||
const sqlProjPath = await testUtils.createTestSqlProjFile(baselines.openProjectWithProjectReferencesBaseline, path.join(folderPath, 'proj1'));
|
||||
await testUtils.createTestSqlProjFile(baselines.openProjectFileBaseline, path.join(folderPath, 'ReferencedProject'));
|
||||
|
||||
const projController = new ProjectsController(new SqlDatabaseProjectTreeViewProvider());
|
||||
await projController.openProject(vscode.Uri.file(sqlProjPath));
|
||||
|
||||
should(projController.projects.length).equal(2, 'Referenced project should have been opened when the project referencing it was opened');
|
||||
});
|
||||
|
||||
it('Should not keep failed to load project in project list.', async function (): Promise<void> {
|
||||
const folderPath = await testUtils.generateTestFolderPath();
|
||||
const sqlProjPath = await testUtils.createTestSqlProjFile('empty file with no valid xml', folderPath);
|
||||
const projController = new ProjectsController(new SqlDatabaseProjectTreeViewProvider());
|
||||
|
||||
try {
|
||||
await projController.openProject(vscode.Uri.file(sqlProjPath));
|
||||
should.fail(null, null, 'The given project not expected to open');
|
||||
}
|
||||
catch {
|
||||
should(projController.projects.length).equal(0, 'The added project should be removed');
|
||||
}
|
||||
});
|
||||
|
||||
it('Should return silently when no SQL object name provided in prompts', async function (): Promise<void> {
|
||||
for (const name of ['', ' ', undefined]) {
|
||||
const showInputBoxStub = sinon.stub(vscode.window, 'showInputBox').resolves(name);
|
||||
const showErrorMessageSpy = sinon.spy(vscode.window, 'showErrorMessage');
|
||||
const projController = new ProjectsController(new SqlDatabaseProjectTreeViewProvider());
|
||||
const projController = new ProjectsController();
|
||||
const project = new Project('FakePath');
|
||||
|
||||
should(project.files.length).equal(0);
|
||||
@@ -138,7 +96,7 @@ describe('ProjectsController', function (): void {
|
||||
const tableName = 'table1';
|
||||
sinon.stub(vscode.window, 'showInputBox').resolves(tableName);
|
||||
const spy = sinon.spy(vscode.window, 'showErrorMessage');
|
||||
const projController = new ProjectsController(new SqlDatabaseProjectTreeViewProvider());
|
||||
const projController = new ProjectsController();
|
||||
const project = await testUtils.createTestProject(baselines.newProjectFileBaseline);
|
||||
|
||||
should(project.files.length).equal(0, 'There should be no files');
|
||||
@@ -154,14 +112,13 @@ describe('ProjectsController', function (): void {
|
||||
const folderName = 'folder1';
|
||||
const stub = sinon.stub(vscode.window, 'showInputBox').resolves(folderName);
|
||||
|
||||
const projController = new ProjectsController(new SqlDatabaseProjectTreeViewProvider());
|
||||
const projController = new ProjectsController();
|
||||
const project = await testUtils.createTestProject(baselines.newProjectFileBaseline);
|
||||
const projectRoot = new ProjectRootTreeItem(project);
|
||||
|
||||
should(project.files.length).equal(0, 'There should be no other folders');
|
||||
await projController.addFolderPrompt(projectRoot);
|
||||
await projController.addFolderPrompt(createWorkspaceTreeItem(projectRoot));
|
||||
should(project.files.length).equal(1, 'Folder should be successfully added');
|
||||
projController.refreshProjectsTree();
|
||||
stub.restore();
|
||||
await verifyFolderNotAdded(folderName, projController, project, projectRoot);
|
||||
|
||||
@@ -175,7 +132,7 @@ describe('ProjectsController', function (): void {
|
||||
const folderName = 'folder1';
|
||||
const stub = sinon.stub(vscode.window, 'showInputBox').resolves(folderName);
|
||||
|
||||
const projController = new ProjectsController(new SqlDatabaseProjectTreeViewProvider());
|
||||
const projController = new ProjectsController();
|
||||
const project = await testUtils.createTestProject(baselines.openProjectFileBaseline);
|
||||
const projectRoot = new ProjectRootTreeItem(project);
|
||||
|
||||
@@ -190,7 +147,7 @@ describe('ProjectsController', function (): void {
|
||||
async function verifyFolderAdded(folderName: string, projController: ProjectsController, project: Project, node: BaseProjectTreeItem): Promise<void> {
|
||||
const beforeFileCount = project.files.length;
|
||||
const stub = sinon.stub(vscode.window, 'showInputBox').resolves(folderName);
|
||||
await projController.addFolderPrompt(node);
|
||||
await projController.addFolderPrompt(createWorkspaceTreeItem(node));
|
||||
should(project.files.length).equal(beforeFileCount + 1, `File count should be increased by one after adding the folder ${folderName}`);
|
||||
stub.restore();
|
||||
}
|
||||
@@ -199,7 +156,7 @@ describe('ProjectsController', function (): void {
|
||||
const beforeFileCount = project.files.length;
|
||||
const showInputBoxStub = sinon.stub(vscode.window, 'showInputBox').resolves(folderName);
|
||||
const showErrorMessageSpy = sinon.spy(vscode.window, 'showErrorMessage');
|
||||
await projController.addFolderPrompt(node);
|
||||
await projController.addFolderPrompt(createWorkspaceTreeItem(node));
|
||||
should(showErrorMessageSpy.calledOnce).be.true('showErrorMessage should have been called exactly once');
|
||||
const msg = constants.folderAlreadyExists(folderName);
|
||||
should(showErrorMessageSpy.calledWith(msg)).be.true(`showErrorMessage not called with expected message '${msg}' Actual '${showErrorMessageSpy.getCall(0).args[0]}'`);
|
||||
@@ -213,13 +170,13 @@ describe('ProjectsController', function (): void {
|
||||
const setupResult = await setupDeleteExcludeTest(proj);
|
||||
const scriptEntry = setupResult[0], projTreeRoot = setupResult[1], preDeployEntry = setupResult[2], postDeployEntry = setupResult[3], noneEntry = setupResult[4];
|
||||
|
||||
const projController = new ProjectsController(new SqlDatabaseProjectTreeViewProvider());
|
||||
const projController = new ProjectsController();
|
||||
|
||||
await projController.delete(projTreeRoot.children.find(x => x.friendlyName === 'UpperFolder')!.children[0] /* LowerFolder */);
|
||||
await projController.delete(projTreeRoot.children.find(x => x.friendlyName === 'anotherScript.sql')!);
|
||||
await projController.delete(projTreeRoot.children.find(x => x.friendlyName === 'Script.PreDeployment1.sql')!);
|
||||
await projController.delete(projTreeRoot.children.find(x => x.friendlyName === 'Script.PreDeployment2.sql')!);
|
||||
await projController.delete(projTreeRoot.children.find(x => x.friendlyName === 'Script.PostDeployment1.sql')!);
|
||||
await projController.delete(createWorkspaceTreeItem(projTreeRoot.children.find(x => x.friendlyName === 'UpperFolder')!.children[0]) /* LowerFolder */);
|
||||
await projController.delete(createWorkspaceTreeItem(projTreeRoot.children.find(x => x.friendlyName === 'anotherScript.sql')!));
|
||||
await projController.delete(createWorkspaceTreeItem(projTreeRoot.children.find(x => x.friendlyName === 'Script.PreDeployment1.sql')!));
|
||||
await projController.delete(createWorkspaceTreeItem(projTreeRoot.children.find(x => x.friendlyName === 'Script.PreDeployment2.sql')!));
|
||||
await projController.delete(createWorkspaceTreeItem(projTreeRoot.children.find(x => x.friendlyName === 'Script.PostDeployment1.sql')!));
|
||||
|
||||
proj = await Project.openProject(proj.projectFilePath); // reload edited sqlproj from disk
|
||||
|
||||
@@ -239,7 +196,7 @@ describe('ProjectsController', function (): void {
|
||||
it('Should delete database references', async function (): Promise<void> {
|
||||
// setup - openProject baseline has a system db reference to master
|
||||
const proj = await testUtils.createTestProject(baselines.openProjectFileBaseline);
|
||||
const projController = new ProjectsController(new SqlDatabaseProjectTreeViewProvider());
|
||||
const projController = new ProjectsController();
|
||||
sinon.stub(vscode.window, 'showWarningMessage').returns(<any>Promise.resolve(constants.yesString));
|
||||
|
||||
// add dacpac reference
|
||||
@@ -261,9 +218,9 @@ describe('ProjectsController', function (): void {
|
||||
should(proj.databaseReferences.length).equal(3, 'Should start with 3 database references');
|
||||
|
||||
const databaseReferenceNodeChildren = projTreeRoot.children.find(x => x.friendlyName === constants.databaseReferencesNodeName)?.children;
|
||||
await projController.delete(databaseReferenceNodeChildren?.find(x => x.friendlyName === 'master')!); // system db reference
|
||||
await projController.delete(databaseReferenceNodeChildren?.find(x => x.friendlyName === 'test2')!); // dacpac reference
|
||||
await projController.delete(databaseReferenceNodeChildren?.find(x => x.friendlyName === 'project1')!); // project reference
|
||||
await projController.delete(createWorkspaceTreeItem(databaseReferenceNodeChildren?.find(x => x.friendlyName === 'master')!)); // system db reference
|
||||
await projController.delete(createWorkspaceTreeItem(databaseReferenceNodeChildren?.find(x => x.friendlyName === 'test2')!)); // dacpac reference
|
||||
await projController.delete(createWorkspaceTreeItem(databaseReferenceNodeChildren?.find(x => x.friendlyName === 'project1')!)); // project reference
|
||||
|
||||
// confirm result
|
||||
should(proj.databaseReferences.length).equal(0, 'All database references should have been deleted');
|
||||
@@ -274,13 +231,13 @@ describe('ProjectsController', function (): void {
|
||||
const setupResult = await setupDeleteExcludeTest(proj);
|
||||
const scriptEntry = setupResult[0], projTreeRoot = setupResult[1], preDeployEntry = setupResult[2], postDeployEntry = setupResult[3], noneEntry = setupResult[4];
|
||||
|
||||
const projController = new ProjectsController(new SqlDatabaseProjectTreeViewProvider());
|
||||
const projController = new ProjectsController();
|
||||
|
||||
await projController.exclude(<FolderNode>projTreeRoot.children.find(x => x.friendlyName === 'UpperFolder')!.children[0] /* LowerFolder */);
|
||||
await projController.exclude(<FileNode>projTreeRoot.children.find(x => x.friendlyName === 'anotherScript.sql')!);
|
||||
await projController.exclude(<FileNode>projTreeRoot.children.find(x => x.friendlyName === 'Script.PreDeployment1.sql')!);
|
||||
await projController.exclude(<FileNode>projTreeRoot.children.find(x => x.friendlyName === 'Script.PreDeployment2.sql')!);
|
||||
await projController.exclude(<FileNode>projTreeRoot.children.find(x => x.friendlyName === 'Script.PostDeployment1.sql')!);
|
||||
await projController.exclude(createWorkspaceTreeItem(<FolderNode>projTreeRoot.children.find(x => x.friendlyName === 'UpperFolder')!.children[0]) /* LowerFolder */);
|
||||
await projController.exclude(createWorkspaceTreeItem(<FileNode>projTreeRoot.children.find(x => x.friendlyName === 'anotherScript.sql')!));
|
||||
await projController.exclude(createWorkspaceTreeItem(<FileNode>projTreeRoot.children.find(x => x.friendlyName === 'Script.PreDeployment1.sql')!));
|
||||
await projController.exclude(createWorkspaceTreeItem(<FileNode>projTreeRoot.children.find(x => x.friendlyName === 'Script.PreDeployment2.sql')!));
|
||||
await projController.exclude(createWorkspaceTreeItem(<FileNode>projTreeRoot.children.find(x => x.friendlyName === 'Script.PostDeployment1.sql')!));
|
||||
|
||||
proj = await Project.openProject(proj.projectFilePath); // reload edited sqlproj from disk
|
||||
|
||||
@@ -302,18 +259,22 @@ describe('ProjectsController', function (): void {
|
||||
const folderPath = await testUtils.generateTestFolderPath();
|
||||
const sqlProjPath = await testUtils.createTestSqlProjFile(baselines.newProjectFileBaseline, folderPath);
|
||||
const treeProvider = new SqlDatabaseProjectTreeViewProvider();
|
||||
const projController = new ProjectsController(treeProvider);
|
||||
const project = await projController.openProject(vscode.Uri.file(sqlProjPath));
|
||||
const projController = new ProjectsController();
|
||||
const project = await Project.openProject(vscode.Uri.file(sqlProjPath).fsPath);
|
||||
treeProvider.load([project]);
|
||||
|
||||
// change the sql project file
|
||||
await fs.writeFile(sqlProjPath, baselines.newProjectFileWithScriptBaseline);
|
||||
should(project.files.length).equal(0);
|
||||
|
||||
// call reload project
|
||||
await projController.reloadProject(vscode.Uri.file(project.projectFilePath));
|
||||
should(project.files.length).equal(1);
|
||||
await projController.reloadProject({ treeDataProvider: treeProvider, element: { root: { project: project } } });
|
||||
// calling this because this gets called in the projectProvider.getProjectTreeDataProvider(), which is called by workspaceTreeDataProvider
|
||||
// when notifyTreeDataChanged() happens
|
||||
treeProvider.load([project]);
|
||||
|
||||
// check that the new project is in the tree
|
||||
should(project.files.length).equal(1);
|
||||
should(treeProvider.getChildren()[0].children.find(c => c.friendlyName === 'Script1.sql')).not.equal(undefined);
|
||||
});
|
||||
|
||||
@@ -321,7 +282,7 @@ describe('ProjectsController', function (): void {
|
||||
const preDeployScriptName = 'PreDeployScript1.sql';
|
||||
const postDeployScriptName = 'PostDeployScript1.sql';
|
||||
|
||||
const projController = new ProjectsController(new SqlDatabaseProjectTreeViewProvider());
|
||||
const projController = new ProjectsController();
|
||||
const project = await testUtils.createTestProject(baselines.newProjectFileBaseline);
|
||||
|
||||
sinon.stub(vscode.window, 'showInputBox').resolves(preDeployScriptName);
|
||||
@@ -339,9 +300,9 @@ describe('ProjectsController', function (): void {
|
||||
it('Should change target platform', async function (): Promise<void> {
|
||||
sinon.stub(vscode.window, 'showQuickPick').resolves({ label: constants.sqlAzure });
|
||||
|
||||
const projController = new ProjectsController(new SqlDatabaseProjectTreeViewProvider());
|
||||
const projController = new ProjectsController();
|
||||
const sqlProjPath = await testUtils.createTestSqlProjFile(baselines.openProjectFileBaseline);
|
||||
const project = await projController.openProject(vscode.Uri.file(sqlProjPath));
|
||||
const project = await Project.openProject(sqlProjPath);
|
||||
should(project.getProjectTargetVersion()).equal(constants.targetPlatformToVersion.get(constants.sqlServer2019));
|
||||
should(project.databaseReferences.length).equal(1, 'Project should have one database reference to master');
|
||||
should(project.databaseReferences[0].fsUri.fsPath).containEql(constants.targetPlatformToVersion.get(constants.sqlServer2019));
|
||||
@@ -387,12 +348,12 @@ describe('ProjectsController', function (): void {
|
||||
let projController = TypeMoq.Mock.ofType(ProjectsController);
|
||||
projController.callBase = true;
|
||||
projController.setup(x => x.getPublishDialog(TypeMoq.It.isAny())).returns(() => publishDialog.object);
|
||||
projController.setup(x => x.executionCallback(TypeMoq.It.isAny(), TypeMoq.It.is((_): _ is IPublishSettings => true))).returns(() => {
|
||||
projController.setup(x => x.publishProjectCallback(TypeMoq.It.isAny(), TypeMoq.It.is((_): _ is IPublishSettings => true))).returns(() => {
|
||||
holler = publishHoller;
|
||||
return Promise.resolve(undefined);
|
||||
});
|
||||
|
||||
projController.setup(x => x.executionCallback(TypeMoq.It.isAny(), TypeMoq.It.is((_): _ is IGenerateScriptSettings => true))).returns(() => {
|
||||
projController.setup(x => x.publishProjectCallback(TypeMoq.It.isAny(), TypeMoq.It.is((_): _ is IGenerateScriptSettings => true))).returns(() => {
|
||||
holler = generateHoller;
|
||||
return Promise.resolve(undefined);
|
||||
});
|
||||
@@ -430,7 +391,7 @@ describe('ProjectsController', function (): void {
|
||||
|
||||
projController.setup(x => x.getDaxFxService()).returns(() => Promise.resolve(testContext.dacFxService.object));
|
||||
|
||||
await projController.object.executionCallback(new Project(''), { connectionUri: '', databaseName: '' });
|
||||
await projController.object.publishProjectCallback(new Project(''), { connectionUri: '', databaseName: '' });
|
||||
|
||||
should(builtDacpacPath).not.equal('', 'built dacpac path should be set');
|
||||
should(publishedDacpacPath).not.equal('', 'published dacpac path should be set');
|
||||
@@ -440,11 +401,15 @@ describe('ProjectsController', function (): void {
|
||||
});
|
||||
});
|
||||
|
||||
describe('import operations', function (): void {
|
||||
describe('Create project from database', function (): void {
|
||||
afterEach(() => {
|
||||
sinon.restore();
|
||||
});
|
||||
|
||||
it('Should create list of all files and folders correctly', async function (): Promise<void> {
|
||||
const testFolderPath = await testUtils.createDummyFileStructure();
|
||||
|
||||
const projController = new ProjectsController(new SqlDatabaseProjectTreeViewProvider());
|
||||
const projController = new ProjectsController();
|
||||
const fileList = await projController.generateList(testFolderPath);
|
||||
|
||||
should(fileList.length).equal(15); // Parent folder + 2 files under parent folder + 2 directories with 5 files each
|
||||
@@ -456,7 +421,7 @@ describe('ProjectsController', function (): void {
|
||||
let testFolderPath = await testUtils.generateTestFolderPath();
|
||||
testFolderPath += '_nonexistentFolder'; // Modify folder path to point to a nonexistent location
|
||||
|
||||
const projController = new ProjectsController(new SqlDatabaseProjectTreeViewProvider());
|
||||
const projController = new ProjectsController();
|
||||
|
||||
await projController.generateList(testFolderPath);
|
||||
should(spy.calledOnce).be.true('showErrorMessage should have been called');
|
||||
@@ -466,11 +431,16 @@ describe('ProjectsController', function (): void {
|
||||
|
||||
it('Should show error when no project name provided', async function (): Promise<void> {
|
||||
for (const name of ['', ' ', undefined]) {
|
||||
const dataWorkspaceMock = TypeMoq.Mock.ofType<dataworkspace.IExtension>();
|
||||
dataWorkspaceMock.setup(x => x.getProjectsInWorkspace()).returns(() => []);
|
||||
dataWorkspaceMock.setup(x => x.defaultProjectSaveLocation).returns(() => vscode.Uri.file('/test/folder'));
|
||||
sinon.stub(vscode.extensions, 'getExtension').returns(<any>{ exports: dataWorkspaceMock.object});
|
||||
sinon.stub(vscode.workspace, 'workspaceFile').value(vscode.Uri.file('/test/folder/ws.code-workspace'));
|
||||
sinon.stub(vscode.window, 'showInputBox').resolves(name);
|
||||
const spy = sinon.spy(vscode.window, 'showErrorMessage');
|
||||
|
||||
const projController = new ProjectsController(new SqlDatabaseProjectTreeViewProvider());
|
||||
await projController.importNewDatabaseProject({ connectionProfile: mockConnectionProfile });
|
||||
const projController = new ProjectsController();
|
||||
await projController.createProjectFromDatabase({ connectionProfile: mockConnectionProfile });
|
||||
should(spy.calledOnce).be.true('showErrorMessage should have been called');
|
||||
should(spy.calledWith(constants.projectNameRequired)).be.true(`showErrorMessage not called with expected message '${constants.projectNameRequired}' Actual '${spy.getCall(0).args[0]}'`);
|
||||
sinon.restore();
|
||||
@@ -478,37 +448,52 @@ describe('ProjectsController', function (): void {
|
||||
});
|
||||
|
||||
it('Should show error when no target information provided', async function (): Promise<void> {
|
||||
const dataWorkspaceMock = TypeMoq.Mock.ofType<dataworkspace.IExtension>();
|
||||
dataWorkspaceMock.setup(x => x.getProjectsInWorkspace()).returns(() => []);
|
||||
dataWorkspaceMock.setup(x => x.defaultProjectSaveLocation).returns(() => vscode.Uri.file('/test/folder'));
|
||||
sinon.stub(vscode.extensions, 'getExtension').returns(<any>{ exports: dataWorkspaceMock.object});
|
||||
sinon.stub(vscode.workspace, 'workspaceFile').value(vscode.Uri.file('/test/folder/ws.code-workspace'));
|
||||
sinon.stub(vscode.window, 'showInputBox').resolves('MyProjectName');
|
||||
sinon.stub(vscode.window, 'showQuickPick').resolves(undefined);
|
||||
sinon.stub(vscode.window, 'showOpenDialog').resolves([vscode.Uri.file('fakePath')]);
|
||||
const spy = sinon.spy(vscode.window, 'showErrorMessage');
|
||||
|
||||
const projController = new ProjectsController(new SqlDatabaseProjectTreeViewProvider());
|
||||
await projController.importNewDatabaseProject({ connectionProfile: mockConnectionProfile });
|
||||
const projController = new ProjectsController();
|
||||
await projController.createProjectFromDatabase({ connectionProfile: mockConnectionProfile });
|
||||
should(spy.calledOnce).be.true('showErrorMessage should have been called');
|
||||
should(spy.calledWith(constants.extractTargetRequired)).be.true(`showErrorMessage not called with expected message '${constants.extractTargetRequired}' Actual '${spy.getCall(0).args[0]}'`);
|
||||
});
|
||||
|
||||
it('Should show error when no location provided with ExtractTarget = File', async function (): Promise<void> {
|
||||
const dataWorkspaceMock = TypeMoq.Mock.ofType<dataworkspace.IExtension>();
|
||||
dataWorkspaceMock.setup(x => x.getProjectsInWorkspace()).returns(() => []);
|
||||
dataWorkspaceMock.setup(x => x.defaultProjectSaveLocation).returns(() => vscode.Uri.file('/test/folder'));
|
||||
sinon.stub(vscode.extensions, 'getExtension').returns(<any>{ exports: dataWorkspaceMock.object});
|
||||
sinon.stub(vscode.workspace, 'workspaceFile').value(vscode.Uri.file('/test/folder/ws.code-workspace'));
|
||||
sinon.stub(vscode.window, 'showInputBox').resolves('MyProjectName');
|
||||
sinon.stub(vscode.window, 'showOpenDialog').resolves(undefined);
|
||||
sinon.stub(vscode.window, 'showQuickPick').resolves({ label: constants.file });
|
||||
const spy = sinon.spy(vscode.window, 'showErrorMessage');
|
||||
|
||||
const projController = new ProjectsController(new SqlDatabaseProjectTreeViewProvider());
|
||||
await projController.importNewDatabaseProject({ connectionProfile: mockConnectionProfile });
|
||||
const projController = new ProjectsController();
|
||||
await projController.createProjectFromDatabase({ connectionProfile: mockConnectionProfile });
|
||||
should(spy.calledOnce).be.true('showErrorMessage should have been called');
|
||||
should(spy.calledWith(constants.projectLocationRequired)).be.true(`showErrorMessage not called with expected message '${constants.projectLocationRequired}' Actual '${spy.getCall(0).args[0]}'`);
|
||||
});
|
||||
|
||||
it('Should show error when no location provided with ExtractTarget = SchemaObjectType', async function (): Promise<void> {
|
||||
const dataWorkspaceMock = TypeMoq.Mock.ofType<dataworkspace.IExtension>();
|
||||
dataWorkspaceMock.setup(x => x.getProjectsInWorkspace()).returns(() => []);
|
||||
dataWorkspaceMock.setup(x => x.defaultProjectSaveLocation).returns(() => vscode.Uri.file('/test/folder'));
|
||||
sinon.stub(vscode.extensions, 'getExtension').returns(<any>{ exports: dataWorkspaceMock.object});
|
||||
sinon.stub(vscode.workspace, 'workspaceFile').value(vscode.Uri.file('/test/folder/ws.code-workspace'));
|
||||
sinon.stub(vscode.window, 'showInputBox').resolves('MyProjectName');
|
||||
sinon.stub(vscode.window, 'showQuickPick').resolves({ label: constants.schemaObjectType });
|
||||
sinon.stub(vscode.window, 'showOpenDialog').resolves(undefined);
|
||||
const spy = sinon.spy(vscode.window, 'showErrorMessage');
|
||||
|
||||
const projController = new ProjectsController(new SqlDatabaseProjectTreeViewProvider());
|
||||
await projController.importNewDatabaseProject({ connectionProfile: mockConnectionProfile });
|
||||
const projController = new ProjectsController();
|
||||
await projController.createProjectFromDatabase({ connectionProfile: mockConnectionProfile });
|
||||
should(spy.calledOnce).be.true('showErrorMessage should have been called');
|
||||
should(spy.calledWith(constants.projectLocationRequired)).be.true(`showErrorMessage not called with expected message '${constants.projectLocationRequired}' Actual '${spy.getCall(0).args[0]}'`);
|
||||
});
|
||||
@@ -517,6 +502,11 @@ describe('ProjectsController', function (): void {
|
||||
const projectName = 'MyProjectName';
|
||||
let folderPath = await testUtils.generateTestFolderPath();
|
||||
|
||||
const dataWorkspaceMock = TypeMoq.Mock.ofType<dataworkspace.IExtension>();
|
||||
dataWorkspaceMock.setup(x => x.defaultProjectSaveLocation).returns(() => vscode.Uri.file('/test/folder'));
|
||||
dataWorkspaceMock.setup(x => x.getProjectsInWorkspace()).returns(() => []);
|
||||
sinon.stub(vscode.extensions, 'getExtension').returns(<any>{ exports: dataWorkspaceMock.object});
|
||||
sinon.stub(vscode.workspace, 'workspaceFile').value(vscode.Uri.file('/test/folder/ws.code-workspace'));
|
||||
sinon.stub(vscode.window, 'showInputBox').resolves(projectName);
|
||||
const showQuickPickStub = sinon.stub(vscode.window, 'showQuickPick').resolves({ label: constants.file });
|
||||
sinon.stub(vscode.window, 'showOpenDialog').callsFake(() => Promise.resolve([vscode.Uri.file(folderPath)]));
|
||||
@@ -526,9 +516,9 @@ describe('ProjectsController', function (): void {
|
||||
let projController = TypeMoq.Mock.ofType(ProjectsController, undefined, undefined, new SqlDatabaseProjectTreeViewProvider());
|
||||
projController.callBase = true;
|
||||
|
||||
projController.setup(x => x.importApiCall(TypeMoq.It.isAny())).returns(async (model) => { importPath = model.filePath; });
|
||||
projController.setup(x => x.createProjectFromDatabaseApiCall(TypeMoq.It.isAny())).returns(async (model) => { importPath = model.filePath; });
|
||||
|
||||
await projController.object.importNewDatabaseProject({ connectionProfile: mockConnectionProfile });
|
||||
await projController.object.createProjectFromDatabase({ connectionProfile: mockConnectionProfile });
|
||||
should(importPath).equal(vscode.Uri.file(path.join(folderPath, projectName, projectName + '.sql')).fsPath, `model.filePath should be set to a specific file for ExtractTarget === file, but was ${importPath}`);
|
||||
|
||||
// reset for counter-test
|
||||
@@ -536,7 +526,7 @@ describe('ProjectsController', function (): void {
|
||||
folderPath = await testUtils.generateTestFolderPath();
|
||||
showQuickPickStub.resolves({ label: constants.schemaObjectType });
|
||||
|
||||
await projController.object.importNewDatabaseProject({ connectionProfile: mockConnectionProfile });
|
||||
await projController.object.createProjectFromDatabase({ connectionProfile: mockConnectionProfile });
|
||||
should(importPath).equal(vscode.Uri.file(path.join(folderPath, projectName)).fsPath, `model.filePath should be set to a folder for ExtractTarget !== file, but was ${importPath}`);
|
||||
});
|
||||
|
||||
@@ -552,7 +542,7 @@ describe('ProjectsController', function (): void {
|
||||
options: {}
|
||||
});
|
||||
|
||||
let projController = new ProjectsController(new SqlDatabaseProjectTreeViewProvider());
|
||||
let projController = new ProjectsController();
|
||||
|
||||
let result = await projController.getModelFromContext(undefined);
|
||||
|
||||
@@ -590,14 +580,16 @@ describe('ProjectsController', function (): void {
|
||||
const addDbReferenceDialog = TypeMoq.Mock.ofType(AddDatabaseReferenceDialog, undefined, undefined, proj);
|
||||
addDbReferenceDialog.callBase = true;
|
||||
addDbReferenceDialog.setup(x => x.addReferenceClick()).returns(() => {
|
||||
projController.object.addDatabaseReferenceCallback(proj, { systemDb: SystemDatabase.master, databaseName: 'master', suppressMissingDependenciesErrors: false });
|
||||
projController.object.addDatabaseReferenceCallback(proj,
|
||||
{ systemDb: SystemDatabase.master, databaseName: 'master', suppressMissingDependenciesErrors: false },
|
||||
{ treeDataProvider: new SqlDatabaseProjectTreeViewProvider(), element: undefined });
|
||||
return Promise.resolve(undefined);
|
||||
});
|
||||
|
||||
const projController = TypeMoq.Mock.ofType(ProjectsController);
|
||||
projController.callBase = true;
|
||||
projController.setup(x => x.getAddDatabaseReferenceDialog(TypeMoq.It.isAny())).returns(() => addDbReferenceDialog.object);
|
||||
projController.setup(x => x.addDatabaseReferenceCallback(TypeMoq.It.isAny(), TypeMoq.It.is((_): _ is IDacpacReferenceSettings => true))).returns(() => {
|
||||
projController.setup(x => x.addDatabaseReferenceCallback(TypeMoq.It.isAny(), TypeMoq.It.is((_): _ is IDacpacReferenceSettings => true), TypeMoq.It.isAny())).returns(() => {
|
||||
holler = addDbRefHoller;
|
||||
return Promise.resolve(undefined);
|
||||
});
|
||||
@@ -609,14 +601,16 @@ describe('ProjectsController', function (): void {
|
||||
});
|
||||
|
||||
it('Should not allow adding circular project references', async function (): Promise<void> {
|
||||
const showErrorMessageSpy = sinon.spy(vscode.window, 'showErrorMessage');
|
||||
|
||||
const projPath1 = await testUtils.createTestSqlProjFile(baselines.openProjectFileBaseline);
|
||||
const projPath2 = await testUtils.createTestSqlProjFile(baselines.newProjectFileBaseline);
|
||||
const projController = new ProjectsController(new SqlDatabaseProjectTreeViewProvider());
|
||||
const projController = new ProjectsController();
|
||||
|
||||
const project1 = await projController.openProject(vscode.Uri.file(projPath1));
|
||||
const project2 = await projController.openProject(vscode.Uri.file(projPath2));
|
||||
const project1 = await Project.openProject(vscode.Uri.file(projPath1).fsPath);
|
||||
const project2 = await Project.openProject(vscode.Uri.file(projPath2).fsPath);
|
||||
const showErrorMessageSpy = sinon.spy(vscode.window, 'showErrorMessage');
|
||||
const dataWorkspaceMock = TypeMoq.Mock.ofType<dataworkspace.IExtension>();
|
||||
dataWorkspaceMock.setup(x => x.getProjectsInWorkspace()).returns(() => [vscode.Uri.file(project1.projectFilePath), vscode.Uri.file(project2.projectFilePath)]);
|
||||
sinon.stub(vscode.extensions, 'getExtension').returns(<any>{ exports: dataWorkspaceMock.object });
|
||||
|
||||
// add project reference from project1 to project2
|
||||
await projController.addDatabaseReferenceCallback(project1, {
|
||||
@@ -624,7 +618,8 @@ describe('ProjectsController', function (): void {
|
||||
projectName: 'TestProject',
|
||||
projectRelativePath: undefined,
|
||||
suppressMissingDependenciesErrors: false
|
||||
});
|
||||
},
|
||||
{ treeDataProvider: new SqlDatabaseProjectTreeViewProvider(), element: undefined });
|
||||
should(showErrorMessageSpy.notCalled).be.true('showErrorMessage should not have been called');
|
||||
|
||||
// try to add circular reference
|
||||
@@ -633,75 +628,14 @@ describe('ProjectsController', function (): void {
|
||||
projectName: 'TestProjectName',
|
||||
projectRelativePath: undefined,
|
||||
suppressMissingDependenciesErrors: false
|
||||
});
|
||||
},
|
||||
{ treeDataProvider: new SqlDatabaseProjectTreeViewProvider(), element: undefined });
|
||||
should(showErrorMessageSpy.called).be.true('showErrorMessage should have been called');
|
||||
});
|
||||
|
||||
});
|
||||
});
|
||||
|
||||
describe.skip('ProjectsController: round trip feature with SSDT', function (): void {
|
||||
it('Should show warning message for SSDT project opened in Azure Data Studio', async function (): Promise<void> {
|
||||
const stub = sinon.stub(vscode.window, 'showWarningMessage').returns(<any>Promise.resolve(constants.noString));
|
||||
|
||||
// setup test files
|
||||
const folderPath = await testUtils.generateTestFolderPath();
|
||||
const sqlProjPath = await testUtils.createTestSqlProjFile(baselines.SSDTProjectFileBaseline, folderPath);
|
||||
await testUtils.createTestDataSources(baselines.openDataSourcesBaseline, folderPath);
|
||||
|
||||
const projController = new ProjectsController(new SqlDatabaseProjectTreeViewProvider());
|
||||
|
||||
await projController.openProject(vscode.Uri.file(sqlProjPath));
|
||||
should(stub.calledOnce).be.true('showWarningMessage should have been called exactly once');
|
||||
should(stub.calledWith(constants.updateProjectForRoundTrip)).be.true(`showWarningMessage not called with expected message '${constants.updateProjectForRoundTrip}' Actual '${stub.getCall(0).args[0]}'`);
|
||||
});
|
||||
|
||||
it('Should not show warning message for non-SSDT projects that have the additional information for Build', async function (): Promise<void> {
|
||||
// setup test files
|
||||
const folderPath = await testUtils.generateTestFolderPath();
|
||||
const sqlProjPath = await testUtils.createTestSqlProjFile(baselines.openProjectFileBaseline, folderPath);
|
||||
await testUtils.createTestDataSources(baselines.openDataSourcesBaseline, folderPath);
|
||||
|
||||
const projController = new ProjectsController(new SqlDatabaseProjectTreeViewProvider());
|
||||
|
||||
const project = await projController.openProject(vscode.Uri.file(sqlProjPath)); // no error thrown
|
||||
|
||||
should(project.importedTargets.length).equal(3); // additional target should exist by default
|
||||
});
|
||||
|
||||
it('Should not update project and no backup file should be created when update to project is rejected', async function (): Promise<void> {
|
||||
sinon.stub(vscode.window, 'showWarningMessage').returns(<any>Promise.resolve(constants.noString));
|
||||
// setup test files
|
||||
const folderPath = await testUtils.generateTestFolderPath();
|
||||
const sqlProjPath = await testUtils.createTestSqlProjFile(baselines.SSDTProjectFileBaseline, folderPath);
|
||||
await testUtils.createTestDataSources(baselines.openDataSourcesBaseline, folderPath);
|
||||
|
||||
const projController = new ProjectsController(new SqlDatabaseProjectTreeViewProvider());
|
||||
|
||||
const project = await projController.openProject(vscode.Uri.file(sqlProjPath));
|
||||
|
||||
should(await exists(sqlProjPath + '_backup')).equal(false); // backup file should not be generated
|
||||
should(project.importedTargets.length).equal(2); // additional target should not be added by updateProjectForRoundTrip method
|
||||
});
|
||||
|
||||
it('Should load Project and associated import targets when update to project is accepted', async function (): Promise<void> {
|
||||
sinon.stub(vscode.window, 'showWarningMessage').returns(<any>Promise.resolve(constants.yesString));
|
||||
|
||||
// setup test files
|
||||
const folderPath = await testUtils.generateTestFolderPath();
|
||||
const sqlProjPath = await testUtils.createTestSqlProjFile(baselines.SSDTProjectFileBaseline, folderPath);
|
||||
await testUtils.createTestDataSources(baselines.openDataSourcesBaseline, folderPath);
|
||||
|
||||
const projController = new ProjectsController(new SqlDatabaseProjectTreeViewProvider());
|
||||
|
||||
const project = await projController.openProject(vscode.Uri.file(sqlProjPath));
|
||||
|
||||
should(await exists(sqlProjPath + '_backup')).equal(true); // backup file should be generated before the project is updated
|
||||
should(project.importedTargets.length).equal(3); // additional target added by updateProjectForRoundTrip method
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
async function setupDeleteExcludeTest(proj: Project): Promise<[FileProjectEntry, ProjectRootTreeItem, FileProjectEntry, FileProjectEntry, FileProjectEntry]> {
|
||||
await proj.addFolderItem('UpperFolder');
|
||||
await proj.addFolderItem('UpperFolder/LowerFolder');
|
||||
@@ -725,3 +659,10 @@ async function setupDeleteExcludeTest(proj: Project): Promise<[FileProjectEntry,
|
||||
|
||||
return [scriptEntry, projTreeRoot, preDeployEntry, postDeployEntry, noneEntry];
|
||||
}
|
||||
|
||||
function createWorkspaceTreeItem(node: BaseProjectTreeItem): dataworkspace.WorkspaceTreeItem {
|
||||
return {
|
||||
element: node,
|
||||
treeDataProvider: new SqlDatabaseProjectTreeViewProvider()
|
||||
};
|
||||
}
|
||||
|
||||
@@ -12,7 +12,6 @@ import * as baselines from './baselines/baselines';
|
||||
import * as testUtils from './testUtils';
|
||||
import * as constants from '../common/constants';
|
||||
import { ProjectsController } from '../controllers/projectController';
|
||||
import { SqlDatabaseProjectTreeViewProvider } from '../controllers/databaseProjectTreeViewProvider';
|
||||
import { TestContext, createContext, mockDacFxOptionsResult } from './testContext';
|
||||
import { load } from '../models/publishProfile/publishProfile';
|
||||
|
||||
@@ -82,7 +81,7 @@ describe('Publish profile tests', function (): void {
|
||||
it('Should throw error when connecting does not work', async function (): Promise<void> {
|
||||
await baselines.loadBaselines();
|
||||
let profilePath = await testUtils.createTestFile(baselines.publishProfileIntegratedSecurityBaseline, 'publishProfile.publish.xml');
|
||||
const projController = new ProjectsController(new SqlDatabaseProjectTreeViewProvider());
|
||||
const projController = new ProjectsController();
|
||||
|
||||
sinon.stub(azdata.connection, 'connect').throws(new Error('Could not connect'));
|
||||
|
||||
|
||||
@@ -110,7 +110,7 @@ export class MockDacFxService implements mssql.IDacFxService {
|
||||
public exportBacpac(_: string, __: string, ___: string, ____: azdata.TaskExecutionMode): Thenable<mssql.DacFxResult> { return Promise.resolve(mockDacFxResult); }
|
||||
public importBacpac(_: string, __: string, ___: string, ____: azdata.TaskExecutionMode): Thenable<mssql.DacFxResult> { return Promise.resolve(mockDacFxResult); }
|
||||
public extractDacpac(_: string, __: string, ___: string, ____: string, _____: string, ______: azdata.TaskExecutionMode): Thenable<mssql.DacFxResult> { return Promise.resolve(mockDacFxResult); }
|
||||
public importDatabaseProject(_: string, __: string, ___: string, ____: string, _____: string, ______: mssql.ExtractTarget, _______: azdata.TaskExecutionMode): Thenable<mssql.DacFxResult> { return Promise.resolve(mockDacFxResult); }
|
||||
public createProjectFromDatabase(_: string, __: string, ___: string, ____: string, _____: string, ______: mssql.ExtractTarget, _______: azdata.TaskExecutionMode): Thenable<mssql.DacFxResult> { return Promise.resolve(mockDacFxResult); }
|
||||
public deployDacpac(_: string, __: string, ___: boolean, ____: string, _____: azdata.TaskExecutionMode, ______?: Record<string, string>): Thenable<mssql.DacFxResult> { return Promise.resolve(mockDacFxResult); }
|
||||
public generateDeployScript(_: string, __: string, ___: string, ____: azdata.TaskExecutionMode, ______?: Record<string, string>): Thenable<mssql.DacFxResult> { return Promise.resolve(mockDacFxResult); }
|
||||
public generateDeployPlan(_: string, __: string, ___: string, ____: azdata.TaskExecutionMode): Thenable<mssql.GenerateDeployPlanResult> { return Promise.resolve(mockDacFxResult); }
|
||||
|
||||
@@ -5,24 +5,17 @@
|
||||
|
||||
import * as vscode from 'vscode';
|
||||
import * as fs from 'fs';
|
||||
import * as os from 'os';
|
||||
import * as path from 'path';
|
||||
import * as os from 'os';
|
||||
import * as constants from '../common/constants';
|
||||
|
||||
/**
|
||||
* Sets workspace setting on the default save location to the user's home directory
|
||||
*/
|
||||
export async function initializeSaveLocationSetting() {
|
||||
if (!projectSaveLocationSettingExists()) {
|
||||
await config().update(constants.projectSaveLocationKey, os.homedir(), true);
|
||||
}
|
||||
}
|
||||
import * as utils from '../common/utils';
|
||||
|
||||
/**
|
||||
* Returns the default location to save a new database project
|
||||
*/
|
||||
export function defaultProjectSaveLocation(): vscode.Uri {
|
||||
return projectSaveLocationSettingIsValid() ? vscode.Uri.file(projectSaveLocationSetting()) : vscode.Uri.file(os.homedir());
|
||||
export function defaultProjectSaveLocation(): vscode.Uri | undefined {
|
||||
const workspaceApi = utils.getDataWorkspaceExtensionApi();
|
||||
return workspaceApi.defaultProjectSaveLocation;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -41,7 +34,8 @@ export function defaultProjectNameNewProj(): string {
|
||||
*/
|
||||
export function defaultProjectNameFromDb(dbName: string): string {
|
||||
const projectNameStarter = constants.defaultProjectNameStarter + dbName;
|
||||
const projectPath: string = path.join(defaultProjectSaveLocation().fsPath, projectNameStarter);
|
||||
const defaultLocation = defaultProjectSaveLocation() ?? vscode.Uri.file(os.homedir());
|
||||
const projectPath: string = path.join(defaultLocation.fsPath, projectNameStarter);
|
||||
if (!fs.existsSync(projectPath)) {
|
||||
return projectNameStarter;
|
||||
}
|
||||
@@ -49,58 +43,6 @@ export function defaultProjectNameFromDb(dbName: string): string {
|
||||
return defaultProjectName(projectNameStarter, 2);
|
||||
}
|
||||
|
||||
/**
|
||||
* Prompts user to update workspace settings
|
||||
*/
|
||||
export async function updateSaveLocationSetting(): Promise<void> {
|
||||
const showPrompt: boolean = config()[constants.showUpdatePromptKey];
|
||||
if (showPrompt) {
|
||||
const openSettingsMessage = projectSaveLocationSettingIsValid() ?
|
||||
constants.newDefaultProjectSaveLocation : constants.invalidDefaultProjectSaveLocation;
|
||||
const result = await vscode.window.showInformationMessage(openSettingsMessage, constants.openWorkspaceSettings,
|
||||
constants.doNotPromptAgain);
|
||||
|
||||
if (result === constants.openWorkspaceSettings || result === constants.doNotPromptAgain) {
|
||||
// if user either opens settings or clicks "don't ask again", do not prompt for save location again
|
||||
await config().update(constants.showUpdatePromptKey, false, true);
|
||||
|
||||
if (result === constants.openWorkspaceSettings) {
|
||||
await vscode.commands.executeCommand('workbench.action.openGlobalSettings'); //open settings
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get workspace configurations for this extension
|
||||
*/
|
||||
function config(): vscode.WorkspaceConfiguration {
|
||||
return vscode.workspace.getConfiguration(constants.dbProjectConfigurationKey);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the workspace setting on the default location to save new database projects
|
||||
*/
|
||||
function projectSaveLocationSetting(): string {
|
||||
return config()[constants.projectSaveLocationKey];
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns if the default save location for new database projects workspace setting exists and is
|
||||
* a valid path
|
||||
*/
|
||||
function projectSaveLocationSettingIsValid(): boolean {
|
||||
return projectSaveLocationSettingExists() && fs.existsSync(projectSaveLocationSetting());
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns if a value for the default save location for new database projects exists
|
||||
*/
|
||||
function projectSaveLocationSettingExists(): boolean {
|
||||
return projectSaveLocationSetting() !== undefined && projectSaveLocationSetting() !== null
|
||||
&& projectSaveLocationSetting().trim() !== '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a project name that begins with the given nameStarter, and ends in a number, such as
|
||||
* 'DatabaseProject1'. Number begins at the given counter, but auto-increments if a project of
|
||||
@@ -112,7 +54,8 @@ function projectSaveLocationSettingExists(): boolean {
|
||||
function defaultProjectName(nameStarter: string, counter: number): string {
|
||||
while (counter < Number.MAX_SAFE_INTEGER) {
|
||||
const name: string = nameStarter + counter;
|
||||
const projectPath: string = path.join(defaultProjectSaveLocation().fsPath, name);
|
||||
const defaultLocation = defaultProjectSaveLocation() ?? vscode.Uri.file(os.homedir());
|
||||
const projectPath: string = path.join(defaultLocation.fsPath, name);
|
||||
if (!fs.existsSync(projectPath)) {
|
||||
return name;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user