Files
muninn-aio/ent/schema/link.go

45 lines
739 B
Go

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"
)
// URL holds the schema definition for the URL entity.
type Link struct {
ent.Schema
}
// Fields of the URL.
func (Link) Fields() []ent.Field {
return []ent.Field{
field.UUID("id", uuid.UUID{}).
Default(uuid.New).
Unique().
Immutable(),
field.String("key").
Unique(),
field.String("original_url").
NotEmpty(),
}
}
func (Link) Indexes() []ent.Index {
return []ent.Index{
index.Fields("key").
Unique(),
}
}
// Edges of the URL.
func (Link) Edges() []ent.Edge {
return []ent.Edge{
edge.From("owner", User.Type).
Required().
Ref("links"),
}
}