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
52 lines
839 B
Go
52 lines
839 B
Go
package schema
|
|
|
|
import (
|
|
"entgo.io/ent"
|
|
"entgo.io/ent/schema/edge"
|
|
"entgo.io/ent/schema/field"
|
|
"entgo.io/ent/schema/mixin"
|
|
"github.com/google/uuid"
|
|
)
|
|
|
|
type UserStaff struct {
|
|
ent.Schema
|
|
}
|
|
|
|
func (UserStaff) Fields() []ent.Field {
|
|
return []ent.Field{
|
|
field.UUID("id", uuid.UUID{}).
|
|
Default(uuid.New).
|
|
Immutable().
|
|
Unique(),
|
|
|
|
field.UUID("user_id", uuid.UUID{}).
|
|
Immutable(),
|
|
|
|
field.UUID("site_id", uuid.UUID{}).
|
|
Immutable(),
|
|
}
|
|
}
|
|
|
|
func (UserStaff) Edges() []ent.Edge {
|
|
return []ent.Edge{
|
|
edge.From("users", User.Type).
|
|
Field("user_id").
|
|
Ref("staffs").
|
|
Unique().
|
|
Immutable().
|
|
Required(),
|
|
|
|
edge.From("site", Site.Type).
|
|
Field("site_id").
|
|
Ref("site_members").
|
|
Unique().
|
|
Immutable().
|
|
Required(),
|
|
}
|
|
}
|
|
|
|
func (UserStaff) Mixin() []ent.Mixin {
|
|
return []ent.Mixin{
|
|
mixin.Time{},
|
|
}
|
|
}
|