rano/db/ent/schema/user.go

55 lines
1.6 KiB
Go
Raw Permalink Normal View History

2024-11-10 09:22:33 +00:00
package schema
import (
"entgo.io/ent"
"entgo.io/ent/dialect/entsql"
"entgo.io/ent/schema/edge"
"entgo.io/ent/schema/field"
"entgo.io/ent/schema/index"
)
// User holds the schema definition for the User entity.
type User struct {
ent.Schema
}
// Fields of the User.
func (User) Fields() []ent.Field {
return []ent.Field{
fieldID,
fieldCreated,
fieldUpdated,
field.String("email").Unique().NotEmpty(),
field.Bool("email_verified").Default(false),
field.String("phone").MaxLen(20).Optional(),
2024-11-10 09:22:33 +00:00
field.Bool("phone_verified").Default(false),
2024-11-17 16:58:29 +00:00
field.String("pwd_salt").MaxLen(100).NotEmpty(),
field.String("pwd_hash").MaxLen(100).NotEmpty(),
2024-11-10 09:22:33 +00:00
field.Uint8("login_failed_count").Optional().Default(0),
field.Time("login_attempt_on").Optional().Nillable(),
field.Time("login_locked_until").Optional().Nillable(),
field.String("first_name").MaxLen(30),
field.String("middle_name").MaxLen(30).Nillable(),
field.String("last_name").MaxLen(30),
field.Enum("status").Values("Pending", "Active", "InActive").Default("Pending"),
}
}
// Edges of the User.
func (User) Edges() []ent.Edge {
return []ent.Edge{
edge.To("sessions", UserSession.Type).StorageKey(edge.Column("user_id")),
edge.To("audit_logs", Audit.Type).StorageKey(edge.Column("user_id")),
2024-11-17 16:58:29 +00:00
edge.To("verify_tokens", VerifyToken.Type).StorageKey(edge.Column("user_id")),
2024-11-10 09:22:33 +00:00
}
}
func (User) Indexes() []ent.Index {
return []ent.Index{
index.Fields("created_at").Annotations(entsql.Desc()),
index.Fields("updated_at").Annotations(entsql.Desc()),
index.Fields("phone"),
index.Fields("status"),
}
}