Fix for schema compare dropping constraints (#2120)

* fix for scripts that are displayed in schema compare drop constraints bug

* update DacFx version

* add more comments
This commit is contained in:
Kim Santiago
2023-06-26 14:01:28 -10:00
committed by GitHub
parent 9034b397ac
commit 95a094438e
5 changed files with 34 additions and 18 deletions

View File

@@ -71,21 +71,21 @@ namespace Microsoft.SqlTools.ServiceLayer.SchemaCompare
if(this.Parameters.IncludeRequest)
{
IEnumerable<SchemaDifference> affectedDependencies = this.ComparisonResult.GetIncludeDependencies(node);
this.AffectedDependencies = affectedDependencies.Select(difference => SchemaCompareUtils.CreateDiffEntry(difference: difference, parent: null)).ToList();
this.AffectedDependencies = affectedDependencies.Select(difference => SchemaCompareUtils.CreateDiffEntry(difference: difference, parent: null, schemaComparisonResult: this.ComparisonResult)).ToList();
}
else
{ // if exclude was successful, the possible affected dependencies are given by GetIncludedDependencies()
if(this.Success)
{
IEnumerable<SchemaDifference> affectedDependencies = this.ComparisonResult.GetIncludeDependencies(node);
this.AffectedDependencies = affectedDependencies.Select(difference => SchemaCompareUtils.CreateDiffEntry(difference: difference, parent: null)).ToList();
this.AffectedDependencies = affectedDependencies.Select(difference => SchemaCompareUtils.CreateDiffEntry(difference: difference, parent: null, schemaComparisonResult: this.ComparisonResult)).ToList();
}
// if not successful, send back the exclude dependencies that caused it to fail
else
{
IEnumerable<SchemaDifference> blockingDependencies = this.ComparisonResult.GetExcludeDependencies(node);
blockingDependencies = blockingDependencies.Where(difference => difference.Included == node.Included);
this.BlockingDependencies = blockingDependencies.Select(difference => SchemaCompareUtils.CreateDiffEntry(difference: difference, parent: null)).ToList();
this.BlockingDependencies = blockingDependencies.Select(difference => SchemaCompareUtils.CreateDiffEntry(difference: difference, parent: null, schemaComparisonResult: this.ComparisonResult)).ToList();
}
}
@@ -122,7 +122,7 @@ namespace Microsoft.SqlTools.ServiceLayer.SchemaCompare
{
bool result = true;
// Create a diff entry from difference and check if it matches the diff entry passed
DiffEntry entryFromDifference = SchemaCompareUtils.CreateDiffEntry(difference, null);
DiffEntry entryFromDifference = SchemaCompareUtils.CreateDiffEntry(difference, null, schemaComparisonResult: this.ComparisonResult);
System.Reflection.PropertyInfo[] properties = diffEntry.GetType().GetProperties();
foreach (var prop in properties)

View File

@@ -121,7 +121,7 @@ namespace Microsoft.SqlTools.ServiceLayer.SchemaCompare
foreach (SchemaDifference difference in this.ComparisonResult.Differences)
{
DiffEntry diffEntry = SchemaCompareUtils.CreateDiffEntry(difference, null);
DiffEntry diffEntry = SchemaCompareUtils.CreateDiffEntry(difference, null, this.ComparisonResult);
this.Differences.Add(diffEntry);
}
}

View File

@@ -24,7 +24,7 @@ namespace Microsoft.SqlTools.ServiceLayer.SchemaCompare
/// </summary>
internal static partial class SchemaCompareUtils
{
internal static DiffEntry CreateDiffEntry(SchemaDifference difference, DiffEntry parent)
internal static DiffEntry CreateDiffEntry(SchemaDifference difference, DiffEntry parent, SchemaComparisonResult schemaComparisonResult)
{
if (difference == null)
{
@@ -56,15 +56,31 @@ namespace Microsoft.SqlTools.ServiceLayer.SchemaCompare
// set source and target scripts
if (difference.SourceObject != null)
{
string sourceScript;
difference.SourceObject.TryGetScript(out sourceScript);
diffEntry.SourceScript = FormatScript(sourceScript);
string sourceScript = schemaComparisonResult.GetDiffEntrySourceScript(difference);
// Child scripts that do not use alter need to be added if they are being changed, ex: "EXECUTE sp_addextendedproperty...".
// Don't add scripts that start with alter because those are handled by a top level element's create
// ex: if a column changes, then the parent table's script will have the column updated, but GetDiffEntrySourceScript() on the child
// will return an alter table statement for updating that column when getting the child script. The child's alter script is unecessary
// for displaying the script in schema compare because the comparison displays the create scripts
if (!sourceScript.ToLowerInvariant().StartsWith("alter"))
{
diffEntry.SourceScript = FormatScript(sourceScript);
}
}
if (difference.TargetObject != null)
{
string targetScript;
difference.TargetObject.TryGetScript(out targetScript);
diffEntry.TargetScript = FormatScript(targetScript);
string targetScript = schemaComparisonResult.GetDiffEntryTargetScript(difference);
// Child scripts that do not use alter need to be added if they are being changed, ex: "EXECUTE sp_addextendedproperty...".
// Don't add scripts that start with alter because those are handled by a top level element's create
// ex: if a column changes, then the parent table's script will have the column updated, but GetDiffEntrySourceScript() on the child
// will return an alter table script for updating that column when getting the child script. The child's alter script is unecessary
// for displaying the script in schema compare because the comparison displays the create scripts
if (!targetScript.ToLowerInvariant().StartsWith("alter"))
{
diffEntry.TargetScript = FormatScript(targetScript);
}
}
}
@@ -72,7 +88,7 @@ namespace Microsoft.SqlTools.ServiceLayer.SchemaCompare
foreach (SchemaDifference child in difference.Children)
{
diffEntry.Children.Add(CreateDiffEntry(child, diffEntry));
diffEntry.Children.Add(CreateDiffEntry(child, diffEntry, schemaComparisonResult));
}
return diffEntry;