searcherside/infrastructure/db/schema/user.go

70 lines
1.1 KiB
Go
Raw Permalink Normal View History

package schema
import (
"entgo.io/contrib/entgql"
"entgo.io/ent"
"entgo.io/ent/schema"
"entgo.io/ent/schema/edge"
"entgo.io/ent/schema/field"
"entgo.io/ent/schema/index"
"entgo.io/ent/schema/mixin"
"github.com/google/uuid"
)
type User struct {
ent.Schema
}
func (User) Fields() []ent.Field {
return []ent.Field{
field.UUID("id", uuid.UUID{}).
Default(uuid.New).
Immutable().
Unique(),
field.String("email").
NotEmpty().
Immutable().
Unique(),
field.String("given_name").
Optional(),
field.String("surname").
Optional(),
field.Bool("is_admin").
Default(false).
Annotations(entgql.Skip(entgql.SkipAll)),
field.Bytes("password").
NotEmpty().
Sensitive().
Annotations(entgql.Skip(entgql.SkipAll)),
}
}
func (User) Edges() []ent.Edge {
return []ent.Edge{
edge.To("staffs", UserStaff.Type),
}
}
func (User) Indexes() []ent.Index {
return []ent.Index{
index.Fields("email"),
}
}
func (User) Mixin() []ent.Mixin {
return []ent.Mixin{
mixin.Time{},
}
}
func (User) Annotations() []schema.Annotation {
return []schema.Annotation{
entgql.QueryField(),
}
}