2026-08-27 10:09:54 +08:00
|
|
|
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"
|
|
|
|
|
)
|
|
|
|
|
|
2026-08-27 10:56:41 +08:00
|
|
|
// Role holds the schema definition for the Role entity.
|
2026-08-27 10:09:54 +08:00
|
|
|
type Role struct {
|
|
|
|
|
ent.Schema
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (Role) Annotations() []schema.Annotation {
|
|
|
|
|
return []schema.Annotation{
|
2026-08-27 10:56:41 +08:00
|
|
|
entsql.Annotation{Table: "role"},
|
2026-08-27 10:09:54 +08:00
|
|
|
entsql.WithComments(true),
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-08-27 10:56:41 +08:00
|
|
|
// Fields of the Role.
|
2026-08-27 10:09:54 +08:00
|
|
|
func (Role) Fields() []ent.Field {
|
|
|
|
|
return []ent.Field{
|
2026-08-27 10:56:41 +08:00
|
|
|
field.Int("id").Positive(),
|
|
|
|
|
field.String("name").MaxLen(20).NotEmpty().Unique().Comment("角色名, 不能超过20个字符"),
|
2026-08-27 10:09:54 +08:00
|
|
|
field.String("description").SchemaType(
|
|
|
|
|
map[string]string{
|
|
|
|
|
dialect.MySQL: "text",
|
|
|
|
|
dialect.Postgres: "varchar",
|
2026-08-27 10:56:41 +08:00
|
|
|
}).MaxLen(60).Optional().Comment("描述, 不能超过60个字符"),
|
|
|
|
|
field.Time("createdAt").Default(time.Now).Immutable().Comment("创建时间"), // 创建时间
|
|
|
|
|
field.Time("updatedAt").Default(time.Now).UpdateDefault(time.Now).Comment("更新时间"), // 更新时间
|
2026-08-27 10:09:54 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-08-27 10:56:41 +08:00
|
|
|
// Edges of the Role.
|
2026-08-27 10:09:54 +08:00
|
|
|
func (Role) Edges() []ent.Edge {
|
|
|
|
|
return []ent.Edge{
|
2026-08-27 10:56:41 +08:00
|
|
|
edge.To("users", User.Type),
|
|
|
|
|
edge.To("permissions", Permission.Type),
|
2026-08-27 10:09:54 +08:00
|
|
|
}
|
|
|
|
|
}
|