Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions KustoSchemaTools/Changes/DatabaseChanges.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using KustoSchemaTools.Model;
using Microsoft.Extensions.Logging;
using System.Data;

namespace KustoSchemaTools.Changes
{
Expand Down Expand Up @@ -43,7 +44,7 @@ public static List<IChange> GenerateChanges(Database oldState, Database newState

result.AddRange(GenerateDeletions(oldState, newState.Deletions, log));

result.AddRange(GenerateScriptCompareChanges(oldState, newState, db => db.Tables, nameof(newState.Tables), log));
result.AddRange(GenerateScriptCompareChanges(oldState, newState, db => db.Tables, nameof(newState.Tables), log, (oldItem, newItem) => oldItem != null || newItem.Columns?.Any() == true));
result.AddRange(GenerateScriptCompareChanges(oldState, newState, db => db.MaterializedViews, nameof(newState.MaterializedViews), log));
result.AddRange(GenerateScriptCompareChanges(oldState, newState, db => db.ContinuousExports, nameof(newState.ContinuousExports), log));
result.AddRange(GenerateScriptCompareChanges(oldState, newState, db => db.Functions, nameof(newState.Functions), log));
Expand Down Expand Up @@ -132,7 +133,9 @@ private static List<IChange> GenerateEntityGroupChanges(Database oldState, Datab
return changes;
}

private static List<IChange> GenerateScriptCompareChanges<T>(Database oldState, Database newState,Func<Database,Dictionary<string,T>> entitySelector,string entityName, ILogger log) where T: IKustoBaseEntity


private static List<IChange> GenerateScriptCompareChanges<T>(Database oldState, Database newState,Func<Database,Dictionary<string,T>> entitySelector,string entityName, ILogger log, Func<T?,T,bool> validator = null) where T: IKustoBaseEntity
{
var tmp = new List<IChange>();
var existing = entitySelector(oldState) ?? new Dictionary<string, T>();
Expand All @@ -143,6 +146,12 @@ private static List<IChange> GenerateScriptCompareChanges<T>(Database oldState,

foreach (var item in newItems)
{
var existingOldItem = existing.ContainsKey(item.Key) ? existing[item.Key] : default(T);
if(validator != null && !validator(existingOldItem, item.Value))
{
log.LogInformation($"Skipping {entityName} {item.Key} as it failed validation");
continue;
}
if (existing.ContainsKey(item.Key))
{
var change = new ScriptCompareChange(item.Key, existing[item.Key], item.Value);
Expand Down