mirror of
https://github.com/ckaczor/sqltoolsservice.git
synced 2026-02-16 10:58:30 -05:00
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:
@@ -22,7 +22,7 @@
|
|||||||
|
|
||||||
<PackageReference Update="Microsoft.Data.SqlClient.AlwaysEncrypted.AzureKeyVaultProvider" Version="1.1.1" />
|
<PackageReference Update="Microsoft.Data.SqlClient.AlwaysEncrypted.AzureKeyVaultProvider" Version="1.1.1" />
|
||||||
<PackageReference Update="Microsoft.SqlServer.Management.SmoMetadataProvider" Version="170.12.0" />
|
<PackageReference Update="Microsoft.SqlServer.Management.SmoMetadataProvider" Version="170.12.0" />
|
||||||
<PackageReference Update="Microsoft.SqlServer.DacFx" Version="162.0.34-preview" />
|
<PackageReference Update="Microsoft.SqlServer.DacFx" Version="162.1.59-preview" />
|
||||||
<PackageReference Update="Microsoft.SqlServer.DacFx.Projects" Version="162.1.37-alpha" />
|
<PackageReference Update="Microsoft.SqlServer.DacFx.Projects" Version="162.1.37-alpha" />
|
||||||
<PackageReference Update="Microsoft.Azure.Kusto.Data" Version="9.0.4" />
|
<PackageReference Update="Microsoft.Azure.Kusto.Data" Version="9.0.4" />
|
||||||
<PackageReference Update="Microsoft.Azure.Kusto.Language" Version="9.0.4" />
|
<PackageReference Update="Microsoft.Azure.Kusto.Language" Version="9.0.4" />
|
||||||
|
|||||||
@@ -71,21 +71,21 @@ namespace Microsoft.SqlTools.ServiceLayer.SchemaCompare
|
|||||||
if(this.Parameters.IncludeRequest)
|
if(this.Parameters.IncludeRequest)
|
||||||
{
|
{
|
||||||
IEnumerable<SchemaDifference> affectedDependencies = this.ComparisonResult.GetIncludeDependencies(node);
|
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
|
else
|
||||||
{ // if exclude was successful, the possible affected dependencies are given by GetIncludedDependencies()
|
{ // if exclude was successful, the possible affected dependencies are given by GetIncludedDependencies()
|
||||||
if(this.Success)
|
if(this.Success)
|
||||||
{
|
{
|
||||||
IEnumerable<SchemaDifference> affectedDependencies = this.ComparisonResult.GetIncludeDependencies(node);
|
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
|
// if not successful, send back the exclude dependencies that caused it to fail
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
IEnumerable<SchemaDifference> blockingDependencies = this.ComparisonResult.GetExcludeDependencies(node);
|
IEnumerable<SchemaDifference> blockingDependencies = this.ComparisonResult.GetExcludeDependencies(node);
|
||||||
blockingDependencies = blockingDependencies.Where(difference => difference.Included == node.Included);
|
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;
|
bool result = true;
|
||||||
// Create a diff entry from difference and check if it matches the diff entry passed
|
// 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();
|
System.Reflection.PropertyInfo[] properties = diffEntry.GetType().GetProperties();
|
||||||
foreach (var prop in properties)
|
foreach (var prop in properties)
|
||||||
|
|||||||
@@ -121,7 +121,7 @@ namespace Microsoft.SqlTools.ServiceLayer.SchemaCompare
|
|||||||
|
|
||||||
foreach (SchemaDifference difference in this.ComparisonResult.Differences)
|
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);
|
this.Differences.Add(diffEntry);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ namespace Microsoft.SqlTools.ServiceLayer.SchemaCompare
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
internal static partial class SchemaCompareUtils
|
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)
|
if (difference == null)
|
||||||
{
|
{
|
||||||
@@ -56,15 +56,31 @@ namespace Microsoft.SqlTools.ServiceLayer.SchemaCompare
|
|||||||
// set source and target scripts
|
// set source and target scripts
|
||||||
if (difference.SourceObject != null)
|
if (difference.SourceObject != null)
|
||||||
{
|
{
|
||||||
string sourceScript;
|
string sourceScript = schemaComparisonResult.GetDiffEntrySourceScript(difference);
|
||||||
difference.SourceObject.TryGetScript(out sourceScript);
|
|
||||||
diffEntry.SourceScript = FormatScript(sourceScript);
|
// 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)
|
if (difference.TargetObject != null)
|
||||||
{
|
{
|
||||||
string targetScript;
|
string targetScript = schemaComparisonResult.GetDiffEntryTargetScript(difference);
|
||||||
difference.TargetObject.TryGetScript(out targetScript);
|
|
||||||
diffEntry.TargetScript = FormatScript(targetScript);
|
// 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)
|
foreach (SchemaDifference child in difference.Children)
|
||||||
{
|
{
|
||||||
diffEntry.Children.Add(CreateDiffEntry(child, diffEntry));
|
diffEntry.Children.Add(CreateDiffEntry(child, diffEntry, schemaComparisonResult));
|
||||||
}
|
}
|
||||||
|
|
||||||
return diffEntry;
|
return diffEntry;
|
||||||
|
|||||||
@@ -1568,7 +1568,7 @@ WITH VALUES
|
|||||||
Assert.IsNull(schemaCompareOperation.ErrorMessage);
|
Assert.IsNull(schemaCompareOperation.ErrorMessage);
|
||||||
|
|
||||||
// try to exclude
|
// try to exclude
|
||||||
DiffEntry t2Diff = SchemaCompareUtils.CreateDiffEntry(schemaCompareOperation.ComparisonResult.Differences.Where(x => x.SourceObject != null && x.SourceObject.Name.Parts[1] == "t2").First(), null);
|
DiffEntry t2Diff = SchemaCompareUtils.CreateDiffEntry(schemaCompareOperation.ComparisonResult.Differences.Where(x => x.SourceObject != null && x.SourceObject.Name.Parts[1] == "t2").First(), null, schemaCompareOperation.ComparisonResult);
|
||||||
SchemaCompareNodeParams t2ExcludeParams = new SchemaCompareNodeParams()
|
SchemaCompareNodeParams t2ExcludeParams = new SchemaCompareNodeParams()
|
||||||
{
|
{
|
||||||
OperationId = schemaCompareOperation.OperationId,
|
OperationId = schemaCompareOperation.OperationId,
|
||||||
@@ -1585,7 +1585,7 @@ WITH VALUES
|
|||||||
Assert.True(t2ExcludeOperation.BlockingDependencies[0].SourceValue[1] == "v1", "Dependency should be View v1");
|
Assert.True(t2ExcludeOperation.BlockingDependencies[0].SourceValue[1] == "v1", "Dependency should be View v1");
|
||||||
|
|
||||||
// exclude view v1, then t2 should also get excluded by this
|
// exclude view v1, then t2 should also get excluded by this
|
||||||
DiffEntry v1Diff = SchemaCompareUtils.CreateDiffEntry(schemaCompareOperation.ComparisonResult.Differences.Where(x => x.SourceObject != null && x.SourceObject.Name.Parts[1] == "v1").First(), null);
|
DiffEntry v1Diff = SchemaCompareUtils.CreateDiffEntry(schemaCompareOperation.ComparisonResult.Differences.Where(x => x.SourceObject != null && x.SourceObject.Name.Parts[1] == "v1").First(), null, schemaCompareOperation.ComparisonResult);
|
||||||
SchemaCompareNodeParams v1ExcludeParams = new SchemaCompareNodeParams()
|
SchemaCompareNodeParams v1ExcludeParams = new SchemaCompareNodeParams()
|
||||||
{
|
{
|
||||||
OperationId = schemaCompareOperation.OperationId,
|
OperationId = schemaCompareOperation.OperationId,
|
||||||
@@ -1712,7 +1712,7 @@ WITH VALUES
|
|||||||
}
|
}
|
||||||
|
|
||||||
// create Diff Entry from Difference
|
// create Diff Entry from Difference
|
||||||
DiffEntry diff = SchemaCompareUtils.CreateDiffEntry(schemaCompareOperation.ComparisonResult.Differences.First(), null);
|
DiffEntry diff = SchemaCompareUtils.CreateDiffEntry(schemaCompareOperation.ComparisonResult.Differences.First(), null, schemaCompareOperation.ComparisonResult);
|
||||||
|
|
||||||
int initial = schemaCompareOperation.ComparisonResult.Differences.Count();
|
int initial = schemaCompareOperation.ComparisonResult.Differences.Count();
|
||||||
SchemaCompareNodeParams schemaCompareExcludeNodeParams = new SchemaCompareNodeParams()
|
SchemaCompareNodeParams schemaCompareExcludeNodeParams = new SchemaCompareNodeParams()
|
||||||
@@ -1761,7 +1761,7 @@ WITH VALUES
|
|||||||
string initialScript = generateScriptOperation.ScriptGenerationResult.Script;
|
string initialScript = generateScriptOperation.ScriptGenerationResult.Script;
|
||||||
|
|
||||||
// create Diff Entry from on Difference
|
// create Diff Entry from on Difference
|
||||||
DiffEntry diff = SchemaCompareUtils.CreateDiffEntry(schemaCompareOperation.ComparisonResult.Differences.First(), null);
|
DiffEntry diff = SchemaCompareUtils.CreateDiffEntry(schemaCompareOperation.ComparisonResult.Differences.First(), null, schemaCompareOperation.ComparisonResult);
|
||||||
|
|
||||||
//Validate Diff Entry creation for object type
|
//Validate Diff Entry creation for object type
|
||||||
ValidateDiffEntryCreation(diff, schemaCompareOperation.ComparisonResult.Differences.First());
|
ValidateDiffEntryCreation(diff, schemaCompareOperation.ComparisonResult.Differences.First());
|
||||||
|
|||||||
Reference in New Issue
Block a user