feat: community RPC 从内存存储迁移到 ent 数据库
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
package schema
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"entgo.io/ent"
|
||||
"entgo.io/ent/schema/field"
|
||||
"entgo.io/ent/schema/index"
|
||||
)
|
||||
|
||||
type CommentLikes struct {
|
||||
ent.Schema
|
||||
}
|
||||
|
||||
func (CommentLikes) Fields() []ent.Field {
|
||||
return []ent.Field{
|
||||
field.Int64("id").Immutable().Unique(),
|
||||
field.Int64("comment_id"),
|
||||
field.Int64("user_id"),
|
||||
field.Time("created_at").Default(time.Now).Immutable(),
|
||||
}
|
||||
}
|
||||
|
||||
func (CommentLikes) Indexes() []ent.Index {
|
||||
return []ent.Index{
|
||||
index.Fields("comment_id", "user_id").Unique(),
|
||||
index.Fields("user_id", "comment_id"),
|
||||
index.Fields("user_id", "created_at"),
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
package schema
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"entgo.io/ent"
|
||||
"entgo.io/ent/schema/field"
|
||||
"entgo.io/ent/schema/index"
|
||||
)
|
||||
|
||||
type Comments struct {
|
||||
ent.Schema
|
||||
}
|
||||
|
||||
func (Comments) Fields() []ent.Field {
|
||||
return []ent.Field{
|
||||
field.Int64("id").Unique().Immutable(),
|
||||
field.Int64("post_id"),
|
||||
field.Int64("author_id"),
|
||||
field.String("content"),
|
||||
field.Int("like_count").Optional().Default(0),
|
||||
field.Time("created_at").Default(time.Now).Immutable(),
|
||||
field.Time("deleted_at").Optional().Nillable(),
|
||||
}
|
||||
}
|
||||
|
||||
func (Comments) Indexes() []ent.Index {
|
||||
return []ent.Index{
|
||||
index.Fields("post_id", "created_at"),
|
||||
index.Fields("author_id", "created_at"),
|
||||
}
|
||||
}
|
||||
|
||||
func (Comments) Edges() []ent.Edge {
|
||||
return nil
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
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"),
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
package schema
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"juwan-backend/pkg/types"
|
||||
|
||||
"entgo.io/ent"
|
||||
"entgo.io/ent/dialect"
|
||||
"entgo.io/ent/schema/field"
|
||||
"entgo.io/ent/schema/index"
|
||||
)
|
||||
|
||||
type Posts struct {
|
||||
ent.Schema
|
||||
}
|
||||
|
||||
func (Posts) Fields() []ent.Field {
|
||||
return []ent.Field{
|
||||
field.Int64("id").Unique().Immutable(),
|
||||
field.Int64("author_id"),
|
||||
field.String("author_role").MaxLen(20).Default("consumer"),
|
||||
field.String("title").MaxLen(500),
|
||||
field.String("content"),
|
||||
field.Other("images", types.TextArray{}).
|
||||
SchemaType(map[string]string{dialect.Postgres: "text[]"}).
|
||||
Optional(),
|
||||
field.Other("tags", types.TextArray{}).
|
||||
SchemaType(map[string]string{dialect.Postgres: "text[]"}).
|
||||
Optional(),
|
||||
field.Int64("linked_order_id").Optional().Nillable(),
|
||||
field.Int64("quoted_post_id").Optional().Nillable(),
|
||||
field.Int("like_count").Optional().Default(0),
|
||||
field.Int("comment_count").Optional().Default(0),
|
||||
field.Bool("pinned").Optional().Default(false),
|
||||
field.Time("created_at").Default(time.Now).Immutable(),
|
||||
field.Time("updated_at").Default(time.Now).UpdateDefault(time.Now),
|
||||
field.Time("deleted_at").Optional().Nillable(),
|
||||
}
|
||||
}
|
||||
|
||||
func (Posts) Indexes() []ent.Index {
|
||||
return []ent.Index{
|
||||
index.Fields("author_id", "created_at"),
|
||||
index.Fields("created_at"),
|
||||
index.Fields("linked_order_id"),
|
||||
index.Fields("quoted_post_id"),
|
||||
}
|
||||
}
|
||||
|
||||
func (Posts) Edges() []ent.Edge {
|
||||
return nil
|
||||
}
|
||||
Reference in New Issue
Block a user