50 lines
1.3 KiB
Go
50 lines
1.3 KiB
Go
package schema
|
|
|
|
import (
|
|
"time"
|
|
|
|
"entgo.io/ent"
|
|
"entgo.io/ent/dialect/entsql"
|
|
"entgo.io/ent/schema"
|
|
"entgo.io/ent/schema/edge"
|
|
"entgo.io/ent/schema/field"
|
|
)
|
|
|
|
// Permission holds the schema definition for the Permission entity.
|
|
type Permission struct {
|
|
ent.Schema
|
|
}
|
|
|
|
func (Permission) Annotations() []schema.Annotation {
|
|
return []schema.Annotation{
|
|
entsql.Annotation{Table: "permission"},
|
|
entsql.WithComments(true),
|
|
}
|
|
}
|
|
|
|
// Fields of the Permission.
|
|
func (Permission) Fields() []ent.Field {
|
|
return []ent.Field{
|
|
field.Int("id").Positive(),
|
|
field.String("name").MaxLen(20).NotEmpty().Comment("权限名称"),
|
|
field.String("code").MaxLen(40).NotEmpty().Comment("权限代码"),
|
|
field.Int("parentId").Optional().Nillable().Comment("父权限ID"),
|
|
field.String("sort").Default("0").Comment("排序号"),
|
|
field.Bool("isMenu").Default(false).Comment("是否菜单"),
|
|
field.String("description").MaxLen(60).Optional().Comment("权限描述"),
|
|
field.Time("createdAt").Default(time.Now).Immutable().Comment("创建时间"), // 创建时间
|
|
}
|
|
}
|
|
|
|
// Edges of the Permission.
|
|
func (Permission) Edges() []ent.Edge {
|
|
return []ent.Edge{
|
|
edge.From("roles", Role.Type).Ref("permissions"),
|
|
edge.To("apis", Api.Type),
|
|
edge.To("children", Permission.Type).
|
|
From("parent").
|
|
Field("parentId").
|
|
Unique(),
|
|
}
|
|
}
|