41 lines
851 B
Go
41 lines
851 B
Go
|
package schema
|
||
|
|
||
|
import (
|
||
|
"entgo.io/ent"
|
||
|
"entgo.io/ent/schema/edge"
|
||
|
"entgo.io/ent/schema/field"
|
||
|
"entgo.io/ent/schema/index"
|
||
|
)
|
||
|
|
||
|
// UserSession holds the schema definition for the UserSession entity.
|
||
|
type UserSession struct {
|
||
|
ent.Schema
|
||
|
}
|
||
|
|
||
|
// Fields of the UserSession.
|
||
|
func (UserSession) Fields() []ent.Field {
|
||
|
return []ent.Field{
|
||
|
fieldID,
|
||
|
field.Time("issued_at"),
|
||
|
field.Time("expires_at"),
|
||
|
field.Bool("invalidated").Optional().Default(false),
|
||
|
field.String("user_agent").MaxLen(50),
|
||
|
field.String("ip").MaxLen(40),
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// Edges of the UserSession.
|
||
|
func (UserSession) Edges() []ent.Edge {
|
||
|
return []ent.Edge{
|
||
|
edge.From("user", User.Type).Ref("sessions").Unique().Required(),
|
||
|
}
|
||
|
}
|
||
|
|
||
|
func (UserSession) Indexes() []ent.Index {
|
||
|
return []ent.Index{
|
||
|
index.Fields("expires_at"),
|
||
|
index.Fields("invalidated"),
|
||
|
index.Fields("ip"),
|
||
|
}
|
||
|
}
|