This commit is contained in:
2024-08-19 13:18:59 +02:00
parent 11822c6a36
commit 7548c9a304
11 changed files with 189 additions and 0 deletions

3
ent/generate.go Normal file
View File

@ -0,0 +1,3 @@
package ent
//go:generate go run -mod=mod entgo.io/ent/cmd/ent generate ./schema

36
ent/schema/account.go Normal file
View File

@ -0,0 +1,36 @@
package schema
import (
"entgo.io/ent"
"entgo.io/ent/dialect/entsql"
"entgo.io/ent/schema/edge"
"entgo.io/ent/schema/field"
"github.com/google/uuid"
"time"
)
// Account holds the schema definition for the Account entity.
type Account struct {
ent.Schema
}
// Fields of the Account.
func (Account) Fields() []ent.Field {
return []ent.Field{
field.UUID("id", uuid.UUID{}).Unique().Immutable().Annotations(&entsql.Annotation{Default: "gen_random_uuid()"}),
field.Time("created_at").Default(time.Now).Immutable(),
field.Time("updated_at").Default(time.Now).UpdateDefault(time.Now),
field.String("nickname"),
field.String("name"),
field.Bytes("secret"),
field.Bytes("aes").MinLen(16).MaxLen(32),
field.Bytes("x509"),
}
}
// Edges of the Account.
func (Account) Edges() []ent.Edge {
return []ent.Edge{
edge.To("emails", Email.Type),
}
}

33
ent/schema/email.go Normal file
View File

@ -0,0 +1,33 @@
package schema
import (
"entgo.io/ent"
"entgo.io/ent/dialect/entsql"
"entgo.io/ent/schema/edge"
"entgo.io/ent/schema/field"
"github.com/google/uuid"
)
// Email holds the schema definition for the Email entity.
type Email struct {
ent.Schema
}
// Fields of the Email.
func (Email) Fields() []ent.Field {
return []ent.Field{
field.UUID("id", uuid.UUID{}).Unique().Immutable().Annotations(&entsql.Annotation{Default: "gen_random_uuid()"}),
field.String("email"),
field.Bool("primary").Default(false),
field.Bool("verified").Default(false),
field.String("verification_code").Optional(),
field.String("reset_code").Optional(),
}
}
// Edges of the Email.
func (Email) Edges() []ent.Edge {
return []ent.Edge{
edge.From("accounts", Account.Type).Ref("emails").Unique(),
}
}