Skip to content

Commit e51d556

Browse files
authored
Support allowMaterializedViewsWithoutRowLevelSecurity on RLS policies (#147)
1 parent 5decdbe commit e51d556

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

KustoSchemaTools/Changes/DatabaseChanges.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,18 @@ public static List<IChange> GenerateChanges(Database oldState, Database newState
4848

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

51+
// Kusto does not expose AllowMaterializedViewsWithoutRowLevelSecurity in any query output,
52+
// so propagate the flag from the desired state to the cluster state to avoid phantom diffs.
53+
foreach (var table in newState.Tables)
54+
{
55+
if (table.Value.Policies?.AllowMaterializedViewsWithoutRowLevelSecurity == true
56+
&& oldState.Tables.ContainsKey(table.Key)
57+
&& oldState.Tables[table.Key].Policies != null)
58+
{
59+
oldState.Tables[table.Key].Policies.AllowMaterializedViewsWithoutRowLevelSecurity = true;
60+
}
61+
}
62+
5163
result.AddRange(GenerateScriptCompareChanges(oldState, newState, db => db.Tables, nameof(newState.Tables), log, (oldItem, newItem) => oldItem != null || newItem.Columns?.Any() == true));
5264
var mvChanges = GenerateScriptCompareChanges(oldState, newState, db => db.MaterializedViews, nameof(newState.MaterializedViews), log);
5365
foreach(var mvChange in mvChanges)

KustoSchemaTools/Model/Policy.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ public class Policy
1010
public string? HotCache { get; set; }
1111
public PartitioningPolicy? Partitioning { get; set; }
1212
public string? RowLevelSecurity { get; set; }
13+
public bool AllowMaterializedViewsWithoutRowLevelSecurity { get; set; } = false;
1314

1415

1516
public List<DatabaseScriptContainer> CreateScripts(string name, string entity)
@@ -26,7 +27,10 @@ public List<DatabaseScriptContainer> CreateScripts(string name, string entity)
2627

2728
if (!string.IsNullOrEmpty(RowLevelSecurity))
2829
{
29-
scripts.Add(new DatabaseScriptContainer("RowLevelSecurity", 57, $".alter {entity} {name} policy row_level_security enable ```{RowLevelSecurity}```"));
30+
var rlsWithClause = AllowMaterializedViewsWithoutRowLevelSecurity
31+
? " with (allowMaterializedViewsWithoutRowLevelSecurity=true)"
32+
: "";
33+
scripts.Add(new DatabaseScriptContainer("RowLevelSecurity", 57, $".alter {entity} {name} policy row_level_security enable{rlsWithClause} ```{RowLevelSecurity}```"));
3034
}
3135
else
3236
{

0 commit comments

Comments
 (0)