-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHypertableAnnotationApplier.cs
More file actions
48 lines (42 loc) · 1.99 KB
/
HypertableAnnotationApplier.cs
File metadata and controls
48 lines (42 loc) · 1.99 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
using CmdScale.EntityFrameworkCore.TimescaleDB.Configuration.Hypertable;
using Microsoft.EntityFrameworkCore.Scaffolding.Metadata;
using System.Text.Json;
using static CmdScale.EntityFrameworkCore.TimescaleDB.Design.Scaffolding.HypertableScaffoldingExtractor;
namespace CmdScale.EntityFrameworkCore.TimescaleDB.Design.Scaffolding
{
/// <summary>
/// Applies hypertable annotations to scaffolded database tables.
/// </summary>
public sealed class HypertableAnnotationApplier : IAnnotationApplier
{
public void ApplyAnnotations(DatabaseTable table, object featureInfo)
{
if (featureInfo is not HypertableInfo info)
{
throw new ArgumentException($"Expected {nameof(HypertableInfo)}, got {featureInfo.GetType().Name}", nameof(featureInfo));
}
table[HypertableAnnotations.IsHypertable] = true;
table[HypertableAnnotations.HypertableTimeColumn] = info.TimeColumnName;
table[HypertableAnnotations.ChunkTimeInterval] = info.ChunkTimeInterval;
table[HypertableAnnotations.EnableCompression] = info.CompressionEnabled;
if (info.ChunkSkipColumns.Count > 0)
{
table[HypertableAnnotations.ChunkSkipColumns] = string.Join(",", info.ChunkSkipColumns);
}
// Apply SegmentBy annotation if present
if (info.CompressionSegmentBy.Count > 0)
{
table[HypertableAnnotations.CompressionSegmentBy] = string.Join(", ", info.CompressionSegmentBy);
}
// Apply OrderBy annotation if present
if (info.CompressionOrderBy.Count > 0)
{
table[HypertableAnnotations.CompressionOrderBy] = string.Join(", ", info.CompressionOrderBy);
}
if (info.AdditionalDimensions.Count > 0)
{
table[HypertableAnnotations.AdditionalDimensions] = JsonSerializer.Serialize(info.AdditionalDimensions);
}
}
}
}