-
-
Notifications
You must be signed in to change notification settings - Fork 281
/
role.go
62 lines (54 loc) · 1.44 KB
/
role.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
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/suyuan32/simple-admin-common/orm/ent/mixins"
)
type Role struct {
ent.Schema
}
func (Role) Fields() []ent.Field {
return []ent.Field{
field.String("name").
Comment("Role name | 角色名").
Annotations(entsql.WithComments(true)),
field.String("code").Unique().
Comment("Role code for permission control in front end | 角色码,用于前端权限控制").
Annotations(entsql.WithComments(true)),
field.String("default_router").Default("dashboard").
Comment("Default menu : dashboard | 默认登录页面").
Annotations(entsql.WithComments(true)),
field.String("remark").Default("").
Comment("Remark | 备注").
Annotations(entsql.WithComments(true)),
field.Uint32("sort").Default(0).
Comment("Order number | 排序编号").
Annotations(entsql.WithComments(true)),
}
}
func (Role) Mixin() []ent.Mixin {
return []ent.Mixin{
mixins.IDMixin{},
mixins.StatusMixin{},
}
}
func (Role) Edges() []ent.Edge {
return []ent.Edge{
edge.To("menus", Menu.Type),
edge.From("users", User.Type).Ref("roles"),
}
}
func (Role) Indexes() []ent.Index {
return []ent.Index{
index.Fields("code").Unique(),
}
}
func (Role) Annotations() []schema.Annotation {
return []schema.Annotation{
entsql.Annotation{Table: "sys_roles"},
}
}