-
Notifications
You must be signed in to change notification settings - Fork 0
/
conversation.go
61 lines (55 loc) · 1.18 KB
/
conversation.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
package schema
import (
"entgo.io/ent"
"entgo.io/ent/schema/edge"
"entgo.io/ent/schema/field"
"entgo.io/ent/schema/index"
"github.com/google/uuid"
)
// Conversation holds the schema definition for the Conversation entity.
type Conversation struct {
ent.Schema
}
// Fields of the Conversation.
func (Conversation) Fields() []ent.Field {
return []ent.Field{
field.UUID("id", uuid.UUID{}).
Default(uuid.New).
Immutable(),
field.String("title").
Optional().
Nillable(),
field.UUID("person_one_id", uuid.UUID{}).
Immutable(),
field.UUID("person_two_id", uuid.UUID{}).
Immutable(),
}
}
// Edges of the Conversation.
func (Conversation) Edges() []ent.Edge {
return []ent.Edge{
edge.To("person_one", Person.Type).
Field("person_one_id").
Unique().
Required().
Immutable(),
edge.To("person_two", Person.Type).
Field("person_two_id").
Unique().
Required().
Immutable(),
}
}
// Indexes of the Conversation.
func (Conversation) Indexes() []ent.Index {
return []ent.Index{
index.Fields("person_one_id", "person_two_id").
Unique(),
}
}
// Mixin of the Conversation.
func (Conversation) Mixin() []ent.Mixin {
return []ent.Mixin{
TimeMixin{},
}
}