-
Notifications
You must be signed in to change notification settings - Fork 0
/
product_qty.go
92 lines (85 loc) · 1.95 KB
/
product_qty.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
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"
"github.com/shopspring/decimal"
)
// ProductQty holds the schema definition for the ProductQty entity.
type ProductQty struct {
ent.Schema
}
// Annotations of the ProductQty.
func (ProductQty) Annotations() []schema.Annotation {
return []schema.Annotation{
entsql.Annotation{Table: "product_qty"},
}
}
// Fields of the ProductQty.
func (ProductQty) Fields() []ent.Field {
return []ent.Field{
field.UUID("id", uuid.UUID{}).
Default(uuid.New).
Immutable(),
field.UUID("work_unit_id", uuid.UUID{}).
Immutable(),
field.String("product_id").
Immutable().
NotEmpty(),
field.String("product_color_id").
Immutable().
NotEmpty(),
field.Float("price_per_unit").
GoType(decimal.Decimal{}).
Nillable().
SchemaType(map[string]string{
dialect.Postgres: "numeric(12,2)",
dialect.MySQL: "decimal(12,2)",
}),
field.Float("qty").
GoType(decimal.Decimal{}).
Nillable().
SchemaType(map[string]string{
dialect.Postgres: "numeric(12,2)",
dialect.MySQL: "decimal(12,2)",
}),
}
}
// Edges of the ProductQty.
func (ProductQty) Edges() []ent.Edge {
return []ent.Edge{
edge.To("work_unit", WorkUnitInfo.Type).
Field("work_unit_id").
Unique().
Required().
Immutable(),
edge.To("product", ProductInfo.Type).
Field("product_id").
Unique().
Required().
Immutable(),
edge.To("product_color", ProductColor.Type).
Field("product_color_id").
Unique().
Required().
Immutable(),
}
}
// Indexes of the ProductQty.
func (ProductQty) Indexes() []ent.Index {
return []ent.Index{
index.Fields("work_unit_id", "product_id", "product_color_id").
Unique(),
}
}
// Mixin of the ProductQty
func (ProductQty) Mixin() []ent.Mixin {
return []ent.Mixin{
TimeMixin{},
}
}