Files
bj_power/bj_power_mes/schema/role.go
T

40 lines
1.1 KiB
Go

package schema
import (
"time"
"entgo.io/ent"
"entgo.io/ent/dialect"
"entgo.io/ent/dialect/entsql"
"entgo.io/ent/schema"
"entgo.io/ent/schema/field"
"entgo.io/ent/schema/index"
)
// Role 角色:承载菜单/按钮权限
type Role struct {
ent.Schema
}
func (Role) Annotations() []schema.Annotation {
return []schema.Annotation{entsql.Annotation{Table: "role"}, entsql.WithComments(true), schema.Comment("Role 角色:承载菜单/按钮权限")}
}
func (Role) Fields() []ent.Field {
return []ent.Field{
field.Int("id").Positive(),
field.String("name").MaxLen(64).Comment("角色名称"),
field.String("code").Unique().MaxLen(64).Comment("角色编码"),
field.String("remark").Default("").MaxLen(255),
field.JSON("permissionCodes", []string{}).Optional().SchemaType(map[string]string{
dialect.Postgres: "jsonb",
}).Comment("权限编码列表,如 produce.workorder:view"),
field.Time("createdAt").Default(time.Now).Immutable(),
field.Time("updatedAt").Default(time.Now).UpdateDefault(time.Now).Optional().Nillable().Comment("更新时间"),
}
}
func (Role) Indexes() []ent.Index {
return []ent.Index{index.Fields("code").Unique()}
}