mirror of
https://github.com/ckaczor/sqltoolsservice.git
synced 2026-02-13 03:28:37 -05:00
Feature/schemacompare options (#798)
* Initial working code for schema compare options * Removing the unnecessary default value attribute * Cleaning up tests * Taking PR comments * Taking name change for Schema Compare Options --> Deployment Options * Remove parent to avoid circular reference (to avoid issues with serialization)
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
// 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;
|
||||
@@ -40,6 +41,8 @@ namespace Microsoft.SqlTools.ServiceLayer.SchemaCompare
|
||||
|
||||
public List<DiffEntry> Differences;
|
||||
|
||||
public DacDeployOptions DefaultOptions;
|
||||
|
||||
public SchemaCompareOperation(SchemaCompareParams parameters, ConnectionInfo sourceConnInfo, ConnectionInfo targetConnInfo)
|
||||
{
|
||||
Validate.IsNotNull("parameters", parameters);
|
||||
@@ -86,10 +89,16 @@ namespace Microsoft.SqlTools.ServiceLayer.SchemaCompare
|
||||
SchemaCompareEndpoint targetEndpoint = CreateSchemaCompareEndpoint(this.Parameters.TargetEndpointInfo, this.TargetConnectionString);
|
||||
|
||||
SchemaComparison comparison = new SchemaComparison(sourceEndpoint, targetEndpoint);
|
||||
|
||||
if (this.Parameters.DeploymentOptions != null)
|
||||
{
|
||||
comparison.Options = this.CreateSchemaCompareOptions(this.Parameters.DeploymentOptions);
|
||||
}
|
||||
|
||||
this.ComparisonResult = comparison.Compare();
|
||||
|
||||
// try one more time if it didn't work the first time
|
||||
if(!this.ComparisonResult.IsValid)
|
||||
if (!this.ComparisonResult.IsValid)
|
||||
{
|
||||
this.ComparisonResult = comparison.Compare();
|
||||
}
|
||||
@@ -109,6 +118,22 @@ namespace Microsoft.SqlTools.ServiceLayer.SchemaCompare
|
||||
}
|
||||
}
|
||||
|
||||
private DacDeployOptions CreateSchemaCompareOptions(DeploymentOptions deploymentOptions)
|
||||
{
|
||||
System.Reflection.PropertyInfo[] deploymentOptionsProperties = deploymentOptions.GetType().GetProperties();
|
||||
|
||||
DacDeployOptions dacOptions = new DacDeployOptions();
|
||||
foreach (var deployOptionsProp in deploymentOptionsProperties)
|
||||
{
|
||||
var prop = dacOptions.GetType().GetProperty(deployOptionsProp.Name);
|
||||
if (prop != null)
|
||||
{
|
||||
prop.SetValue(dacOptions, deployOptionsProp.GetValue(deploymentOptions));
|
||||
}
|
||||
}
|
||||
return dacOptions;
|
||||
}
|
||||
|
||||
private DiffEntry CreateDiffEntry(SchemaDifference difference, DiffEntry parent)
|
||||
{
|
||||
DiffEntry diffEntry = new DiffEntry();
|
||||
@@ -141,7 +166,7 @@ namespace Microsoft.SqlTools.ServiceLayer.SchemaCompare
|
||||
diffEntry.TargetScript = RemoveExcessWhitespace(targetScript);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
diffEntry.Children = new List<DiffEntry>();
|
||||
|
||||
foreach (SchemaDifference child in difference.Children)
|
||||
@@ -157,17 +182,17 @@ namespace Microsoft.SqlTools.ServiceLayer.SchemaCompare
|
||||
switch (endpointInfo.EndpointType)
|
||||
{
|
||||
case SchemaCompareEndpointType.Dacpac:
|
||||
{
|
||||
return new SchemaCompareDacpacEndpoint(endpointInfo.PackageFilePath);
|
||||
}
|
||||
{
|
||||
return new SchemaCompareDacpacEndpoint(endpointInfo.PackageFilePath);
|
||||
}
|
||||
case SchemaCompareEndpointType.Database:
|
||||
{
|
||||
return new SchemaCompareDatabaseEndpoint(connectionString);
|
||||
}
|
||||
{
|
||||
return new SchemaCompareDatabaseEndpoint(connectionString);
|
||||
}
|
||||
default:
|
||||
{
|
||||
return null;
|
||||
}
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user