Files
bj_power/bj_power_mes/schema/role.go
T

49 lines
1.4 KiB
Go
Raw Normal View History

package schema
import (
"time"
"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"
)
// Role 角色,RBAC权限体系中的角色定义
type Role struct {
ent.Schema
}
func (Role) Annotations() []schema.Annotation {
return []schema.Annotation{
entsql.Annotation{
Table: "role",
Options: "COMMENT='角色表,RBAC权限体系中的角色定义,关联用户和权限资源'",
},
entsql.WithComments(true),
}
}
func (Role) Fields() []ent.Field {
return []ent.Field{
field.Int("id").Positive().Comment("主键ID"),
field.String("name").MaxLen(20).NotEmpty().Unique().Comment("角色名,如 管理员/操作员/质检员,不超过20个字符"),
field.String("description").SchemaType(
map[string]string{
dialect.MySQL: "text",
dialect.Postgres: "varchar",
}).MaxLen(60).Optional().Comment("角色描述,说明角色职责,不超过60个字符"),
field.Time("createdAt").Default(time.Now).Immutable().Comment("创建时间"),
field.Time("updatedAt").Default(time.Now).UpdateDefault(time.Now).Comment("更新时间"),
}
}
func (Role) Edges() []ent.Edge {
return []ent.Edge{
edge.To("users", User.Type).Comment("拥有该角色的用户列表"),
edge.To("permissions", Permission.Type).Comment("角色拥有的权限列表"),
}
}