online-order/ent/schema/domain.go
2023-10-29 02:42:07 +03:30

34 lines
843 B
Go

package schema
import (
"entgo.io/ent"
"entgo.io/ent/schema/edge"
"entgo.io/ent/schema/field"
"time"
)
// Domain holds the schema definition for the Domain entity.
type Domain struct {
ent.Schema
}
// Fields of the Domain.
func (Domain) Fields() []ent.Field {
return []ent.Field{
field.String("domain").Unique(),
field.Int("business_id").Unique().Optional().Nillable(),
field.Int("user_id").Optional().Nillable(),
field.JSON("config", []string{}).Optional(),
field.Time("created_at").Default(time.Now),
field.Time("updated_at").Default(time.Now).UpdateDefault(time.Now),
}
}
// Edges of the Domain.
func (Domain) Edges() []ent.Edge {
return []ent.Edge{
edge.From("businesses", Business.Type).Ref("domains").Unique().Field("business_id"),
edge.From("users", User.Type).Ref("domains").Unique().Field("user_id"),
}
}