mirror of
https://github.com/ckaczor/sqltoolsservice.git
synced 2026-01-18 01:25:41 -05:00
Schema compare include/exclude changes (#881)
* send back success of include/exclude request * update dacfx nuget package and use new api to get affected dependencies of include/exclude request * addressing comments * rename test * Addressing comments
This commit is contained in:
@@ -20,7 +20,7 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.SqlServer.DacFx" Version="150.4534.2-preview" />
|
||||
<PackageReference Include="Microsoft.SqlServer.DacFx" Version="150.4576.1-preview" />
|
||||
<PackageReference Include="System.Text.Encoding.CodePages" Version="4.6.0-preview3-26501-04" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
using Microsoft.SqlTools.Hosting.Protocol.Contracts;
|
||||
using Microsoft.SqlTools.ServiceLayer.TaskServices;
|
||||
using Microsoft.SqlTools.ServiceLayer.Utility;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Microsoft.SqlTools.ServiceLayer.SchemaCompare.Contracts
|
||||
{
|
||||
@@ -40,4 +41,12 @@ namespace Microsoft.SqlTools.ServiceLayer.SchemaCompare.Contracts
|
||||
public static readonly RequestType<SchemaCompareNodeParams, ResultStatus> Type =
|
||||
RequestType<SchemaCompareNodeParams, ResultStatus>.Create("schemaCompare/includeExcludeNode");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Parameters returned from a schema compare include/exclude request.
|
||||
/// </summary>
|
||||
public class SchemaCompareIncludeExcludeResult : ResultStatus
|
||||
{
|
||||
public List<DiffEntry> ChangedDifferences { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -101,6 +101,7 @@ namespace Microsoft.SqlTools.ServiceLayer.SchemaCompare.Contracts
|
||||
public string TargetScript { get; set; }
|
||||
public string SourceObjectType { get; set; }
|
||||
public string TargetObjectType { get; set; }
|
||||
public bool Included { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -10,6 +10,7 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Threading;
|
||||
using System.Linq;
|
||||
|
||||
namespace Microsoft.SqlTools.ServiceLayer.SchemaCompare
|
||||
{
|
||||
@@ -38,6 +39,8 @@ namespace Microsoft.SqlTools.ServiceLayer.SchemaCompare
|
||||
|
||||
public bool Success { get; set; }
|
||||
|
||||
public List<DiffEntry> ChangedDifferences;
|
||||
|
||||
public SchemaCompareIncludeExcludeNodeOperation(SchemaCompareNodeParams parameters, SchemaComparisonResult comparisonResult)
|
||||
{
|
||||
Validate.IsNotNull("parameters", parameters);
|
||||
@@ -46,6 +49,11 @@ namespace Microsoft.SqlTools.ServiceLayer.SchemaCompare
|
||||
this.ComparisonResult = comparisonResult;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Exclude will return false if included dependencies are found. Include will also include dependencies that need to be included.
|
||||
/// This is the same behavior as SSDT
|
||||
/// </summary>
|
||||
/// <param name="mode"></param>
|
||||
public void Execute(TaskExecutionMode mode)
|
||||
{
|
||||
this.CancellationToken.ThrowIfCancellationRequested();
|
||||
@@ -58,7 +66,27 @@ namespace Microsoft.SqlTools.ServiceLayer.SchemaCompare
|
||||
throw new InvalidOperationException(SR.SchemaCompareExcludeIncludeNodeNotFound);
|
||||
}
|
||||
|
||||
// Check first if the dependencies will allow this if it's an exclude request
|
||||
if (!this.Parameters.IncludeRequest)
|
||||
{
|
||||
IEnumerable<SchemaDifference> dependencies = this.ComparisonResult.GetExcludeDependencies(node);
|
||||
|
||||
bool block = dependencies.Any(d => d.Included);
|
||||
if (block)
|
||||
{
|
||||
this.Success = false;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
this.Success = this.Parameters.IncludeRequest ? this.ComparisonResult.Include(node) : this.ComparisonResult.Exclude(node);
|
||||
|
||||
// create list of affected dependencies of this request
|
||||
if (this.Success)
|
||||
{
|
||||
IEnumerable<SchemaDifference> dependencies = this.ComparisonResult.GetIncludeDependencies(node);
|
||||
this.ChangedDifferences = dependencies.Select(difference => SchemaCompareUtils.CreateDiffEntry(difference, null)).ToList();
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
@@ -97,10 +125,16 @@ namespace Microsoft.SqlTools.ServiceLayer.SchemaCompare
|
||||
System.Reflection.PropertyInfo[] properties = diffEntry.GetType().GetProperties();
|
||||
foreach (var prop in properties)
|
||||
{
|
||||
result = result &&
|
||||
((prop.GetValue(diffEntry) == null &&
|
||||
prop.GetValue(entryFromDifference) == null) ||
|
||||
prop.GetValue(diffEntry).SafeToString().Equals(prop.GetValue(entryFromDifference).SafeToString()));
|
||||
// Don't need to check if included is the same when verifying if the difference is equal
|
||||
if (prop.Name != "Included")
|
||||
{
|
||||
if(!((prop.GetValue(diffEntry) == null &&
|
||||
prop.GetValue(entryFromDifference) == null) ||
|
||||
prop.GetValue(diffEntry).SafeToString().Equals(prop.GetValue(entryFromDifference).SafeToString())))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
|
||||
@@ -245,10 +245,17 @@ namespace Microsoft.SqlTools.ServiceLayer.SchemaCompare
|
||||
|
||||
operation.Execute(parameters.TaskExecutionMode);
|
||||
|
||||
await requestContext.SendResult(new ResultStatus()
|
||||
// update the comparison result if the include/exclude was successful
|
||||
if(operation.Success)
|
||||
{
|
||||
Success = true,
|
||||
ErrorMessage = operation.ErrorMessage
|
||||
schemaCompareResults.Value[parameters.OperationId] = operation.ComparisonResult;
|
||||
}
|
||||
|
||||
await requestContext.SendResult(new SchemaCompareIncludeExcludeResult()
|
||||
{
|
||||
Success = operation.Success,
|
||||
ErrorMessage = operation.ErrorMessage,
|
||||
ChangedDifferences = operation.ChangedDifferences
|
||||
});
|
||||
}
|
||||
catch (Exception e)
|
||||
|
||||
@@ -48,6 +48,7 @@ namespace Microsoft.SqlTools.ServiceLayer.SchemaCompare
|
||||
diffEntry.UpdateAction = difference.UpdateAction;
|
||||
diffEntry.DifferenceType = difference.DifferenceType;
|
||||
diffEntry.Name = difference.Name;
|
||||
diffEntry.Included = difference.Included;
|
||||
|
||||
if (difference.SourceObject != null)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user