fix: 给有 FK 依赖的建表脚本加数字前缀以保证字母序就是依赖序

This commit is contained in:
zetaloop
2026-05-03 07:31:12 +08:00
parent 22c7c4e7d9
commit 631469a713
16 changed files with 0 additions and 0 deletions
+21
View File
@@ -0,0 +1,21 @@
CREATE TABLE shop_players
(
id BIGINT PRIMARY KEY,
shop_id BIGINT NOT NULL REFERENCES shops (id),
player_id BIGINT NOT NULL,
-- 标记是否为主店铺。用于个人主页展示和 players.shop_id 缓存源
is_primary BOOLEAN DEFAULT FALSE,
joined_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
left_at TIMESTAMPTZ, -- 软删除,表示已离职
UNIQUE (shop_id, player_id)
);
-- 索引
CREATE INDEX idx_shop_players_player ON shop_players (player_id) WHERE left_at IS NULL;
CREATE INDEX idx_shop_players_shop_active ON shop_players (shop_id, joined_at DESC) WHERE left_at IS NULL;
-- 唯一索引:确保一个打手同一时间只能有一个主店铺
CREATE UNIQUE INDEX idx_shop_players_one_primary
ON shop_players (player_id) WHERE is_primary = TRUE AND left_at IS NULL;