Skip to content

Commit

Permalink
Update dacfx to latest preview (#845)
Browse files Browse the repository at this point in the history
* updating dacfx with private nuget for testing

* Updating to real dacfx-preview version

* Removing additional refs added by nuget package manager (these were not there previously)
  • Loading branch information
udeeshagautam committed Aug 9, 2019
1 parent 8d7acab commit 4fe02a6
Show file tree
Hide file tree
Showing 7 changed files with 105 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
<ItemGroup>
<PackageReference Include="System.Data.SqlClient" Version="4.6.0" />
<PackageReference Include="Microsoft.SqlServer.SqlManagementObjects" Version="$(SmoPackageVersion)" />
<PackageReference Include="Microsoft.SqlServer.DacFx" Version="150.4451.1-preview" />
<PackageReference Include="Microsoft.SqlServer.DacFx" Version="150.4505.1-preview" />
<PackageReference Include="System.Text.Encoding.CodePages" Version="4.6.0-preview3-26501-04" />
</ItemGroup>
<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,10 @@ public class DeploymentOptions

public int CommandTimeout { get; set; } = 120;

public int LongRunningCommandTimeout { get; set; } = 0;

public int DatabaseLockTimeout { get; set; } = 60;

public bool BlockWhenDriftDetected { get; set; }

public bool BlockOnPossibleDataLoss { get; set; }
Expand Down Expand Up @@ -176,6 +180,8 @@ public class DeploymentOptions

public bool IgnoreColumnOrder { get; set; }

public string AdditionalDeploymentContributorPaths { get; set; } = string.Empty;

public ObjectType[] DoNotDropObjectTypes { get; set; } = null;

public ObjectType[] ExcludeObjectTypes { get; set; } =
Expand All @@ -185,7 +191,7 @@ public class DeploymentOptions
ObjectType.LinkedServerLogins,
ObjectType.Endpoints,
ObjectType.ErrorMessages,
ObjectType.Filegroups,
ObjectType.Files,
ObjectType.Logins,
ObjectType.LinkedServers,
ObjectType.Credentials,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
<PackageReference Include="xunit.runner.visualstudio" Version="2.2.0" />
<PackageReference Include="System.Data.SqlClient" Version="4.6.0" />
<PackageReference Include="Microsoft.SqlServer.SqlManagementObjects" Version="$(SmoPackageVersion)" />
<PackageReference Include="Microsoft.SqlServer.DacFx" Version="150.4451.1-preview" />
<PackageReference Include="Microsoft.SqlServer.DacFx" Version="150.4505.1-preview" />
</ItemGroup>
<ItemGroup>
<Service Include="{82a7f48d-3b50-4b1e-b82e-3ada8210c358}" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
<PackageReference Include="xunit.runner.visualstudio" Version="2.2.0" />
<PackageReference Include="System.Data.SqlClient" Version="4.6.0" />
<PackageReference Include="Microsoft.SqlServer.SqlManagementObjects" Version="$(SmoPackageVersion)" />
<PackageReference Include="Microsoft.SqlServer.DacFx" Version="150.4451.1-preview" />
<PackageReference Include="Microsoft.SqlServer.DacFx" Version="150.4505.1-preview" />
</ItemGroup>
<ItemGroup>
<Service Include="{82a7f48d-3b50-4b1e-b82e-3ada8210c358}" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ private DeploymentOptions GetExcludeTableValuedFunctionOptions()
ObjectType.Endpoints,
ObjectType.ErrorMessages,
ObjectType.Filegroups,
ObjectType.Files,
ObjectType.Logins,
ObjectType.LinkedServers,
ObjectType.Credentials,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,23 @@ public class SchemaCompareServiceTests
[col1] INT NULL,
)";

private const string CreateKey = @"CREATE COLUMN MASTER KEY [CMK_Auto1]
WITH (
KEY_STORE_PROVIDER_NAME = N'MSSQL_CERTIFICATE_STORE',
KEY_PATH = N'CurrentUser/my/1234'
);
CREATE COLUMN ENCRYPTION KEY [CEK_Auto1]
WITH VALUES
(
COLUMN_MASTER_KEY = [CMK_Auto1],
ALGORITHM = N'RSA_OAEP',
ENCRYPTED_VALUE = 0x0000
);";

private const string CreateFileGroup = @"ALTER DATABASE {0}
ADD FILEGROUP [MyFileGroup] CONTAINS MEMORY_OPTIMIZED_DATA;
GO";

/// <summary>
/// Verify the schema compare request comparing two dacpacs
/// </summary>
Expand Down Expand Up @@ -653,7 +670,7 @@ public async Task VerifySchemaCompareServiceCalls()

await SchemaCompareService.Instance.HandleSchemaCompareOpenScmpRequest(openScmpParams, openScmpRequestContext.Object);
await SchemaCompareService.Instance.CurrentSchemaCompareTask;
SchemaCompareTestUtils.VerifyAndCleanup(scmpFilePath);
SchemaCompareTestUtils.VerifyAndCleanup(scmpFilePath);
}
finally
{
Expand Down Expand Up @@ -712,6 +729,81 @@ public async void SchemaCompareCancelCompareOperation()
}
}

