-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathReorderPolicyAnnotationApplier.cs
More file actions
49 lines (42 loc) · 2 KB
/
ReorderPolicyAnnotationApplier.cs
File metadata and controls
49 lines (42 loc) · 2 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
using CmdScale.EntityFrameworkCore.TimescaleDB.Configuration.ReorderPolicy;
using Microsoft.EntityFrameworkCore.Scaffolding.Metadata;
using static CmdScale.EntityFrameworkCore.TimescaleDB.Design.Scaffolding.ReorderPolicyScaffoldingExtractor;
namespace CmdScale.EntityFrameworkCore.TimescaleDB.Design.Scaffolding
{
/// <summary>
/// Applies reorder policy annotations to scaffolded database tables.
/// </summary>
public sealed class ReorderPolicyAnnotationApplier : IAnnotationApplier
{
public void ApplyAnnotations(DatabaseTable table, object featureInfo)
{
if (featureInfo is not ReorderPolicyInfo policyInfo)
{
throw new ArgumentException($"Expected {nameof(ReorderPolicyInfo)}, got {featureInfo.GetType().Name}", nameof(featureInfo));
}
table[ReorderPolicyAnnotations.HasReorderPolicy] = true;
table[ReorderPolicyAnnotations.IndexName] = policyInfo.IndexName;
if (policyInfo.InitialStart.HasValue)
{
table[ReorderPolicyAnnotations.InitialStart] = policyInfo.InitialStart.Value;
}
// Set annotations only if they differ from TimescaleDB defaults
if (policyInfo.ScheduleInterval != DefaultValues.ReorderPolicyScheduleInterval)
{
table[ReorderPolicyAnnotations.ScheduleInterval] = policyInfo.ScheduleInterval;
}
if (policyInfo.MaxRuntime != DefaultValues.ReorderPolicyMaxRuntime)
{
table[ReorderPolicyAnnotations.MaxRuntime] = policyInfo.MaxRuntime;
}
if (policyInfo.MaxRetries != DefaultValues.ReorderPolicyMaxRetries)
{
table[ReorderPolicyAnnotations.MaxRetries] = policyInfo.MaxRetries;
}
if (policyInfo.RetryPeriod != DefaultValues.ReorderPolicyScheduleInterval)
{
table[ReorderPolicyAnnotations.RetryPeriod] = policyInfo.RetryPeriod;
}
}
}
}