mirror of
https://github.com/hay-kot/homebox.git
synced 2025-07-26 12:30:27 +00:00
refactor schema edges
This commit is contained in:
parent
ccd40ffcac
commit
883468e04c
12 changed files with 499 additions and 460 deletions
|
@ -2,11 +2,9 @@ package schema
|
|||
|
||||
import (
|
||||
"entgo.io/ent"
|
||||
"entgo.io/ent/schema/edge"
|
||||
"entgo.io/ent/schema/field"
|
||||
"entgo.io/ent/schema/index"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"github.com/hay-kot/homebox/backend/internal/data/ent/schema/mixins"
|
||||
)
|
||||
|
||||
|
@ -17,14 +15,20 @@ type Notifier struct {
|
|||
func (Notifier) Mixin() []ent.Mixin {
|
||||
return []ent.Mixin{
|
||||
mixins.BaseMixin{},
|
||||
GroupMixin{
|
||||
ref: "notifiers",
|
||||
field: "group_id",
|
||||
},
|
||||
UserMixin{
|
||||
ref: "notifiers",
|
||||
field: "user_id",
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
// Fields of the Notifier.
|
||||
func (Notifier) Fields() []ent.Field {
|
||||
return []ent.Field{
|
||||
field.UUID("user_id", uuid.UUID{}),
|
||||
field.UUID("group_id", uuid.UUID{}),
|
||||
field.String("name").
|
||||
MaxLen(255).
|
||||
NotEmpty(),
|
||||
|
@ -37,22 +41,6 @@ func (Notifier) Fields() []ent.Field {
|
|||
}
|
||||
}
|
||||
|
||||
// Edges of the Notifier.
|
||||
func (Notifier) Edges() []ent.Edge {
|
||||
return []ent.Edge{
|
||||
edge.From("user", User.Type).
|
||||
Field("user_id").
|
||||
Ref("notifiers").
|
||||
Required().
|
||||
Unique(),
|
||||
edge.From("group", Group.Type).
|
||||
Field("group_id").
|
||||
Ref("notifiers").
|
||||
Required().
|
||||
Unique(),
|
||||
}
|
||||
}
|
||||
|
||||
func (Notifier) Indexes() []ent.Index {
|
||||
return []ent.Index{
|
||||
index.Fields("user_id"),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue