package schema import ( "entgo.io/ent" "entgo.io/ent/schema/field" "entgo.io/ent/schema/index" ) // User 用户 type User struct { ent.Schema } func (User) Fields() []ent.Field { return []ent.Field{ field.String("username").Unique().Comment("登录名"), field.String("password").Comment("密码(哈希)"), field.String("real_name").Optional().Comment("姓名"), field.String("role").Default("operator").Comment("角色 admin/operator/inspector"), field.String("dept").Optional().Comment("部门"), field.String("phone").Optional().Comment("电话"), field.Bool("is_active").Default(true).Comment("是否启用"), field.Int64("last_login_at").Optional().Comment("最近登录时间"), field.Int64("created_at").DefaultFunc(nowUnix), field.Int64("updated_at").DefaultFunc(nowUnix), } } func (User) Indexes() []ent.Index { return []ent.Index{ index.Fields("role"), } }