Files
xuanzhi-service/server/.ai-specs/doc-sql/book_comment.sql
wdh-home 1e33640629
Some checks failed
CI / init (pull_request) Has been cancelled
CI / Frontend node 18.16.0 (pull_request) Has been cancelled
CI / Backend go (1.22) (pull_request) Has been cancelled
CI / release-pr (pull_request) Has been cancelled
CI / devops-test (1.22, 18.16.0) (pull_request) Has been cancelled
CI / release-please (pull_request) Has been cancelled
CI / devops-prod (1.22, 18.x) (pull_request) Has been cancelled
CI / docker (pull_request) Has been cancelled
基础项目
2026-04-26 15:32:21 +08:00

44 lines
2.1 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
-- # 书籍评论表
--
-- ## 基本信息
--
-- 模块book
-- 表名book_comment
-- 模型model/book/book_comment.go
-- 迁移接入initialize/gorm_biz.go
-- 删除策略硬删表
-- 评论状态字典book_comment_status
-- 职责承载书籍章节和文本行三级评论定位信息并冗余维护评论点赞聚合值
CREATE TABLE book_comment (
id bigserial PRIMARY KEY,
created_at timestamp with time zone NOT NULL DEFAULT CURRENT_TIMESTAMP,
updated_at timestamp with time zone NOT NULL DEFAULT CURRENT_TIMESTAMP,
member_user_id bigint NOT NULL,
book_id bigint NOT NULL,
chapter_id bigint NOT NULL DEFAULT 0 CHECK (chapter_id >= 0),
line_index integer NOT NULL DEFAULT 0 CHECK (line_index >= 0),
content text NOT NULL,
like_count bigint NOT NULL DEFAULT 0 CHECK (like_count >= 0),
comment_status varchar(32) NOT NULL DEFAULT 'normal',
CHECK ((chapter_id = 0 AND line_index = 0) OR (chapter_id > 0 AND line_index >= 0))
);
COMMENT ON TABLE book_comment IS '书籍评论表';
COMMENT ON COLUMN book_comment.id IS '主键';
COMMENT ON COLUMN book_comment.created_at IS '创建时间';
COMMENT ON COLUMN book_comment.updated_at IS '更新时间';
COMMENT ON COLUMN book_comment.member_user_id IS '评论用户的会员 ID';
COMMENT ON COLUMN book_comment.book_id IS '所属书籍 ID';
COMMENT ON COLUMN book_comment.chapter_id IS '评论目标章节 ID0 表示整本书';
COMMENT ON COLUMN book_comment.line_index IS '评论目标文本行下标0 表示整章或整本书';
COMMENT ON COLUMN book_comment.content IS '评论正文内容';
COMMENT ON COLUMN book_comment.like_count IS '评论点赞聚合值';
COMMENT ON COLUMN book_comment.comment_status IS '评论状态字典值对应 book_comment_status';
CREATE INDEX idx_book_comment_book_id ON book_comment (book_id);
CREATE INDEX idx_book_comment_book_id_chapter_id_line_index ON book_comment (book_id, chapter_id, line_index);
CREATE INDEX idx_book_comment_member_user_id ON book_comment (member_user_id);
CREATE INDEX idx_book_comment_comment_status ON book_comment (comment_status);
CREATE INDEX idx_book_comment_created_at ON book_comment (created_at);