Splitting out default DacFx options for Publish and Schema Compare (#1126)

* Splitting out schema comp and publish defaults

* Added test

* Correcting comments, changing scope

* Moving DeploymentOptions to DacFx folder due to dependency hierarchy between DacFx and SchemaCompare
This commit is contained in:
Benjin Dubishar
2020-11-25 14:44:34 -08:00
committed by GitHub
parent 4f42b17226
commit 25c542319e
10 changed files with 130 additions and 38 deletions

View File

@@ -2,11 +2,13 @@
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
//
using System;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.SqlServer.Dac;
namespace Microsoft.SqlTools.ServiceLayer.SchemaCompare.Contracts
namespace Microsoft.SqlTools.ServiceLayer.DacFx.Contracts
{
/// <summary>
/// Class to define deployment options.
@@ -15,6 +17,8 @@ namespace Microsoft.SqlTools.ServiceLayer.SchemaCompare.Contracts
/// </summary>
public class DeploymentOptions
{
#region Properties
public bool IgnoreTableOptions { get; set; }
public bool IgnoreSemicolonBetweenStatements { get; set; }
@@ -209,6 +213,8 @@ namespace Microsoft.SqlTools.ServiceLayer.SchemaCompare.Contracts
ObjectType.AssemblyFiles,
};
#endregion
public DeploymentOptions()
{
DacDeployOptions options = new DacDeployOptions();
@@ -297,5 +303,19 @@ namespace Microsoft.SqlTools.ServiceLayer.SchemaCompare.Contracts
}
}
}
public static DeploymentOptions GetDefaultSchemaCompareOptions()
{
return new DeploymentOptions();
}
public static DeploymentOptions GetDefaultPublishOptions()
{
DeploymentOptions result = new DeploymentOptions();
result.ExcludeObjectTypes = result.ExcludeObjectTypes.Where(x => x != ObjectType.DatabaseScopedCredentials).ToArray(); // re-include database-scoped credentials
return result;
}
}
}

View File

@@ -0,0 +1,27 @@
//
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
//
using System.Collections.Generic;
using Microsoft.SqlTools.Hosting.Protocol.Contracts;
using Microsoft.SqlTools.ServiceLayer.SchemaCompare.Contracts;
using Microsoft.SqlTools.ServiceLayer.Utility;
namespace Microsoft.SqlTools.ServiceLayer.DacFx.Contracts
{
/// <summary>
/// Parameters for a DacFx get default publish options request.
/// </summary>
public class GetDefaultPublishOptionsParams
{
}
/// <summary>
/// Defines the DacFx get default publish options request type
/// </summary>
class GetDefaultPublishOptionsRequest
{
public static readonly RequestType<GetDefaultPublishOptionsParams, DacFxOptionsResult> Type =
RequestType<GetDefaultPublishOptionsParams, DacFxOptionsResult>.Create("dacfx/getDefaultPublishOptions");
}
}

View File