/// <summary>
/// test to verify recent dacfx bugs
/// does not need all combinations of db and dacpacs
/// </summary>
[Fact]
public async void SchemaCompareCEKAndFilegoupTest()
{
var result = SchemaCompareTestUtils.GetLiveAutoCompleteTestObjects();
SqlTestDb sourceDb = await SqlTestDb.CreateNewAsync(TestServerType.OnPrem, false, null, CreateKey, "SchemaCompareSource");
sourceDb.RunQuery(string.Format(CreateFileGroup, sourceDb.DatabaseName));
SqlTestDb targetDb = await SqlTestDb.CreateNewAsync(TestServerType.OnPrem, false, null, TargetScript, "SchemaCompareTarget");

try
{
SchemaCompareEndpointInfo sourceInfo = new SchemaCompareEndpointInfo();
SchemaCompareEndpointInfo targetInfo = new SchemaCompareEndpointInfo();

sourceInfo.EndpointType = SchemaCompareEndpointType.Database;
sourceInfo.DatabaseName = sourceDb.DatabaseName;
targetInfo.EndpointType = SchemaCompareEndpointType.Database;
targetInfo.DatabaseName = targetDb.DatabaseName;
DeploymentOptions options = new DeploymentOptions();

// ensure that files are excluded seperate from filegroups
Assert.True(options.ExcludeObjectTypes.Contains(SqlServer.Dac.ObjectType.Files));
Assert.False(options.ExcludeObjectTypes.Contains(SqlServer.Dac.ObjectType.Filegroups));

var schemaCompareParams = new SchemaCompareParams
{
SourceEndpointInfo = sourceInfo,
TargetEndpointInfo = targetInfo,
DeploymentOptions = options
};

SchemaCompareOperation schemaCompareOperation = new SchemaCompareOperation(schemaCompareParams, result.ConnectionInfo, result.ConnectionInfo);
schemaCompareOperation.Execute(TaskExecutionMode.Execute);

Assert.True(schemaCompareOperation.ComparisonResult.IsValid);
Assert.False(schemaCompareOperation.ComparisonResult.IsEqual);
Assert.NotNull(schemaCompareOperation.ComparisonResult.Differences);

// validate CEK script
var cek = schemaCompareOperation.ComparisonResult.Differences.First(x => x.Name == "SqlColumnEncryptionKey");
Assert.NotNull(cek);
Assert.True(cek.SourceObject != null, "CEK obect is null");
Assert.True(cek.SourceObject.Name.ToString() == "[CEK_Auto1]", string.Format("CEK object name incorrect. Expected {0}, Actual {1}", "CEK_Auto1", cek.SourceObject.Name.ToString()));
Assert.True(CreateKey.Contains(cek.SourceObject.GetScript().Trim()), string.Format("Expected script : {0}, Actual Script {1}", cek.SourceObject.GetScript(), CreateKey));

// validate CMK script
var cmk = schemaCompareOperation.ComparisonResult.Differences.First(x => x.Name == "SqlColumnMasterKey");
Assert.NotNull(cmk);
Assert.True(cmk.SourceObject != null, "CMK obect is null");
Assert.True(cmk.SourceObject.Name.ToString() == "[CMK_Auto1]", string.Format("CMK object name incorrect. Expected {0}, Actual {1}", "CEK_Auto1", cmk.SourceObject.Name.ToString()));
Assert.True(CreateKey.Contains(cmk.SourceObject.GetScript().Trim()), string.Format("Expected script : {0}, Actual Script {1}", cmk.SourceObject.GetScript(), CreateKey));

// validate filegroup's presence
var filegroup = schemaCompareOperation.ComparisonResult.Differences.First(x => x.Name == "SqlFilegroup");
Assert.NotNull(filegroup);
Assert.True(filegroup.SourceObject != null, "File group obect is null");

// validate file's absense
bool filepresent = schemaCompareOperation.ComparisonResult.Differences.Any(x => x.Name == "SqlFile");
Assert.False(filepresent, "SqlFile should not be present");
var objectsWithFileInName = schemaCompareOperation.ComparisonResult.Differences.Where(x => x.Name.Contains("File"));
Assert.True(1 == objectsWithFileInName.Count(), string.Format("Only one File/Filegroup object was to be found, but found {0}", objectsWithFileInName.Count()));
}
finally
{
// cleanup
sourceDb.Cleanup();
targetDb.Cleanup();
}

}

private void ValidateSchemaCompareWithExcludeIncludeResults(SchemaCompareOperation schemaCompareOperation)
{
schemaCompareOperation.Execute(TaskExecutionMode.Execute);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ internal static void CompareOptions(DeploymentOptions deploymentOptions, DacDepl
System.Reflection.PropertyInfo[] deploymentOptionsProperties = deploymentOptions.GetType().GetProperties();
System.Reflection.PropertyInfo[] dacDeployProperties = dacDeployOptions.GetType().GetProperties();

// Note that DatabaseSpecification and sql cmd variables list is not present in Sqltools service - its not settable and is not used by ADS options.
// Note that DatabaseSpecification and sql cmd variables list is not present in Sqltools service - its not settable with checkbox and is not used by ADS options.
// They are not present in SSDT as well
// TODO : update this test if the above options are added later
Assert.True(deploymentOptionsProperties.Length == dacDeployProperties.Length - 2, $"Number of properties is not same Deployment options : {deploymentOptionsProperties.Length} DacFx options : {dacDeployProperties.Length}");
Expand Down

0 comments on commit 4fe02a6

Please sign in to comment.