mirror of
https://github.com/ckaczor/sqltoolsservice.git
synced 2026-02-07 01:25:41 -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:
@@ -0,0 +1,222 @@
|
||||
//
|
||||
// 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 System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Text;
|
||||
|
||||
namespace Microsoft.SqlTools.ServiceLayer.SchemaCompare.Contracts
|
||||
{
|
||||
/// <summary>
|
||||
/// Class to define deployment options.
|
||||
/// Keeping the order and defaults same as DacFx
|
||||
/// The default values here should also match the default values in ADS UX
|
||||
/// </summary>
|
||||
public class DeploymentOptions
|
||||
{
|
||||
public bool IgnoreTableOptions { get; set; }
|
||||
|
||||
public bool IgnoreSemicolonBetweenStatements { get; set; }
|
||||
|
||||
public bool IgnoreRouteLifetime { get; set; }
|
||||
|
||||
public bool IgnoreRoleMembership { get; set; }
|
||||
|
||||
public bool IgnoreQuotedIdentifiers { get; set; }
|
||||
|
||||
public bool IgnorePermissions { get; set; }
|
||||
|
||||
public bool IgnorePartitionSchemes { get; set; }
|
||||
|
||||
public bool IgnoreObjectPlacementOnPartitionScheme { get; set; }
|
||||
|
||||
public bool IgnoreNotForReplication { get; set; }
|
||||
|
||||
public bool IgnoreLoginSids { get; set; }
|
||||
|
||||
public bool IgnoreLockHintsOnIndexes { get; set; }
|
||||
|
||||
public bool IgnoreKeywordCasing { get; set; }
|
||||
|
||||
public bool IgnoreIndexPadding { get; set; }
|
||||
|
||||
public bool IgnoreIndexOptions { get; set; }
|
||||
|
||||
public bool IgnoreIncrement { get; set; }
|
||||
|
||||
public bool IgnoreIdentitySeed { get; set; }
|
||||
|
||||
public bool IgnoreUserSettingsObjects { get; set; }
|
||||
|
||||
public bool IgnoreFullTextCatalogFilePath { get; set; }
|
||||
|
||||
public bool IgnoreWhitespace { get; set; }
|
||||
|
||||
public bool IgnoreWithNocheckOnForeignKeys { get; set; }
|
||||
|
||||
public bool VerifyCollationCompatibility { get; set; }
|
||||
|
||||
public bool UnmodifiableObjectWarnings { get; set; }
|
||||
|
||||
public bool TreatVerificationErrorsAsWarnings { get; set; }
|
||||
|
||||
public bool ScriptRefreshModule { get; set; }
|
||||
|
||||
public bool ScriptNewConstraintValidation { get; set; }
|
||||
|
||||
public bool ScriptFileSize { get; set; }
|
||||
|
||||
public bool ScriptDeployStateChecks { get; set; }
|
||||
|
||||
public bool ScriptDatabaseOptions { get; set; }
|
||||
|
||||
public bool ScriptDatabaseCompatibility { get; set; }
|
||||
|
||||
public bool ScriptDatabaseCollation { get; set; }
|
||||
|
||||
public bool RunDeploymentPlanExecutors { get; set; }
|
||||
|
||||
public bool RegisterDataTierApplication { get; set; }
|
||||
|
||||
public bool PopulateFilesOnFileGroups { get; set; }
|
||||
|
||||
public bool NoAlterStatementsToChangeClrTypes { get; set; }
|
||||
|
||||
public bool IncludeTransactionalScripts { get; set; }
|
||||
|
||||
public bool IncludeCompositeObjects { get; set; }
|
||||
|
||||
public bool AllowUnsafeRowLevelSecurityDataMovement { get; set; }
|
||||
|
||||
public bool IgnoreWithNocheckOnCheckConstraints { get; set; }
|
||||
|
||||
public bool IgnoreFillFactor { get; set; }
|
||||
|
||||
public bool IgnoreFileSize { get; set; }
|
||||
|
||||
public bool IgnoreFilegroupPlacement { get; set; }
|
||||
|
||||
public bool DoNotAlterReplicatedObjects { get; set; }
|
||||
|
||||
public bool DoNotAlterChangeDataCaptureObjects { get; set; }
|
||||
|
||||
public bool DisableAndReenableDdlTriggers { get; set; }
|
||||
|
||||
public bool DeployDatabaseInSingleUserMode { get; set; }
|
||||
|
||||
public bool CreateNewDatabase { get; set; }
|
||||
|
||||
public bool CompareUsingTargetCollation { get; set; }
|
||||
|
||||
public bool CommentOutSetVarDeclarations { get; set; }
|
||||
|
||||
public int CommandTimeout { get; set; } = 120;
|
||||
|
||||
public bool BlockWhenDriftDetected { get; set; }
|
||||
|
||||
public bool BlockOnPossibleDataLoss { get; set; }
|
||||
|
||||
public bool BackupDatabaseBeforeChanges { get; set; }
|
||||
|
||||
public bool AllowIncompatiblePlatform { get; set; }
|
||||
|
||||
public bool AllowDropBlockingAssemblies { get; set; }
|
||||
|
||||
public string AdditionalDeploymentContributorArguments { get; set; }
|
||||
|
||||
public string AdditionalDeploymentContributors { get; set; }
|
||||
|
||||
public bool DropConstraintsNotInSource { get; set; }
|
||||
|
||||
public bool DropDmlTriggersNotInSource { get; set; }
|
||||
|
||||
public bool DropExtendedPropertiesNotInSource { get; set; }
|
||||
|
||||
public bool DropIndexesNotInSource { get; set; }
|
||||
|
||||
public bool IgnoreFileAndLogFilePath { get; set; }
|
||||
|
||||
public bool IgnoreExtendedProperties { get; set; }
|
||||
|
||||
public bool IgnoreDmlTriggerState { get; set; }
|
||||
|
||||
public bool IgnoreDmlTriggerOrder { get; set; }
|
||||
|
||||
public bool IgnoreDefaultSchema { get; set; }
|
||||
|
||||
public bool IgnoreDdlTriggerState { get; set; }
|
||||
|
||||
public bool IgnoreDdlTriggerOrder { get; set; }
|
||||
|
||||
public bool IgnoreCryptographicProviderFilePath { get; set; }
|
||||
|
||||
public bool VerifyDeployment { get; set; }
|
||||
|
||||
public bool IgnoreComments { get; set; }
|
||||
|
||||
public bool IgnoreColumnCollation { get; set; }
|
||||
|
||||
public bool IgnoreAuthorizer { get; set; }
|
||||
|
||||
public bool IgnoreAnsiNulls { get; set; }
|
||||
|
||||
public bool GenerateSmartDefaults { get; set; }
|
||||
|
||||
public bool DropStatisticsNotInSource { get; set; }
|
||||
|
||||
public bool DropRoleMembersNotInSource { get; set; }
|
||||
|
||||
public bool DropPermissionsNotInSource { get; set; }
|
||||
|
||||
public bool DropObjectsNotInSource { get; set; }
|
||||
|
||||
public bool IgnoreColumnOrder { get; set; }
|
||||
|
||||
public ObjectType[] DoNotDropObjectTypes { get; set; } = null;
|
||||
|
||||
public ObjectType[] ExcludeObjectTypes { get; set; } =
|
||||
{
|
||||
ObjectType.ServerTriggers,
|
||||
ObjectType.Routes,
|
||||
ObjectType.LinkedServerLogins,
|
||||
ObjectType.Endpoints,
|
||||
ObjectType.ErrorMessages,
|
||||
ObjectType.Filegroups,
|
||||
ObjectType.Logins,
|
||||
ObjectType.LinkedServers,
|
||||
ObjectType.Credentials,
|
||||
ObjectType.DatabaseScopedCredentials,
|
||||
ObjectType.DatabaseEncryptionKeys,
|
||||
ObjectType.MasterKeys,
|
||||
ObjectType.DatabaseAuditSpecifications,
|
||||
ObjectType.Audits,
|
||||
ObjectType.ServerAuditSpecifications,
|
||||
ObjectType.CryptographicProviders,
|
||||
ObjectType.ServerRoles,
|
||||
ObjectType.EventSessions,
|
||||
ObjectType.DatabaseOptions,
|
||||
ObjectType.EventNotifications,
|
||||
ObjectType.ServerRoleMembership,
|
||||
ObjectType.AssemblyFiles,
|
||||
};
|
||||
|
||||
public DeploymentOptions()
|
||||
{
|
||||
DacDeployOptions options = new DacDeployOptions();
|
||||
System.Reflection.PropertyInfo[] deploymentOptionsProperties = this.GetType().GetProperties();
|
||||
|
||||
foreach (var deployOptionsProp in deploymentOptionsProperties)
|
||||
{
|
||||
var prop = options.GetType().GetProperty(deployOptionsProp.Name);
|
||||
if (prop != null)
|
||||
{
|
||||
deployOptionsProp.SetValue(this, prop.GetValue(options));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -58,6 +58,11 @@ namespace Microsoft.SqlTools.ServiceLayer.SchemaCompare.Contracts
|
||||
/// Executation mode for the operation. Default is execution
|
||||
/// </summary>
|
||||
public TaskExecutionMode TaskExecutionMode { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// gets or sets the deployment options for schema compare
|
||||
/// </summary>
|
||||
public DeploymentOptions DeploymentOptions { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -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