-- # 评论点赞记录表
--
-- ## 基本信息
--
-- 模块：book
-- 表名：book_comment_like_record
-- 模型：model/book/book_comment_like_record.go
-- 迁移接入：initialize/gorm_biz.go
-- 删除策略：硬删表
-- 职责：承载用户对评论的有效点赞关系，支持点赞/取消点赞的幂等判断和计数维护。

CREATE TABLE book_comment_like_record (
  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,
  comment_id bigint NOT NULL,
  member_user_id bigint NOT NULL,
  liked_at timestamp with time zone NOT NULL DEFAULT CURRENT_TIMESTAMP
);

COMMENT ON TABLE book_comment_like_record IS '评论点赞记录表';
COMMENT ON COLUMN book_comment_like_record.id IS '主键';
COMMENT ON COLUMN book_comment_like_record.created_at IS '创建时间';
COMMENT ON COLUMN book_comment_like_record.updated_at IS '更新时间';
COMMENT ON COLUMN book_comment_like_record.comment_id IS '被点赞评论 ID';
COMMENT ON COLUMN book_comment_like_record.member_user_id IS '点赞用户的会员 ID';
COMMENT ON COLUMN book_comment_like_record.liked_at IS '点赞发生时间';

CREATE UNIQUE INDEX uk_book_comment_like_record_comment_id_member_user_id ON book_comment_like_record (comment_id, member_user_id);
CREATE INDEX idx_book_comment_like_record_member_user_id ON book_comment_like_record (member_user_id);
CREATE INDEX idx_book_comment_like_record_liked_at ON book_comment_like_record (liked_at);