@@ -10,7 +10,6 @@ using Microsoft.SqlTools.Hosting.Protocol;
using Microsoft.SqlTools.ServiceLayer.Connection;
using Microsoft.SqlTools.ServiceLayer.DacFx.Contracts;
using Microsoft.SqlTools.ServiceLayer.Hosting;
using Microsoft.SqlTools.ServiceLayer.SchemaCompare.Contracts;
using Microsoft.SqlTools.ServiceLayer.TaskServices;
namespace Microsoft.SqlTools.ServiceLayer.DacFx
@@ -48,6 +47,7 @@ namespace Microsoft.SqlTools.ServiceLayer.DacFx
serviceHost.SetRequestHandler(GenerateDeployPlanRequest.Type, this.HandleGenerateDeployPlanRequest);
serviceHost.SetRequestHandler(GetOptionsFromProfileRequest.Type, this.HandleGetOptionsFromProfileRequest);
serviceHost.SetRequestHandler(ValidateStreamingJobRequest.Type, this.HandleValidateStreamingJobRequest);
serviceHost.SetRequestHandler(GetDefaultPublishOptionsRequest.Type, this.HandleGetDefaultPublishOptionsRequest);
}
/// <summary>
@@ -239,7 +239,7 @@ namespace Microsoft.SqlTools.ServiceLayer.DacFx
DacProfile profile = DacProfile.Load(parameters.ProfilePath);
if (profile.DeployOptions != null)
{
options = new DeploymentOptions();
options = DeploymentOptions.GetDefaultPublishOptions();
await options.InitializeFromProfile(profile.DeployOptions, parameters.ProfilePath);
}
}
@@ -276,6 +276,35 @@ namespace Microsoft.SqlTools.ServiceLayer.DacFx
}
}
/// <summary>
/// Handles request to create default publish options for DacFx
/// </summary>
/// <returns></returns>
public async Task HandleGetDefaultPublishOptionsRequest(GetDefaultPublishOptionsParams parameters, RequestContext<DacFxOptionsResult> requestContext)
{
try
{
// this does not need to be an async operation since this only creates and returns the default object
DeploymentOptions options = DeploymentOptions.GetDefaultPublishOptions();
await requestContext.SendResult(new DacFxOptionsResult()
{
DeploymentOptions = options,
Success = true,
ErrorMessage = null
});
}
catch (Exception e)
{
await requestContext.SendResult(new DacFxOptionsResult()
{
DeploymentOptions = null,
Success = false,
ErrorMessage = e.Message
});
}
}
private void ExecuteOperation(DacFxOperation operation, DacFxParams parameters, string taskName, RequestContext<DacFxResult> requestContext)
{
Task.Run(async () =>

View File

@@ -2,10 +2,10 @@
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
//
using Microsoft.SqlTools.Hosting.Protocol.Contracts;
using Microsoft.SqlTools.ServiceLayer.TaskServices;
using Microsoft.SqlTools.ServiceLayer.Utility;
using System.Collections.Generic;
using Microsoft.SqlTools.Hosting.Protocol.Contracts;
using Microsoft.SqlTools.ServiceLayer.DacFx.Contracts;
using Microsoft.SqlTools.ServiceLayer.Utility;
namespace Microsoft.SqlTools.ServiceLayer.SchemaCompare.Contracts
{

View File

@@ -4,6 +4,7 @@
//
using Microsoft.SqlTools.Hosting.Protocol.Contracts;
using Microsoft.SqlTools.ServiceLayer.DacFx.Contracts;
using Microsoft.SqlTools.ServiceLayer.Utility;
namespace Microsoft.SqlTools.ServiceLayer.SchemaCompare.Contracts

View File

@@ -2,12 +2,13 @@
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
//
using System.Collections.Generic;
using Microsoft.SqlServer.Dac.Compare;
using Microsoft.SqlTools.Hosting.Protocol.Contracts;
using Microsoft.SqlTools.ServiceLayer.Connection.Contracts;
using Microsoft.SqlTools.ServiceLayer.DacFx.Contracts;
using Microsoft.SqlTools.ServiceLayer.TaskServices;
using Microsoft.SqlTools.ServiceLayer.Utility;
using System.Collections.Generic;
namespace Microsoft.SqlTools.ServiceLayer.SchemaCompare.Contracts
{

View File

@@ -2,20 +2,17 @@
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
//
using Microsoft.SqlServer.Dac;
using Microsoft.SqlServer.Dac.Compare;
using Microsoft.SqlTools.ServiceLayer.Connection;
using Microsoft.SqlTools.ServiceLayer.SchemaCompare.Contracts;
using Microsoft.SqlTools.ServiceLayer.TaskServices;
using Microsoft.SqlTools.Utility;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text.RegularExpressions;
using System.Threading;
using System.Xml;
using System.Xml.Linq;
using Microsoft.SqlServer.Dac.Compare;
using Microsoft.SqlTools.ServiceLayer.DacFx.Contracts;
using Microsoft.SqlTools.ServiceLayer.SchemaCompare.Contracts;
using Microsoft.SqlTools.ServiceLayer.TaskServices;
using Microsoft.SqlTools.Utility;
namespace Microsoft.SqlTools.ServiceLayer.SchemaCompare
{

View File

@@ -2,19 +2,19 @@
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
//
using Microsoft.SqlTools.Hosting.Protocol;
using Microsoft.SqlTools.ServiceLayer.Connection;
using Microsoft.SqlTools.ServiceLayer.SchemaCompare.Contracts;
using Microsoft.SqlTools.ServiceLayer.Hosting;
using Microsoft.SqlTools.ServiceLayer.TaskServices;
using System;
using System.Collections.Concurrent;
using System.Diagnostics;
using System.Threading.Tasks;
using Microsoft.SqlServer.Dac.Compare;
using Microsoft.SqlTools.Hosting.Protocol;
using Microsoft.SqlTools.ServiceLayer.Connection;
using Microsoft.SqlTools.ServiceLayer.DacFx.Contracts;
using Microsoft.SqlTools.ServiceLayer.Hosting;
using Microsoft.SqlTools.ServiceLayer.SchemaCompare.Contracts;
using Microsoft.SqlTools.ServiceLayer.TaskServices;
using Microsoft.SqlTools.ServiceLayer.Utility;
using Microsoft.SqlTools.Utility;
using System.Diagnostics;
using System.Threading;
namespace Microsoft.SqlTools.ServiceLayer.SchemaCompare
{
@@ -278,8 +278,8 @@ namespace Microsoft.SqlTools.ServiceLayer.SchemaCompare
{
try
{
// this does not need to be an async operation since this only creates and resturn the default opbject
DeploymentOptions options = new DeploymentOptions();
// this does not need to be an async operation since this only creates and returns the default object
DeploymentOptions options = DeploymentOptions.GetDefaultSchemaCompareOptions();
await requestContext.SendResult(new SchemaCompareOptionsResult()
{

View File

@@ -2,16 +2,17 @@
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
//
using Microsoft.SqlServer.Dac;
using Microsoft.SqlServer.Dac.Compare;
using Microsoft.SqlServer.Dac.Model;
using Microsoft.SqlTools.ServiceLayer.Connection;
using Microsoft.SqlTools.ServiceLayer.SchemaCompare.Contracts;
using Microsoft.SqlTools.ServiceLayer.Utility;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
using Microsoft.SqlServer.Dac;
using Microsoft.SqlServer.Dac.Compare;
using Microsoft.SqlServer.Dac.Model;
using Microsoft.SqlTools.ServiceLayer.Connection;
using Microsoft.SqlTools.ServiceLayer.DacFx.Contracts;
using Microsoft.SqlTools.ServiceLayer.SchemaCompare.Contracts;
using Microsoft.SqlTools.ServiceLayer.Utility;
namespace Microsoft.SqlTools.ServiceLayer.SchemaCompare
{

View File

@@ -725,13 +725,12 @@ FROM MissingEdgeHubInputStream'";
[Test]
public async Task GetOptionsFromProfile()
{
DeploymentOptions expectedResults = new DeploymentOptions()
{
ExcludeObjectTypes = null,
IncludeCompositeObjects = true,
BlockOnPossibleDataLoss = true,
AllowIncompatiblePlatform = true
};
DeploymentOptions expectedResults = DeploymentOptions.GetDefaultPublishOptions();
expectedResults.ExcludeObjectTypes = null;
expectedResults.IncludeCompositeObjects = true;
expectedResults.BlockOnPossibleDataLoss = true;
expectedResults.AllowIncompatiblePlatform = true;
var dacfxRequestContext = new Mock<RequestContext<DacFxOptionsResult>>();
dacfxRequestContext.Setup((RequestContext<DacFxOptionsResult> x) => x.SendResult(It.Is<DacFxOptionsResult>((result) => ValidateOptions(expectedResults, result.DeploymentOptions) == true))).Returns(Task.FromResult(new object()));
@@ -754,7 +753,7 @@ FROM MissingEdgeHubInputStream'";
[Test]
public async Task GetOptionsFromProfileWithoutOptions()
{
DeploymentOptions expectedResults = new DeploymentOptions();
DeploymentOptions expectedResults = DeploymentOptions.GetDefaultPublishOptions();
expectedResults.ExcludeObjectTypes = null;
var dacfxRequestContext = new Mock<RequestContext<DacFxOptionsResult>>();
@@ -772,6 +771,23 @@ FROM MissingEdgeHubInputStream'";
dacfxRequestContext.VerifyAll();
}
/// <summary>
/// Verify the default dacFx options for publishing
/// </summary>
[Test]
public async Task ValidateGetDefaultPublishOptionsCallFromService()
{
DeploymentOptions expectedResults = DeploymentOptions.GetDefaultPublishOptions();
var dacfxRequestContext = new Mock<RequestContext<DacFxOptionsResult>>();
dacfxRequestContext.Setup((RequestContext<DacFxOptionsResult> x) => x.SendResult(It.Is<DacFxOptionsResult>((result) => ValidateOptions(expectedResults, result.DeploymentOptions) == true))).Returns(Task.FromResult(new object()));
GetDefaultPublishOptionsParams p = new GetDefaultPublishOptionsParams();
DacFxService service = new DacFxService();
await service.HandleGetDefaultPublishOptionsRequest(p, dacfxRequestContext.Object);
}
/// <summary>
/// Verify that streaming job
/// </summary>