Skip to content

Commit f06f9ac

Browse files
authored
Support allowMaterializedViewsWithoutRowLevelSecurity when creating materialized views (#148)
* Support allowMaterializedViewsWithoutRowLevelSecurity when creating materialized views * Only allowed for new MVs
1 parent e51d556 commit f06f9ac

2 files changed

Lines changed: 19 additions & 1 deletion

File tree

KustoSchemaTools/Changes/DatabaseChanges.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,15 @@ public static List<IChange> GenerateChanges(Database oldState, Database newState
6060
}
6161
}
6262

63+
foreach (var mv in newState.MaterializedViews)
64+
{
65+
if (mv.Value.AllowMaterializedViewsWithoutRowLevelSecurity
66+
&& oldState.MaterializedViews.ContainsKey(mv.Key))
67+
{
68+
oldState.MaterializedViews[mv.Key].AllowMaterializedViewsWithoutRowLevelSecurity = true;
69+
}
70+
}
71+
6372
result.AddRange(GenerateScriptCompareChanges(oldState, newState, db => db.Tables, nameof(newState.Tables), log, (oldItem, newItem) => oldItem != null || newItem.Columns?.Any() == true));
6473
var mvChanges = GenerateScriptCompareChanges(oldState, newState, db => db.MaterializedViews, nameof(newState.MaterializedViews), log);
6574
foreach(var mvChange in mvChanges)

KustoSchemaTools/Model/MaterializedView.cs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ public class MaterializedView : IKustoBaseEntity
2525
public string? RowLevelSecurity { get; set; }
2626
public Policy? Policies { get; set; }
2727
public bool Preformatted { get; set; } = false;
28+
public bool AllowMaterializedViewsWithoutRowLevelSecurity { get; set; } = false;
2829
public List<DatabaseScriptContainer> CreateScripts(string name, bool isNew)
2930
{
3031
var asyncSetup = isNew && Backfill == true;
@@ -36,7 +37,8 @@ public List<DatabaseScriptContainer> CreateScripts(string name, bool isNew)
3637
"RetentionAndCachePolicy",
3738
"RowLevelSecurity",
3839
"Policies",
39-
"Preformatted"
40+
"Preformatted",
41+
"AllowMaterializedViewsWithoutRowLevelSecurity"
4042
]);
4143

4244
if (!asyncSetup)
@@ -52,6 +54,13 @@ public List<DatabaseScriptContainer> CreateScripts(string name, bool isNew)
5254
.Where(p => !string.IsNullOrWhiteSpace(p.Value?.ToString()))
5355
.Select(p => $"{p.Name}=```{p.Value}```"));
5456

57+
if (AllowMaterializedViewsWithoutRowLevelSecurity && isNew)
58+
{
59+
properties = string.IsNullOrEmpty(properties)
60+
? "allowMaterializedViewsWithoutRowLevelSecurity=true"
61+
: $"{properties}, allowMaterializedViewsWithoutRowLevelSecurity=true";
62+
}
63+
5564
if (asyncSetup)
5665
{
5766
scripts.Add(new DatabaseScriptContainer("CreateMaterializedViewAsync", Kind == "table" ? 40 : 41, $".create async ifnotexists materialized-view with ({properties}) {name} on {Kind} {Source} {{ {Query} }}", true));

0 commit comments

Comments
 (0)