98 lines
2.1 KiB
Go
98 lines
2.1 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"
|
|
"github.com/saas-mingyang/mingyang-admin-common/orm/ent/mixins"
|
|
mixins2 "mingyang-admin-app-rpc/ent/schema/mixins"
|
|
"time"
|
|
)
|
|
|
|
// UserLoginLog 定义用户登录日志实体
|
|
type UserLoginLog struct {
|
|
ent.Schema
|
|
}
|
|
|
|
func (UserLoginLog) Fields() []ent.Field {
|
|
return []ent.Field{
|
|
field.Uint64("user_id").Comment("用户ID"),
|
|
field.Time("login_time").
|
|
Default(time.Now),
|
|
field.String("login_ip").
|
|
NotEmpty().
|
|
MaxLen(45),
|
|
field.String("login_location").
|
|
Comment("登录位置").
|
|
Optional().
|
|
MaxLen(200),
|
|
field.Enum("login_type").
|
|
Values(
|
|
"password",
|
|
"sms_code",
|
|
"email_code",
|
|
"wechat",
|
|
"alipay",
|
|
"apple",
|
|
"google",
|
|
"other_third_party",
|
|
).
|
|
Default("password"),
|
|
field.Enum("login_platform").
|
|
Values(
|
|
"ios",
|
|
"android", "windows").
|
|
Default("android"),
|
|
field.Bool("login_result").
|
|
Comment("登录结果,是否成功").
|
|
Default(true),
|
|
field.String("failure_reason").
|
|
Optional().
|
|
MaxLen(500),
|
|
field.String("session_id").
|
|
Optional().
|
|
MaxLen(200),
|
|
field.Int("latency_ms").
|
|
Optional(),
|
|
field.Uint64("auth_id").Optional().Comment("auth_id"),
|
|
field.JSON("additional_data", map[string]interface{}{}).
|
|
Optional(),
|
|
}
|
|
}
|
|
|
|
func (UserLoginLog) Mixin() []ent.Mixin {
|
|
return []ent.Mixin{
|
|
mixins.IDMixin{},
|
|
mixins.StatusMixin{},
|
|
mixins.TenantMixin{},
|
|
mixins2.SoftDeleteMixin{},
|
|
}
|
|
}
|
|
|
|
func (UserLoginLog) Edges() []ent.Edge {
|
|
return []ent.Edge{}
|
|
|
|
}
|
|
|
|
func (UserLoginLog) Indexes() []ent.Index {
|
|
return []ent.Index{
|
|
index.Fields("user_id", "login_time"),
|
|
index.Fields("login_time"),
|
|
index.Fields("login_ip"),
|
|
index.Fields("login_type"),
|
|
index.Fields("login_platform"),
|
|
index.Fields("login_result"),
|
|
index.Fields("session_id"),
|
|
}
|
|
}
|
|
|
|
func (UserLoginLog) Annotations() []schema.Annotation {
|
|
return []schema.Annotation{
|
|
entsql.WithComments(true),
|
|
schema.Comment("user_login_logs Table | 用户登录信息表"),
|
|
entsql.Annotation{Table: "user_login_logs"},
|
|
}
|
|
}
|