feat: community RPC 从内存存储迁移到 ent 数据库

This commit is contained in:
zetaloop
2026-04-24 08:16:31 +08:00
parent 5ad579f03c
commit 6cc14479c5
69 changed files with 14396 additions and 501 deletions
@@ -0,0 +1,64 @@
// Code generated by ent, DO NOT EDIT.
package migrate
import (
"context"
"fmt"
"io"
"entgo.io/ent/dialect"
"entgo.io/ent/dialect/sql/schema"
)
var (
// WithGlobalUniqueID sets the universal ids options to the migration.
// If this option is enabled, ent migration will allocate a 1<<32 range
// for the ids of each entity (table).
// Note that this option cannot be applied on tables that already exist.
WithGlobalUniqueID = schema.WithGlobalUniqueID
// WithDropColumn sets the drop column option to the migration.
// If this option is enabled, ent migration will drop old columns
// that were used for both fields and edges. This defaults to false.
WithDropColumn = schema.WithDropColumn
// WithDropIndex sets the drop index option to the migration.
// If this option is enabled, ent migration will drop old indexes
// that were defined in the schema. This defaults to false.
// Note that unique constraints are defined using `UNIQUE INDEX`,
// and therefore, it's recommended to enable this option to get more
// flexibility in the schema changes.
WithDropIndex = schema.WithDropIndex
// WithForeignKeys enables creating foreign-key in schema DDL. This defaults to true.
WithForeignKeys = schema.WithForeignKeys
)
// Schema is the API for creating, migrating and dropping a schema.
type Schema struct {
drv dialect.Driver
}
// NewSchema creates a new schema client.
func NewSchema(drv dialect.Driver) *Schema { return &Schema{drv: drv} }
// Create creates all schema resources.
func (s *Schema) Create(ctx context.Context, opts ...schema.MigrateOption) error {
return Create(ctx, s, Tables, opts...)
}
// Create creates all table resources using the given schema driver.
func Create(ctx context.Context, s *Schema, tables []*schema.Table, opts ...schema.MigrateOption) error {
migrate, err := schema.NewMigrate(s.drv, opts...)
if err != nil {
return fmt.Errorf("ent/migrate: %w", err)
}
return migrate.Create(ctx, tables...)
}
// WriteTo writes the schema changes to w instead of running them against the database.
//
// if err := client.Schema.WriteTo(context.Background(), os.Stdout); err != nil {
// log.Fatal(err)
// }
func (s *Schema) WriteTo(ctx context.Context, w io.Writer, opts ...schema.MigrateOption) error {
return Create(ctx, &Schema{drv: &schema.WriteDriver{Writer: w, Driver: s.drv}}, Tables, opts...)
}
@@ -0,0 +1,155 @@
// Code generated by ent, DO NOT EDIT.
package migrate
import (
"entgo.io/ent/dialect/sql/schema"
"entgo.io/ent/schema/field"
)
var (
// CommentLikesColumns holds the columns for the "comment_likes" table.
CommentLikesColumns = []*schema.Column{
{Name: "id", Type: field.TypeInt64, Increment: true},
{Name: "comment_id", Type: field.TypeInt64},
{Name: "user_id", Type: field.TypeInt64},
{Name: "created_at", Type: field.TypeTime},
}
// CommentLikesTable holds the schema information for the "comment_likes" table.
CommentLikesTable = &schema.Table{
Name: "comment_likes",
Columns: CommentLikesColumns,
PrimaryKey: []*schema.Column{CommentLikesColumns[0]},
Indexes: []*schema.Index{
{
Name: "commentlikes_comment_id_user_id",
Unique: true,
Columns: []*schema.Column{CommentLikesColumns[1], CommentLikesColumns[2]},
},
{
Name: "commentlikes_user_id_comment_id",
Unique: false,
Columns: []*schema.Column{CommentLikesColumns[2], CommentLikesColumns[1]},
},
{
Name: "commentlikes_user_id_created_at",
Unique: false,
Columns: []*schema.Column{CommentLikesColumns[2], CommentLikesColumns[3]},
},
},
}
// CommentsColumns holds the columns for the "comments" table.
CommentsColumns = []*schema.Column{
{Name: "id", Type: field.TypeInt64, Increment: true},
{Name: "post_id", Type: field.TypeInt64},
{Name: "author_id", Type: field.TypeInt64},
{Name: "content", Type: field.TypeString},
{Name: "like_count", Type: field.TypeInt, Nullable: true, Default: 0},
{Name: "created_at", Type: field.TypeTime},
{Name: "deleted_at", Type: field.TypeTime, Nullable: true},
}
// CommentsTable holds the schema information for the "comments" table.
CommentsTable = &schema.Table{
Name: "comments",
Columns: CommentsColumns,
PrimaryKey: []*schema.Column{CommentsColumns[0]},
Indexes: []*schema.Index{
{
Name: "comments_post_id_created_at",
Unique: false,
Columns: []*schema.Column{CommentsColumns[1], CommentsColumns[5]},
},
{
Name: "comments_author_id_created_at",
Unique: false,
Columns: []*schema.Column{CommentsColumns[2], CommentsColumns[5]},
},
},
}
// PostLikesColumns holds the columns for the "post_likes" table.
PostLikesColumns = []*schema.Column{
{Name: "id", Type: field.TypeInt64, Increment: true},
{Name: "post_id", Type: field.TypeInt64},
{Name: "user_id", Type: field.TypeInt64},
{Name: "created_at", Type: field.TypeTime},
}
// PostLikesTable holds the schema information for the "post_likes" table.
PostLikesTable = &schema.Table{
Name: "post_likes",
Columns: PostLikesColumns,
PrimaryKey: []*schema.Column{PostLikesColumns[0]},
Indexes: []*schema.Index{
{
Name: "postlikes_post_id_user_id",
Unique: true,
Columns: []*schema.Column{PostLikesColumns[1], PostLikesColumns[2]},
},
{
Name: "postlikes_user_id_post_id",
Unique: false,
Columns: []*schema.Column{PostLikesColumns[2], PostLikesColumns[1]},
},
{
Name: "postlikes_user_id_created_at",
Unique: false,
Columns: []*schema.Column{PostLikesColumns[2], PostLikesColumns[3]},
},
},
}
// PostsColumns holds the columns for the "posts" table.
PostsColumns = []*schema.Column{
{Name: "id", Type: field.TypeInt64, Increment: true},
{Name: "author_id", Type: field.TypeInt64},
{Name: "author_role", Type: field.TypeString, Size: 20, Default: "consumer"},
{Name: "title", Type: field.TypeString, Size: 500},
{Name: "content", Type: field.TypeString},
{Name: "images", Type: field.TypeOther, Nullable: true, SchemaType: map[string]string{"postgres": "text[]"}},
{Name: "tags", Type: field.TypeOther, Nullable: true, SchemaType: map[string]string{"postgres": "text[]"}},
{Name: "linked_order_id", Type: field.TypeInt64, Nullable: true},
{Name: "quoted_post_id", Type: field.TypeInt64, Nullable: true},
{Name: "like_count", Type: field.TypeInt, Nullable: true, Default: 0},
{Name: "comment_count", Type: field.TypeInt, Nullable: true, Default: 0},
{Name: "pinned", Type: field.TypeBool, Nullable: true, Default: false},
{Name: "created_at", Type: field.TypeTime},
{Name: "updated_at", Type: field.TypeTime},
{Name: "deleted_at", Type: field.TypeTime, Nullable: true},
}
// PostsTable holds the schema information for the "posts" table.
PostsTable = &schema.Table{
Name: "posts",
Columns: PostsColumns,
PrimaryKey: []*schema.Column{PostsColumns[0]},
Indexes: []*schema.Index{
{
Name: "posts_author_id_created_at",
Unique: false,
Columns: []*schema.Column{PostsColumns[1], PostsColumns[12]},
},
{
Name: "posts_created_at",
Unique: false,
Columns: []*schema.Column{PostsColumns[12]},
},
{
Name: "posts_linked_order_id",
Unique: false,
Columns: []*schema.Column{PostsColumns[7]},
},
{
Name: "posts_quoted_post_id",
Unique: false,
Columns: []*schema.Column{PostsColumns[8]},
},
},
}
// Tables holds all the tables in the schema.
Tables = []*schema.Table{
CommentLikesTable,
CommentsTable,
PostLikesTable,
PostsTable,
}
)
func init() {
}