-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathPolicy.cs
More file actions
72 lines (61 loc) · 2.85 KB
/
Policy.cs
File metadata and controls
72 lines (61 loc) · 2.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
using KustoSchemaTools.Changes;
using KustoSchemaTools.Helpers;
using Newtonsoft.Json;
namespace KustoSchemaTools.Model
{
public class Policy
{
public string? Retention { get; set; }
public string? HotCache { get; set; }
public PartitioningPolicy? Partitioning { get; set; }
public string? RowLevelSecurity { get; set; }
public bool AllowMaterializedViewsWithoutRowLevelSecurity { get; set; } = false;
public List<DatabaseScriptContainer> CreateScripts(string name, string entity)
{
var scripts = new List<DatabaseScriptContainer>();
if (Retention != null)
{
scripts.Add(new DatabaseScriptContainer("SoftDelete", 60, $".alter-merge {entity} {name} policy retention softdelete={Retention}"));
}
if (HotCache != null)
{
scripts.Add(new DatabaseScriptContainer("HotCache", 70, $".alter {entity} {name} policy caching hot={HotCache}"));
}
if (!string.IsNullOrEmpty(RowLevelSecurity))
{
var rlsWithClause = AllowMaterializedViewsWithoutRowLevelSecurity
? " with (allowMaterializedViewsWithoutRowLevelSecurity=true)"
: "";
scripts.Add(new DatabaseScriptContainer("RowLevelSecurity", 57, $".alter {entity} {name} policy row_level_security enable{rlsWithClause} ```{RowLevelSecurity}```"));
}
else
{
scripts.Add(new DatabaseScriptContainer("RowLevelSecurity", 52, $".delete {entity} {name} policy row_level_security"));
}
if (Partitioning != null)
{
scripts.Add(Partitioning.CreateScript(name, entity));
}
return scripts;
}
}
public class TablePolicy : Policy
{
public List<UpdatePolicy>? UpdatePolicies { get; set; }
public bool RestrictedViewAccess { get; set; } = false;
public List<DatabaseScriptContainer> CreateScripts(string name)
{
var scripts = new List<DatabaseScriptContainer>();
scripts.AddRange(base.CreateScripts(name, "table"));
if (UpdatePolicies != null)
{
var policies = JsonConvert.SerializeObject(UpdatePolicies, Serialization.JsonPascalCase);
var upPriority = UpdatePolicies.Any() ? 59 : 50;
scripts.Add(new DatabaseScriptContainer("TableUpdatePolicy", upPriority, $".alter table {name} policy update ```{policies}```"));
}
var rvaPrio = RestrictedViewAccess ? 58 : 51;
scripts.Add(new DatabaseScriptContainer("RestrictedViewAccess", rvaPrio, $".alter table {name} policy restricted_view_access {(RestrictedViewAccess ? "true" : "false")}"));
return scripts;
}
}
}