ent seteup
This commit is contained in:
53
db/ent/schema/user.go
Normal file
53
db/ent/schema/user.go
Normal file
@@ -0,0 +1,53 @@
|
||||
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),
|
||||
field.Bool("phone_verified").Default(false),
|
||||
field.String("pwd_salt").NotEmpty(),
|
||||
field.String("pwd_hash").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"),
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user