-
Notifications
You must be signed in to change notification settings - Fork 0
/
userpromocode.go
67 lines (53 loc) · 1.34 KB
/
userpromocode.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
package schema
import (
"entgo.io/ent"
"entgo.io/ent/dialect"
"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/google/uuid"
)
// UserPromoCode holds the schema definition for the UserPromoCode entity.
type UserPromoCode struct {
ent.Schema
}
func (UserPromoCode) Annotations() []schema.Annotation {
return []schema.Annotation{
entsql.Annotation{Table: "user_promo_codes"},
}
}
// Fields of the UserPromoCode.
func (UserPromoCode) Fields() []ent.Field {
return []ent.Field{
field.UUID("id", uuid.UUID{}).Default(uuid.New).Immutable(),
field.String("city"),
// Foreign key UUID has no default!
field.UUID("user_id", uuid.UUID{}),
field.String("code"),
field.Time("timestamp").Optional().
// Do not convert to session timezone
SchemaType(map[string]string{
dialect.Postgres: "TIMESTAMP",
}),
field.Int("usage_count").Optional(),
}
}
// Edges of the VehicleLocationHistory.
func (UserPromoCode) Edges() []ent.Edge {
return []ent.Edge{
// A UserPromoCode has one ride
edge.From("user", User.Type).
Ref("user_promo_codes").
Field("user_id").
Unique().
Required(),
}
}
// Indexes of the Vehicle.
func (UserPromoCode) Indexes() []ent.Index {
return []ent.Index{
index.Fields("city", "user_id", "code"),
}
}