31 lines
562 B
Go
31 lines
562 B
Go
package schema
|
|
|
|
import (
|
|
"time"
|
|
|
|
"entgo.io/ent"
|
|
"entgo.io/ent/schema/field"
|
|
"entgo.io/ent/schema/index"
|
|
)
|
|
|
|
type PostLikes struct {
|
|
ent.Schema
|
|
}
|
|
|
|
func (PostLikes) Fields() []ent.Field {
|
|
return []ent.Field{
|
|
field.Int64("id").Immutable().Unique(),
|
|
field.Int64("post_id"),
|
|
field.Int64("user_id"),
|
|
field.Time("created_at").Default(time.Now).Immutable(),
|
|
}
|
|
}
|
|
|
|
func (PostLikes) Indexes() []ent.Index {
|
|
return []ent.Index{
|
|
index.Fields("post_id", "user_id").Unique(),
|
|
index.Fields("user_id", "post_id"),
|
|
index.Fields("user_id", "created_at"),
|
|
}
|
|
}
|