You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
56 lines
1.2 KiB
Go
56 lines
1.2 KiB
Go
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"
|
|
mixins2 "git.noahlan.cn/n-admin/n-admin-server/rpc/core/ent/schema/mixins"
|
|
"git.noahlan.cn/noahlan/ntool-biz/core/orm/nent/mixins"
|
|
"git.noahlan.cn/noahlan/ntool/nrandom"
|
|
)
|
|
|
|
type Role struct {
|
|
ent.Schema
|
|
}
|
|
|
|
func (Role) Fields() []ent.Field {
|
|
return []ent.Field{
|
|
field.String("code").Unique().
|
|
Comment("Role Code | 角色编码,可用于权限控制"),
|
|
field.String("name").
|
|
Comment("Role Name | 角色名"),
|
|
field.String("description").
|
|
Comment("Description | 角色描述"),
|
|
}
|
|
}
|
|
|
|
func (Role) Mixin() []ent.Mixin {
|
|
return []ent.Mixin{
|
|
mixins.NewDistributedIDMixin(func() int64 { return nrandom.SnowflakeId() }),
|
|
mixins.TimeMixin{},
|
|
mixins.OptimisticLockMixin{},
|
|
mixins.StatusMixin{},
|
|
mixins2.SoftDeleteMixin{},
|
|
}
|
|
}
|
|
|
|
func (Role) Edges() []ent.Edge {
|
|
return []ent.Edge{
|
|
edge.From("users", User.Type).Ref("roles"), // 2m
|
|
}
|
|
}
|
|
|
|
func (Role) Indexes() []ent.Index {
|
|
return []ent.Index{}
|
|
}
|
|
|
|
func (Role) Annotations() []schema.Annotation {
|
|
return []schema.Annotation{
|
|
entsql.WithComments(true),
|
|
entsql.Annotation{Table: "sys_role"},
|
|
schema.Comment("系统角色表"),
|
|
}
|
|
}
|