mirror of
https://github.com/hay-kot/homebox.git
synced 2025-07-26 12:30:27 +00:00
refactor schema folder
This commit is contained in:
parent
77fb37ebf4
commit
9fa4da819f
22 changed files with 723 additions and 735 deletions
|
@ -5,6 +5,7 @@ import (
|
|||
"entgo.io/ent/dialect/entsql"
|
||||
"entgo.io/ent/schema/edge"
|
||||
"entgo.io/ent/schema/field"
|
||||
"entgo.io/ent/schema/mixin"
|
||||
"github.com/hay-kot/homebox/backend/internal/data/ent/schema/mixins"
|
||||
)
|
||||
|
||||
|
@ -33,34 +34,36 @@ func (Group) Fields() []ent.Field {
|
|||
|
||||
// Edges of the Home.
|
||||
func (Group) Edges() []ent.Edge {
|
||||
owned := func(name string, t any) ent.Edge {
|
||||
return edge.To(name, t).
|
||||
Annotations(entsql.Annotation{
|
||||
OnDelete: entsql.Cascade,
|
||||
})
|
||||
}
|
||||
|
||||
return []ent.Edge{
|
||||
edge.To("users", User.Type).
|
||||
Annotations(entsql.Annotation{
|
||||
OnDelete: entsql.Cascade,
|
||||
}),
|
||||
edge.To("locations", Location.Type).
|
||||
Annotations(entsql.Annotation{
|
||||
OnDelete: entsql.Cascade,
|
||||
}),
|
||||
edge.To("items", Item.Type).
|
||||
Annotations(entsql.Annotation{
|
||||
OnDelete: entsql.Cascade,
|
||||
}),
|
||||
edge.To("labels", Label.Type).
|
||||
Annotations(entsql.Annotation{
|
||||
OnDelete: entsql.Cascade,
|
||||
}),
|
||||
edge.To("documents", Document.Type).
|
||||
Annotations(entsql.Annotation{
|
||||
OnDelete: entsql.Cascade,
|
||||
}),
|
||||
edge.To("invitation_tokens", GroupInvitationToken.Type).
|
||||
Annotations(entsql.Annotation{
|
||||
OnDelete: entsql.Cascade,
|
||||
}),
|
||||
edge.To("notifiers", Notifier.Type).
|
||||
Annotations(entsql.Annotation{
|
||||
OnDelete: entsql.Cascade,
|
||||
}),
|
||||
owned("users", User.Type),
|
||||
owned("locations", Location.Type),
|
||||
owned("items", Item.Type),
|
||||
owned("labels", Label.Type),
|
||||
owned("documents", Document.Type),
|
||||
owned("invitation_tokens", GroupInvitationToken.Type),
|
||||
owned("notifiers", Notifier.Type),
|
||||
}
|
||||
}
|
||||
|
||||
// GroupMixin when embedded in an ent.Schema, adds a reference to
|
||||
// the Group entity.
|
||||
type GroupMixin struct {
|
||||
ref string
|
||||
mixin.Schema
|
||||
}
|
||||
|
||||
func (g GroupMixin) Edges() []ent.Edge {
|
||||
return []ent.Edge{
|
||||
edge.From("group", Group.Type).
|
||||
Ref(g.ref).
|
||||
Unique().
|
||||
Required(),
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue