-
Notifications
You must be signed in to change notification settings - Fork 39
/
resource_definition_matching_rule.go
101 lines (93 loc) · 2.7 KB
/
resource_definition_matching_rule.go
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
package schema
import (
"entgo.io/ent"
"entgo.io/ent/dialect/entsql"
"entgo.io/ent/schema"
"entgo.io/ent/schema/edge"
"entgo.io/ent/schema/field"
"entgo.io/ent/schema/index"
"github.com/seal-io/walrus/pkg/dao/entx"
"github.com/seal-io/walrus/pkg/dao/schema/mixin"
"github.com/seal-io/walrus/pkg/dao/types"
"github.com/seal-io/walrus/pkg/dao/types/object"
"github.com/seal-io/walrus/pkg/dao/types/property"
)
type ResourceDefinitionMatchingRule struct {
ent.Schema
}
func (ResourceDefinitionMatchingRule) Mixin() []ent.Mixin {
return []ent.Mixin{
mixin.ID(),
mixin.Time().WithoutUpdateTime(),
}
}
func (ResourceDefinitionMatchingRule) Indexes() []ent.Index {
return []ent.Index{
index.Fields("resource_definition_id", "name").
Unique(),
index.Fields("resource_definition_id", "template_id", "name").
Unique(),
}
}
func (ResourceDefinitionMatchingRule) Fields() []ent.Field {
return []ent.Field{
object.IDField("resource_definition_id").
Comment("ID of the resource definition to which the relationship connects.").
NotEmpty().
Immutable(),
object.IDField("template_id").
Comment("ID of the template version to which the relationship connects.").
NotEmpty(),
field.String("name").
Comment("Name of the matching rule.").
NotEmpty().
Immutable().
Annotations(
entx.Input(entx.WithUpdate())),
field.JSON("selector", types.Selector{}).
Comment("Resource selector."),
property.ValuesField("attributes").
Comment("Attributes to configure the template.").
Optional(),
field.Int("order").
Comment("Order of the matching rule.").
Annotations(
entx.SkipIO()),
field.Bytes("schema_default_value").
Comment("Default value generated from resource definition's schema, ui schema and attributes").
Optional().
Annotations(
entx.SkipIO()),
}
}
func (ResourceDefinitionMatchingRule) Edges() []ent.Edge {
return []ent.Edge{
edge.To("resource_definition", ResourceDefinition.Type).
Field("resource_definition_id").
Comment("Resource definition that connect to the relationship.").
Unique().
Required().
Immutable().
Annotations(
entsql.OnDelete(entsql.Cascade),
entx.SkipIO()),
edge.To("template", TemplateVersion.Type).
Field("template_id").
Comment("Template version that connect to the relationship.").
Unique().
Required().
Annotations(
entsql.OnDelete(entsql.Restrict),
entx.Input(entx.WithUpdate())),
edge.To("resources", Resource.Type).
Comment("Resources that match the rule.").
Annotations(
entsql.OnDelete(entsql.Restrict),
entx.SkipIO()),
}
}
func (ResourceDefinitionMatchingRule) Annotations() []schema.Annotation {
return []schema.Annotation{
entx.SkipClearingOptionalField(),
}
}