Skip to content

Instantly share code, notes, and snippets.

@dmmusil
Last active March 6, 2021 21:36
Show Gist options
  • Select an option

  • Save dmmusil/630185e1fdf94e4c6d01a3d486abb53b to your computer and use it in GitHub Desktop.

Select an option

Save dmmusil/630185e1fdf94e4c6d01a3d486abb53b to your computer and use it in GitHub Desktop.
Using DACFx to schema compare and ignore a set of schemas
private static int SchemaCompare(string scmpPath, string databaseName, string outputPath)
{
var schemaComparison = new SchemaComparison(scmpPath);
var result = schemaComparison.Compare();
if (result.IsEqual)
{
Console.WriteLine("No differences detected.");
return 0;
}
var excludedSchemas = new[] {"testing"};
static string GetSchema(TSqlObject sqlObject) => sqlObject.Name.Parts[0];
foreach (var diff in result.Differences.Where(d => d.Included))
{
var schemaSource = diff.SourceObject != null ? GetSchema(diff.SourceObject) : null;
var schemaTarget = diff.TargetObject != null ? GetSchema(diff.TargetObject) : null;
if (excludedSchemas.Contains(schemaSource) || excludedSchemas.Contains(schemaTarget))
{
var objectName = GetObjectName(diff);
result.Exclude(diff);
}
}
var script = result.GenerateScript(databaseName).Script;
File.WriteAllText(outputPath, script, Encoding.UTF8);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment