fix: 复合主键表改为单字段 id 以支持 ent 完整生成
This commit is contained in:
@@ -1,10 +1,11 @@
|
||||
CREATE TABLE comment_likes
|
||||
(
|
||||
id BIGINT PRIMARY KEY,
|
||||
comment_id BIGINT NOT NULL,
|
||||
user_id BIGINT NOT NULL,
|
||||
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
|
||||
|
||||
PRIMARY KEY (comment_id, user_id)
|
||||
UNIQUE (comment_id, user_id)
|
||||
);
|
||||
|
||||
CREATE INDEX idx_comment_likes_lookup ON comment_likes (user_id, comment_id);
|
||||
@@ -1,11 +1,11 @@
|
||||
CREATE TABLE post_likes
|
||||
(
|
||||
id BIGINT PRIMARY KEY,
|
||||
post_id BIGINT NOT NULL,
|
||||
user_id BIGINT NOT NULL,
|
||||
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
|
||||
|
||||
-- 复合主键,防止重复点赞
|
||||
PRIMARY KEY (post_id, user_id)
|
||||
UNIQUE (post_id, user_id)
|
||||
);
|
||||
|
||||
-- [核心索引] 优化 "feed流中判断我是否已赞" (user_id = ? AND post_id IN (...))
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
CREATE TABLE shop_players
|
||||
(
|
||||
id BIGINT PRIMARY KEY,
|
||||
shop_id BIGINT NOT NULL REFERENCES shops (id),
|
||||
player_id BIGINT NOT NULL,
|
||||
|
||||
@@ -8,7 +9,7 @@ CREATE TABLE shop_players
|
||||
joined_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
|
||||
left_at TIMESTAMPTZ, -- 软删除,表示已离职
|
||||
|
||||
PRIMARY KEY (shop_id, player_id)
|
||||
UNIQUE (shop_id, player_id)
|
||||
);
|
||||
|
||||
-- 索引
|
||||
|
||||
Reference in New Issue
Block a user