-
Notifications
You must be signed in to change notification settings - Fork 0
/
resource.go
63 lines (58 loc) · 1.7 KB
/
resource.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
package schema
import (
"entgo.io/ent"
"entgo.io/ent/schema/edge"
"entgo.io/ent/schema/field"
pgrpc "github.com/cble-platform/cble-provider-grpc/pkg/provider"
"github.com/cble-platform/cble/backend/engine/models"
"github.com/cble-platform/cble/backend/ent/mixins"
"github.com/google/uuid"
)
// Resource holds the schema definition for the Resource entity.
type Resource struct {
ent.Schema
}
// Fields of the Resource.
func (Resource) Fields() []ent.Field {
return []ent.Field{
field.UUID("id", uuid.UUID{}).
Immutable().
Default(uuid.New),
field.Enum("type").
Values("resource", "data").
Default("resource"),
field.String("key").
Comment("The resource/data key from the blueprint"),
field.String("resource_type").
Comment("The resource/data string from the blueprint"),
field.JSON("features", pgrpc.Features{}).
Optional().
Default(pgrpc.Features{}).
Comment("The features supported by this resource"),
field.JSON("quota_requirements", pgrpc.QuotaRequirements{}).
Optional().
Default(pgrpc.QuotaRequirements{}).
Comment("The quota space required by this resource"),
field.JSON("object", &models.Object{}).
Comment("The entire resource/data object from the blueprint"),
}
}
// Edges of the Resource.
func (Resource) Edges() []ent.Edge {
return []ent.Edge{
edge.To("blueprint", Blueprint.Type).
Unique().
Required().
Comment("Blueprint containing this resource"),
edge.To("required_by", Resource.Type).
Comment("Stores all dependents of this resource").
From("depends_on").
Comment("Stores all dependencies of this resource"),
}
}
// Mixins of the Resource.
func (Resource) Mixin() []ent.Mixin {
return []ent.Mixin{
mixins.Timestamps{},
}
}