pcmt/ent/schema/trackedbreaches.go
surtur 74546f996b
All checks were successful
continuous-integration/drone/push Build is passing
ent: add/extend entities, tests, validation
2023-08-19 04:52:15 +02:00

49 lines
1.1 KiB
Go

// Copyright 2023 wanderer <a_mirre at utb dot cz>
// SPDX-License-Identifier: AGPL-3.0-only
package schema
import (
"entgo.io/ent"
"entgo.io/ent/schema/edge"
"entgo.io/ent/schema/field"
"github.com/google/uuid"
)
// TrackedBreaches holds the schema definition for the TrackedBreaches entity.
type TrackedBreaches struct {
ent.Schema
}
// Fields of the TrackedBreaches.
func (TrackedBreaches) Fields() []ent.Field {
return []ent.Field{
field.UUID("id", uuid.UUID{}).
Default(uuid.New).
Unique().
Immutable(),
field.UUID("breach", uuid.UUID{}),
field.Bool("online").
Default(true).
Immutable().
Comment("Whether the breach is a locally added one or obtained from an online service"),
field.UUID("owner", uuid.UUID{}).
Comment("id of the user tracking the breach").
Immutable(),
}
}
// Edges of the TrackedBreaches.
func (TrackedBreaches) Edges() []ent.Edge {
return []ent.Edge{
edge.From("user", User.Type).
Ref("tracked_breaches").
Field("owner").
Unique().
Immutable().
Required(),
edge.To("localbreach", LocalBreach.Type),
edge.To("hibp", HIBP.Type),
}
}