Last active
March 6, 2021 21:36
-
-
Save dmmusil/630185e1fdf94e4c6d01a3d486abb53b to your computer and use it in GitHub Desktop.
Using DACFx to schema compare and ignore a set of schemas
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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