-
Notifications
You must be signed in to change notification settings - Fork 257
Expand file tree
/
Copy pathNpgsqlRuntimeModelConvention.cs
More file actions
122 lines (107 loc) · 4.7 KB
/
NpgsqlRuntimeModelConvention.cs
File metadata and controls
122 lines (107 loc) · 4.7 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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata.Internal;
namespace Npgsql.EntityFrameworkCore.PostgreSQL.Metadata.Conventions;
/// <summary>
/// A convention that creates an optimized copy of the mutable model.
/// </summary>
public class NpgsqlRuntimeModelConvention : RelationalRuntimeModelConvention
{
/// <summary>
/// Creates a new instance of <see cref="NpgsqlRuntimeModelConvention" />.
/// </summary>
/// <param name="dependencies">Parameter object containing dependencies for this convention.</param>
/// <param name="relationalDependencies">Parameter object containing relational dependencies for this convention.</param>
public NpgsqlRuntimeModelConvention(
ProviderConventionSetBuilderDependencies dependencies,
RelationalConventionSetBuilderDependencies relationalDependencies)
: base(dependencies, relationalDependencies)
{
}
/// <inheritdoc />
protected override void ProcessModelAnnotations(
Dictionary<string, object?> annotations,
IModel model,
RuntimeModel runtimeModel,
bool runtime)
{
base.ProcessModelAnnotations(annotations, model, runtimeModel, runtime);
if (!runtime)
{
annotations.Remove(NpgsqlAnnotationNames.DatabaseTemplate);
annotations.Remove(NpgsqlAnnotationNames.Tablespace);
annotations.Remove(NpgsqlAnnotationNames.CollationDefinitionPrefix);
annotations.Remove(NpgsqlAnnotationNames.Encoding);
#pragma warning disable CS0618
annotations.Remove(NpgsqlAnnotationNames.DefaultColumnCollation);
#pragma warning restore CS0618
foreach (var annotationName in annotations.Keys.Where(
k =>
k.StartsWith(NpgsqlAnnotationNames.PostgresExtensionPrefix, StringComparison.Ordinal)
|| k.StartsWith(NpgsqlAnnotationNames.EnumPrefix, StringComparison.Ordinal)
|| k.StartsWith(NpgsqlAnnotationNames.RangePrefix, StringComparison.Ordinal)))
{
annotations.Remove(annotationName);
}
}
}
/// <inheritdoc />
protected override void ProcessEntityTypeAnnotations(
Dictionary<string, object?> annotations,
IEntityType entityType,
RuntimeEntityType runtimeEntityType,
bool runtime)
{
base.ProcessEntityTypeAnnotations(annotations, entityType, runtimeEntityType, runtime);
if (!runtime)
{
annotations.Remove(NpgsqlAnnotationNames.UnloggedTable);
foreach (var annotationName in annotations.Keys.Where(
k => k.StartsWith(NpgsqlAnnotationNames.StorageParameterPrefix, StringComparison.Ordinal)))
{
annotations.Remove(annotationName);
}
}
}
/// <inheritdoc />
protected override void ProcessPropertyAnnotations(
Dictionary<string, object?> annotations,
IProperty property,
RuntimeProperty runtimeProperty,
bool runtime)
{
base.ProcessPropertyAnnotations(annotations, property, runtimeProperty, runtime);
if (!runtime)
{
annotations.Remove(NpgsqlAnnotationNames.IdentityOptions);
annotations.Remove(NpgsqlAnnotationNames.TsVectorConfig);
annotations.Remove(NpgsqlAnnotationNames.TsVectorProperties);
if (!annotations.ContainsKey(NpgsqlAnnotationNames.ValueGenerationStrategy))
{
annotations[NpgsqlAnnotationNames.ValueGenerationStrategy] = property.GetValueGenerationStrategy();
}
}
}
/// <inheritdoc />
protected override void ProcessIndexAnnotations(
Dictionary<string, object?> annotations,
IIndex index,
RuntimeIndex runtimeIndex,
bool runtime)
{
base.ProcessIndexAnnotations(annotations, index, runtimeIndex, runtime);
if (!runtime)
{
annotations.Remove(NpgsqlAnnotationNames.IndexMethod);
annotations.Remove(NpgsqlAnnotationNames.IndexOperators);
annotations.Remove(NpgsqlAnnotationNames.IndexSortOrder);
annotations.Remove(NpgsqlAnnotationNames.IndexNullSortOrder);
annotations.Remove(NpgsqlAnnotationNames.IndexInclude);
annotations.Remove(NpgsqlAnnotationNames.CreatedConcurrently);
annotations.Remove(NpgsqlAnnotationNames.NullsDistinct);
foreach (var annotationName in annotations.Keys.Where(
k => k.StartsWith(NpgsqlAnnotationNames.StorageParameterPrefix, StringComparison.Ordinal)))
{
annotations.Remove(annotationName);
}
}
}
}