Skip to content

Commit 36b8834

Browse files
authored
Merge pull request #75 from github/caol-ila-fix-creating-invalid-tables
add validation rule for table creation
2 parents 9084c41 + 01f0889 commit 36b8834

1 file changed

Lines changed: 11 additions & 2 deletions

File tree

KustoSchemaTools/Changes/DatabaseChanges.cs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using KustoSchemaTools.Model;
22
using Microsoft.Extensions.Logging;
3+
using System.Data;
34

45
namespace KustoSchemaTools.Changes
56
{
@@ -43,7 +44,7 @@ public static List<IChange> GenerateChanges(Database oldState, Database newState
4344

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

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

135-
private static List<IChange> GenerateScriptCompareChanges<T>(Database oldState, Database newState,Func<Database,Dictionary<string,T>> entitySelector,string entityName, ILogger log) where T: IKustoBaseEntity
136+
137+
138+
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
136139
{
137140
var tmp = new List<IChange>();
138141
var existing = entitySelector(oldState) ?? new Dictionary<string, T>();
@@ -143,6 +146,12 @@ private static List<IChange> GenerateScriptCompareChanges<T>(Database oldState,
143146

144147
foreach (var item in newItems)
145148
{
149+
var existingOldItem = existing.ContainsKey(item.Key) ? existing[item.Key] : default(T);
150+
if(validator != null && !validator(existingOldItem, item.Value))
151+
{
152+
log.LogInformation($"Skipping {entityName} {item.Key} as it failed validation");
153+
continue;
154+
}
146155
if (existing.ContainsKey(item.Key))
147156
{
148157
var change = new ScriptCompareChange(item.Key, existing[item.Key], item.Value);

0 commit comments

Comments
 (0)