Files
2026-04-24 13:24:58 +08:00

37 lines
738 B
Go

package schema
import (
"time"
"entgo.io/ent"
"entgo.io/ent/schema/field"
"entgo.io/ent/schema/index"
)
type Favorites struct {
ent.Schema
}
func (Favorites) Fields() []ent.Field {
return []ent.Field{
field.Int64("id").Unique().Immutable(),
field.Int64("user_id"),
field.String("target_type").MaxLen(20),
field.Int64("target_id"),
field.Time("created_at").Default(time.Now).Immutable(),
}
}
func (Favorites) Indexes() []ent.Index {
return []ent.Index{
index.Fields("user_id", "target_type", "target_id").Unique(),
index.Fields("user_id", "created_at"),
index.Fields("target_type", "target_id"),
index.Fields("user_id", "target_type", "created_at"),
}
}
func (Favorites) Edges() []ent.Edge {
return nil
}