Peter Kurfer
9ea9a8f658
Some checks failed
Go build / build (push) Failing after 1m58s
- setup ent scheme - add command to create users - document API - add helpers to create migrations - add command to run migrations - add basic compose file
69 lines
1.1 KiB
Go
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(),
|
|
}
|
|
}
|