82 lines
1.5 KiB
Go
82 lines
1.5 KiB
Go
package schema
|
|
|
|
import (
|
|
"entgo.io/ent"
|
|
"entgo.io/ent/schema/edge"
|
|
"entgo.io/ent/schema/field"
|
|
"entgo.io/ent/schema/index"
|
|
)
|
|
|
|
// LoginAudit holds the schema definition for the LoginAudit entity.
|
|
type LoginAudit struct {
|
|
ent.Schema
|
|
}
|
|
|
|
func (LoginAudit) Fields() []ent.Field {
|
|
return []ent.Field{
|
|
field.Int("user_id").
|
|
Optional().
|
|
Nillable(),
|
|
field.String("ip").
|
|
MaxLen(64).
|
|
Default(""),
|
|
field.String("user_agent").
|
|
MaxLen(512).
|
|
Default(""),
|
|
field.Enum("status").
|
|
Values("success", "fail").
|
|
Default("fail"),
|
|
field.String("fail_reason").
|
|
MaxLen(255).
|
|
Optional().
|
|
Nillable(),
|
|
field.String("location_iso").
|
|
MaxLen(8).
|
|
Optional().
|
|
Nillable(),
|
|
field.String("location_province").
|
|
MaxLen(64).
|
|
Optional().
|
|
Nillable(),
|
|
field.String("location_city").
|
|
MaxLen(64).
|
|
Optional().
|
|
Nillable(),
|
|
field.Time("logout_at").
|
|
Optional().
|
|
Nillable(),
|
|
field.Int("session_seconds").
|
|
Optional().
|
|
Nillable().
|
|
Default(0),
|
|
field.String("username_tried").
|
|
MaxLen(100).
|
|
Optional().
|
|
Nillable(),
|
|
}
|
|
}
|
|
|
|
func (LoginAudit) Edges() []ent.Edge {
|
|
return []ent.Edge{
|
|
edge.From("user", User.Type).
|
|
Ref("login_audits").
|
|
Field("user_id").
|
|
Unique(),
|
|
}
|
|
}
|
|
|
|
func (LoginAudit) Mixin() []ent.Mixin {
|
|
return []ent.Mixin{
|
|
CommonMixin{},
|
|
}
|
|
}
|
|
|
|
func (LoginAudit) Indexes() []ent.Index {
|
|
return []ent.Index{
|
|
index.Fields("user_id"),
|
|
index.Fields("ip"),
|
|
index.Fields("status"),
|
|
index.Fields("created_at"),
|
|
}
|
|
}
|