54 lines
1.5 KiB
Go
54 lines
1.5 KiB
Go
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(),
|
|
field.Bool("phone_verified").Default(false),
|
|
field.String("pwd_salt").MaxLen(250).NotEmpty(),
|
|
field.String("pwd_hash").MaxLen(250).NotEmpty(),
|
|
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")),
|
|
}
|
|
}
|
|
|
|
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"),
|
|
}
|
|
}
|