searcherside/infrastructure/db/schema/user.go
Peter Kurfer 9ea9a8f658
Some checks failed
Go build / build (push) Failing after 1m58s
feat: continue basic setup
- setup ent scheme
- add command to create users
- document API
- add helpers to create migrations
- add command to run migrations
- add basic compose file
2024-06-19 21:19:37 +02:00

69 lines
1.1 KiB
Go

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(),
}
}