Files
Local_Perplexity/ent/schema/user.go
2026-02-07 12:37:56 +03:00

54 lines
1.3 KiB
Go

package schema
import (
"entgo.io/ent"
"entgo.io/ent/dialect/entsql"
"entgo.io/ent/schema"
"entgo.io/ent/schema/field"
"entgo.io/ent/schema/index"
)
type User struct{ ent.Schema }
func (User) Annotations() []schema.Annotation {
return []schema.Annotation{
entsql.WithComments(true),
schema.Comment("Пользователи системы"),
}
}
func (User) Mixin() []ent.Mixin {
return []ent.Mixin{
PkMixin{},
RegisteredMixin{},
}
}
func (User) Fields() []ent.Field {
return []ent.Field{
field.String("login").NotEmpty().Unique().
MaxLen(128).Annotations(
entsql.Check("char_length(login) <= 128"),
),
field.String("password").NotEmpty().
MaxLen(256).Annotations(
entsql.Check("char_length(password) <= 256"),
).Comment("Хэш пароля"),
field.String("role").NotEmpty().
Default("user").
MaxLen(64).Annotations(
entsql.Check("char_length(role) <= 64"),
).Comment("Роль пользователя"),
field.Bool("is_active").Default(true).Comment("Активность"),
field.Bool("is_temporal").Default(true).Comment("Пароль временный и хранится в открытом виде"),
// field.UUID("ldap_id").NotEmpty().Unique(),
// field.String("ldap_dn").NotEmpty().Unique(),
}
}
func (User) Indexes() []ent.Index {
return []ent.Index{
index.Fields("is_active"),
}
}