mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-16 10:58:30 -05:00
Combine project deploy settings into one (#16383)
This commit is contained in:
@@ -20,7 +20,7 @@ import { PublishDatabaseDialog } from '../dialogs/publishDatabaseDialog';
|
|||||||
import { Project, reservedProjectFolders, FileProjectEntry, SqlProjectReferenceProjectEntry, IDatabaseReferenceProjectEntry } from '../models/project';
|
import { Project, reservedProjectFolders, FileProjectEntry, SqlProjectReferenceProjectEntry, IDatabaseReferenceProjectEntry } from '../models/project';
|
||||||
import { SqlDatabaseProjectTreeViewProvider } from './databaseProjectTreeViewProvider';
|
import { SqlDatabaseProjectTreeViewProvider } from './databaseProjectTreeViewProvider';
|
||||||
import { FolderNode, FileNode } from '../models/tree/fileFolderTreeItem';
|
import { FolderNode, FileNode } from '../models/tree/fileFolderTreeItem';
|
||||||
import { IPublishSettings, IGenerateScriptSettings } from '../models/IPublishSettings';
|
import { IDeploySettings } from '../models/IDeploySettings';
|
||||||
import { BaseProjectTreeItem } from '../models/tree/baseTreeItem';
|
import { BaseProjectTreeItem } from '../models/tree/baseTreeItem';
|
||||||
import { ProjectRootTreeItem } from '../models/tree/projectTreeItem';
|
import { ProjectRootTreeItem } from '../models/tree/projectTreeItem';
|
||||||
import { ImportDataModel } from '../models/api/import';
|
import { ImportDataModel } from '../models/api/import';
|
||||||
@@ -244,8 +244,8 @@ export class ProjectsController {
|
|||||||
if (utils.getAzdataApi()) {
|
if (utils.getAzdataApi()) {
|
||||||
let publishDatabaseDialog = this.getPublishDialog(project);
|
let publishDatabaseDialog = this.getPublishDialog(project);
|
||||||
|
|
||||||
publishDatabaseDialog.publish = async (proj, prof) => this.publishProjectCallback(proj, prof);
|
publishDatabaseDialog.publish = async (proj, prof) => this.publishOrScriptProject(proj, prof, true);
|
||||||
publishDatabaseDialog.generateScript = async (proj, prof) => this.publishProjectCallback(proj, prof);
|
publishDatabaseDialog.generateScript = async (proj, prof) => this.publishOrScriptProject(proj, prof, false);
|
||||||
publishDatabaseDialog.readPublishProfile = async (profileUri) => readPublishProfile(profileUri);
|
publishDatabaseDialog.readPublishProfile = async (profileUri) => readPublishProfile(profileUri);
|
||||||
|
|
||||||
publishDatabaseDialog.openDialog();
|
publishDatabaseDialog.openDialog();
|
||||||
@@ -257,7 +257,14 @@ export class ProjectsController {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public async publishProjectCallback(project: Project, settings: IPublishSettings | IGenerateScriptSettings): Promise<mssql.DacFxResult | undefined> {
|
/**
|
||||||
|
* Builds and either deploys or generates a deployment script for the specified project.
|
||||||
|
* @param project The project to deploy
|
||||||
|
* @param settings The settings used to configure the deployment
|
||||||
|
* @param publish Whether to publish the deployment or just generate a script
|
||||||
|
* @returns The DacFx result of the deployment
|
||||||
|
*/
|
||||||
|
public async publishOrScriptProject(project: Project, settings: IDeploySettings, publish: boolean): Promise<mssql.DacFxResult | undefined> {
|
||||||
const telemetryProps: Record<string, string> = {};
|
const telemetryProps: Record<string, string> = {};
|
||||||
const telemetryMeasures: Record<string, number> = {};
|
const telemetryMeasures: Record<string, number> = {};
|
||||||
const buildStartTime = new Date().getTime();
|
const buildStartTime = new Date().getTime();
|
||||||
@@ -298,17 +305,16 @@ export class ProjectsController {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
const azdataApi = utils.getAzdataApi();
|
const azdataApi = utils.getAzdataApi();
|
||||||
if ((<IPublishSettings>settings).upgradeExisting) {
|
if (publish) {
|
||||||
telemetryProps.publishAction = 'deploy';
|
telemetryProps.publishAction = 'deploy';
|
||||||
if (azdataApi) {
|
if (azdataApi) {
|
||||||
result = await (dacFxService as mssql.IDacFxService).deployDacpac(tempPath, settings.databaseName, (<IPublishSettings>settings).upgradeExisting, settings.connectionUri, azdataApi.TaskExecutionMode.execute, settings.sqlCmdVariables, settings.deploymentOptions);
|
result = await (dacFxService as mssql.IDacFxService).deployDacpac(tempPath, settings.databaseName, true, settings.connectionUri, azdataApi.TaskExecutionMode.execute, settings.sqlCmdVariables, settings.deploymentOptions);
|
||||||
} else {
|
} else {
|
||||||
// TODO@chgagnon Fix typing
|
// TODO@chgagnon Fix typing
|
||||||
result = await (dacFxService as mssqlVscode.IDacFxService).deployDacpac(tempPath, settings.databaseName, (<IPublishSettings>settings).upgradeExisting, settings.connectionUri, <mssqlVscode.TaskExecutionMode><any>azdataApi!.TaskExecutionMode.execute, settings.sqlCmdVariables, <mssqlVscode.DeploymentOptions><any>settings.deploymentOptions);
|
result = await (dacFxService as mssqlVscode.IDacFxService).deployDacpac(tempPath, settings.databaseName, true, settings.connectionUri, <mssqlVscode.TaskExecutionMode><any>azdataApi!.TaskExecutionMode.execute, settings.sqlCmdVariables, <mssqlVscode.DeploymentOptions><any>settings.deploymentOptions);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
telemetryProps.publishAction = 'generateScript';
|
telemetryProps.publishAction = 'generateScript';
|
||||||
if (azdataApi) {
|
if (azdataApi) {
|
||||||
result = await (dacFxService as mssql.IDacFxService).generateDeployScript(tempPath, settings.databaseName, settings.connectionUri, azdataApi.TaskExecutionMode.script, settings.sqlCmdVariables, settings.deploymentOptions);
|
result = await (dacFxService as mssql.IDacFxService).generateDeployScript(tempPath, settings.databaseName, settings.connectionUri, azdataApi.TaskExecutionMode.script, settings.sqlCmdVariables, settings.deploymentOptions);
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ import * as utils from '../common/utils';
|
|||||||
|
|
||||||
import { Project } from '../models/project';
|
import { Project } from '../models/project';
|
||||||
import { SqlConnectionDataSource } from '../models/dataSources/sqlConnectionStringSource';
|
import { SqlConnectionDataSource } from '../models/dataSources/sqlConnectionStringSource';
|
||||||
import { IPublishSettings, IGenerateScriptSettings } from '../models/IPublishSettings';
|
import { IDeploySettings } from '../models/IDeploySettings';
|
||||||
import { DeploymentOptions, SchemaObjectType } from '../../../mssql/src/mssql';
|
import { DeploymentOptions, SchemaObjectType } from '../../../mssql/src/mssql';
|
||||||
import { IconPathHelper } from '../common/iconHelper';
|
import { IconPathHelper } from '../common/iconHelper';
|
||||||
import { cssStyles } from '../common/uiConstants';
|
import { cssStyles } from '../common/uiConstants';
|
||||||
@@ -46,8 +46,8 @@ export class PublishDatabaseDialog {
|
|||||||
|
|
||||||
private toDispose: vscode.Disposable[] = [];
|
private toDispose: vscode.Disposable[] = [];
|
||||||
|
|
||||||
public publish: ((proj: Project, profile: IPublishSettings) => any) | undefined;
|
public publish: ((proj: Project, profile: IDeploySettings) => any) | undefined;
|
||||||
public generateScript: ((proj: Project, profile: IGenerateScriptSettings) => any) | undefined;
|
public generateScript: ((proj: Project, profile: IDeploySettings) => any) | undefined;
|
||||||
public readPublishProfile: ((profileUri: vscode.Uri) => any) | undefined;
|
public readPublishProfile: ((profileUri: vscode.Uri) => any) | undefined;
|
||||||
|
|
||||||
constructor(private project: Project) {
|
constructor(private project: Project) {
|
||||||
@@ -182,10 +182,9 @@ export class PublishDatabaseDialog {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public async publishClick(): Promise<void> {
|
public async publishClick(): Promise<void> {
|
||||||
const settings: IPublishSettings = {
|
const settings: IDeploySettings = {
|
||||||
databaseName: this.getTargetDatabaseName(),
|
databaseName: this.getTargetDatabaseName(),
|
||||||
serverName: this.getServerName(),
|
serverName: this.getServerName(),
|
||||||
upgradeExisting: true,
|
|
||||||
connectionUri: await this.getConnectionUri(),
|
connectionUri: await this.getConnectionUri(),
|
||||||
sqlCmdVariables: this.getSqlCmdVariablesForPublish(),
|
sqlCmdVariables: this.getSqlCmdVariablesForPublish(),
|
||||||
deploymentOptions: await this.getDeploymentOptions(),
|
deploymentOptions: await this.getDeploymentOptions(),
|
||||||
@@ -202,7 +201,7 @@ export class PublishDatabaseDialog {
|
|||||||
TelemetryReporter.sendActionEvent(TelemetryViews.SqlProjectPublishDialog, TelemetryActions.generateScriptClicked);
|
TelemetryReporter.sendActionEvent(TelemetryViews.SqlProjectPublishDialog, TelemetryActions.generateScriptClicked);
|
||||||
|
|
||||||
const sqlCmdVars = this.getSqlCmdVariablesForPublish();
|
const sqlCmdVars = this.getSqlCmdVariablesForPublish();
|
||||||
const settings: IGenerateScriptSettings = {
|
const settings: IDeploySettings = {
|
||||||
databaseName: this.getTargetDatabaseName(),
|
databaseName: this.getTargetDatabaseName(),
|
||||||
serverName: this.getServerName(),
|
serverName: this.getServerName(),
|
||||||
connectionUri: await this.getConnectionUri(),
|
connectionUri: await this.getConnectionUri(),
|
||||||
@@ -213,9 +212,7 @@ export class PublishDatabaseDialog {
|
|||||||
|
|
||||||
utils.getAzdataApi()!.window.closeDialog(this.dialog);
|
utils.getAzdataApi()!.window.closeDialog(this.dialog);
|
||||||
|
|
||||||
if (this.generateScript) {
|
await this.generateScript?.(this.project, settings);
|
||||||
await this.generateScript!(this.project, settings);
|
|
||||||
}
|
|
||||||
|
|
||||||
this.dispose();
|
this.dispose();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,7 +5,6 @@
|
|||||||
|
|
||||||
import * as vscode from 'vscode';
|
import * as vscode from 'vscode';
|
||||||
import * as constants from '../common/constants';
|
import * as constants from '../common/constants';
|
||||||
import { IGenerateScriptSettings, IPublishSettings } from '../models/IPublishSettings';
|
|
||||||
import { Project } from '../models/project';
|
import { Project } from '../models/project';
|
||||||
import { PublishProfile, readPublishProfile } from '../models/publishProfile/publishProfile';
|
import { PublishProfile, readPublishProfile } from '../models/publishProfile/publishProfile';
|
||||||
import { promptForPublishProfile } from './publishDatabaseDialog';
|
import { promptForPublishProfile } from './publishDatabaseDialog';
|
||||||
@@ -188,17 +187,12 @@ export async function launchPublishDatabaseQuickpick(project: Project): Promise<
|
|||||||
|
|
||||||
// TODO@chgagnon: Get deployment options
|
// TODO@chgagnon: Get deployment options
|
||||||
// 6. Generate script/publish
|
// 6. Generate script/publish
|
||||||
let settings: IPublishSettings | IGenerateScriptSettings = {
|
// let settings: IDeploySettings | IGenerateScriptSettings = {
|
||||||
databaseName: databaseName,
|
// databaseName: databaseName,
|
||||||
serverName: '', // TODO@chgagnon: Get from connection profile
|
// serverName: connectionProfile!.server,
|
||||||
connectionUri: '', // TODO@chgagnon: Get from connection profile
|
// connectionUri: '', // TODO@chgagnon: Get from connection profile
|
||||||
sqlCmdVariables: undefined, // this.getSqlCmdVariablesForPublish(),
|
// sqlCmdVariables: sqlCmdVariables,
|
||||||
deploymentOptions: undefined, // await this.getDeploymentOptions(),
|
// deploymentOptions: undefined, // await this.getDeploymentOptions(),
|
||||||
profileUsed: true, // this.profileUsed,
|
// profileUsed: !!publishProfile
|
||||||
};
|
// };
|
||||||
|
|
||||||
// TODO@chgagnon Consolidate creation of the settings into one place
|
|
||||||
if (action === constants.publish) {
|
|
||||||
(settings as IPublishSettings).upgradeExisting = true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,17 +5,7 @@
|
|||||||
|
|
||||||
import { DeploymentOptions } from '../../../mssql/src/mssql';
|
import { DeploymentOptions } from '../../../mssql/src/mssql';
|
||||||
|
|
||||||
export interface IPublishSettings {
|
export interface IDeploySettings {
|
||||||
databaseName: string;
|
|
||||||
serverName: string;
|
|
||||||
connectionUri: string;
|
|
||||||
upgradeExisting: boolean;
|
|
||||||
sqlCmdVariables?: Record<string, string>;
|
|
||||||
deploymentOptions?: DeploymentOptions;
|
|
||||||
profileUsed?: boolean;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface IGenerateScriptSettings {
|
|
||||||
databaseName: string;
|
databaseName: string;
|
||||||
serverName: string;
|
serverName: string;
|
||||||
connectionUri: string;
|
connectionUri: string;
|
||||||
@@ -15,7 +15,7 @@ import * as TypeMoq from 'typemoq';
|
|||||||
import { PublishDatabaseDialog } from '../../dialogs/publishDatabaseDialog';
|
import { PublishDatabaseDialog } from '../../dialogs/publishDatabaseDialog';
|
||||||
import { Project } from '../../models/project';
|
import { Project } from '../../models/project';
|
||||||
import { ProjectsController } from '../../controllers/projectController';
|
import { ProjectsController } from '../../controllers/projectController';
|
||||||
import { IPublishSettings, IGenerateScriptSettings } from '../../models/IPublishSettings';
|
import { IDeploySettings } from '../../models/IDeploySettings';
|
||||||
import { emptySqlDatabaseProjectTypeId } from '../../common/constants';
|
import { emptySqlDatabaseProjectTypeId } from '../../common/constants';
|
||||||
import { mockDacFxOptionsResult } from '../testContext';
|
import { mockDacFxOptionsResult } from '../testContext';
|
||||||
|
|
||||||
@@ -70,13 +70,12 @@ describe('Publish Database Dialog', () => {
|
|||||||
dialog.setup(x => x.getServerName()).returns(() => 'MockServer');
|
dialog.setup(x => x.getServerName()).returns(() => 'MockServer');
|
||||||
dialog.callBase = true;
|
dialog.callBase = true;
|
||||||
|
|
||||||
let profile: IPublishSettings | IGenerateScriptSettings | undefined;
|
let profile: IDeploySettings | undefined;
|
||||||
|
|
||||||
const expectedPublish: IPublishSettings = {
|
const expectedPublish: IDeploySettings = {
|
||||||
databaseName: 'MockDatabaseName',
|
databaseName: 'MockDatabaseName',
|
||||||
serverName: 'MockServer',
|
serverName: 'MockServer',
|
||||||
connectionUri: 'Mock|Connection|Uri',
|
connectionUri: 'Mock|Connection|Uri',
|
||||||
upgradeExisting: true,
|
|
||||||
sqlCmdVariables: {
|
sqlCmdVariables: {
|
||||||
'ProdDatabaseName': 'MyProdDatabase',
|
'ProdDatabaseName': 'MyProdDatabase',
|
||||||
'BackupDatabaseName': 'MyBackupDatabase'
|
'BackupDatabaseName': 'MyBackupDatabase'
|
||||||
@@ -90,7 +89,7 @@ describe('Publish Database Dialog', () => {
|
|||||||
|
|
||||||
should(profile).deepEqual(expectedPublish);
|
should(profile).deepEqual(expectedPublish);
|
||||||
|
|
||||||
const expectedGenScript: IGenerateScriptSettings = {
|
const expectedGenScript: IDeploySettings = {
|
||||||
databaseName: 'MockDatabaseName',
|
databaseName: 'MockDatabaseName',
|
||||||
serverName: 'MockServer',
|
serverName: 'MockServer',
|
||||||
connectionUri: 'Mock|Connection|Uri',
|
connectionUri: 'Mock|Connection|Uri',
|
||||||
|
|||||||
@@ -23,7 +23,6 @@ import { promises as fs } from 'fs';
|
|||||||
import { createContext, TestContext, mockDacFxResult, mockConnectionProfile } from './testContext';
|
import { createContext, TestContext, mockDacFxResult, mockConnectionProfile } from './testContext';
|
||||||
import { Project, reservedProjectFolders, SystemDatabase, FileProjectEntry, SystemDatabaseReferenceProjectEntry } from '../models/project';
|
import { Project, reservedProjectFolders, SystemDatabase, FileProjectEntry, SystemDatabaseReferenceProjectEntry } from '../models/project';
|
||||||
import { PublishDatabaseDialog } from '../dialogs/publishDatabaseDialog';
|
import { PublishDatabaseDialog } from '../dialogs/publishDatabaseDialog';
|
||||||
import { IPublishSettings, IGenerateScriptSettings } from '../models/IPublishSettings';
|
|
||||||
import { ProjectRootTreeItem } from '../models/tree/projectTreeItem';
|
import { ProjectRootTreeItem } from '../models/tree/projectTreeItem';
|
||||||
import { FolderNode, FileNode } from '../models/tree/fileFolderTreeItem';
|
import { FolderNode, FileNode } from '../models/tree/fileFolderTreeItem';
|
||||||
import { BaseProjectTreeItem } from '../models/tree/baseTreeItem';
|
import { BaseProjectTreeItem } from '../models/tree/baseTreeItem';
|
||||||
@@ -386,12 +385,12 @@ describe('ProjectsController', function (): void {
|
|||||||
let projController = TypeMoq.Mock.ofType(ProjectsController);
|
let projController = TypeMoq.Mock.ofType(ProjectsController);
|
||||||
projController.callBase = true;
|
projController.callBase = true;
|
||||||
projController.setup(x => x.getPublishDialog(TypeMoq.It.isAny())).returns(() => publishDialog.object);
|
projController.setup(x => x.getPublishDialog(TypeMoq.It.isAny())).returns(() => publishDialog.object);
|
||||||
projController.setup(x => x.publishProjectCallback(TypeMoq.It.isAny(), TypeMoq.It.is((_): _ is IPublishSettings => true))).returns(() => {
|
projController.setup(x => x.publishOrScriptProject(TypeMoq.It.isAny(), TypeMoq.It.isAny(), true)).returns(() => {
|
||||||
holler = publishHoller;
|
holler = publishHoller;
|
||||||
return Promise.resolve(undefined);
|
return Promise.resolve(undefined);
|
||||||
});
|
});
|
||||||
|
|
||||||
projController.setup(x => x.publishProjectCallback(TypeMoq.It.isAny(), TypeMoq.It.is((_): _ is IGenerateScriptSettings => true))).returns(() => {
|
projController.setup(x => x.publishOrScriptProject(TypeMoq.It.isAny(), TypeMoq.It.isAny(), false)).returns(() => {
|
||||||
holler = generateHoller;
|
holler = generateHoller;
|
||||||
return Promise.resolve(undefined);
|
return Promise.resolve(undefined);
|
||||||
});
|
});
|
||||||
@@ -430,7 +429,7 @@ describe('ProjectsController', function (): void {
|
|||||||
|
|
||||||
const proj = await testUtils.createTestProject(baselines.openProjectFileBaseline);
|
const proj = await testUtils.createTestProject(baselines.openProjectFileBaseline);
|
||||||
|
|
||||||
await projController.object.publishProjectCallback(proj, { connectionUri: '', databaseName: '' , serverName: ''});
|
await projController.object.publishOrScriptProject(proj, { connectionUri: '', databaseName: '' , serverName: ''}, false);
|
||||||
|
|
||||||
should(builtDacpacPath).not.equal('', 'built dacpac path should be set');
|
should(builtDacpacPath).not.equal('', 'built dacpac path should be set');
|
||||||
should(publishedDacpacPath).not.equal('', 'published dacpac path should be set');
|
should(publishedDacpacPath).not.equal('', 'published dacpac path should be set');
|
||||||
|
|||||||
Reference in New Issue
Block a user