fix: api descript

This commit is contained in:
wwweww
2026-02-28 05:33:16 +08:00
parent 5930fb0dde
commit d2f33b4b96
243 changed files with 37065 additions and 780 deletions
@@ -0,0 +1,12 @@
CREATE EXTENSION IF NOT EXISTS pg_trgm;
CREATE EXTENSION IF NOT EXISTS btree_gin;
CREATE EXTENSION IF NOT EXISTS btree_gist;
CREATE EXTENSION IF NOT EXISTS pgcrypto;
CREATE OR REPLACE FUNCTION update_updated_at_column()
RETURNS TRIGGER AS $$
BEGIN
NEW.updated_at = CURRENT_TIMESTAMP;
RETURN NEW;
END;
$$ language 'plpgsql';
-49
View File
@@ -1,49 +0,0 @@
CREATE TABLE player_services (
id BIGINT PRIMARY KEY,
player_id BIGINT NOT NULL REFERENCES players(id),
game_id BIGINT NOT NULL,
title VARCHAR(200) NOT NULL,
description TEXT,
price DECIMAL(10,2) NOT NULL,
unit VARCHAR(20) NOT NULL,
rank_range VARCHAR(100),
availability TEXT[] DEFAULT ARRAY[]::TEXT[],
rating DECIMAL(3,2) DEFAULT 5.00,
is_active BOOLEAN DEFAULT TRUE,
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
CONSTRAINT chk_price_positive CHECK (price > 0),
CONSTRAINT chk_service_rating CHECK (rating >= 0 AND rating <= 5)
);
-- 基础索引
CREATE INDEX idx_services_player ON player_services(player_id) WHERE is_active = TRUE;
CREATE INDEX idx_services_game ON player_services(game_id) WHERE is_active = TRUE;
CREATE INDEX idx_services_price ON player_services(price);
-- 三元组索引用于服务标题模糊搜索
CREATE INDEX idx_services_title_trgm ON player_services USING gin(title gin_trgm_ops)
WHERE is_active = TRUE;
-- 全文搜索索引
CREATE INDEX idx_services_fulltext ON player_services USING gin(
to_tsvector('simple', title || ' ' || coalesce(description, ''))
) WHERE is_active = TRUE;
-- 复合索引优化价格区间查询
CREATE INDEX idx_services_game_price ON player_services(game_id, price, rating DESC)
WHERE is_active = TRUE;
-- 打手+游戏复合索引
CREATE INDEX idx_services_player_game ON player_services(player_id, game_id)
WHERE is_active = TRUE;
-- GIN 索引优化时间段查询
CREATE INDEX idx_services_availability ON player_services USING gin(availability)
WHERE is_active = TRUE;
CREATE TRIGGER trigger_services_updated_at
BEFORE UPDATE ON player_services
FOR EACH ROW
EXECUTE FUNCTION update_updated_at_column();
-17
View File
@@ -1,17 +0,0 @@
CREATE TABLE shop_invitations (
id BIGINT PRIMARY KEY,
shop_id BIGINT NOT NULL REFERENCES shops(id),
player_id BIGINT NOT NULL,
status VARCHAR(20) NOT NULL DEFAULT 'pending',
invited_by BIGINT NOT NULL,
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
responded_at TIMESTAMPTZ,
CONSTRAINT chk_invitation_status CHECK (status IN ('pending', 'accepted', 'rejected', 'cancelled')),
UNIQUE(shop_id, player_id, status) WHERE status = 'pending'
);
CREATE INDEX idx_invitations_shop ON shop_invitations(shop_id);
CREATE INDEX idx_invitations_player ON shop_invitations(player_id) WHERE status = 'pending';
CREATE INDEX idx_invitations_player_status ON shop_invitations(player_id, status, created_at DESC);
CREATE INDEX idx_invitations_shop_status ON shop_invitations(shop_id, status, created_at DESC);
+51
View File
@@ -0,0 +1,51 @@
CREATE TABLE player_services
(
id BIGINT PRIMARY KEY,
player_id BIGINT NOT NULL REFERENCES players (id),
game_id BIGINT NOT NULL,
title VARCHAR(200) NOT NULL,
description TEXT,
price DECIMAL(10, 2) NOT NULL,
unit VARCHAR(20) NOT NULL,
rank_range VARCHAR(100),
availability TEXT[] DEFAULT ARRAY []::TEXT[],
rating DECIMAL(3, 2) DEFAULT 5.00,
is_active BOOLEAN DEFAULT TRUE,
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
CONSTRAINT chk_price_positive CHECK (price > 0),
CONSTRAINT chk_service_rating CHECK (rating >= 0 AND rating <= 5)
);
-- 基础索引
CREATE INDEX idx_services_player ON player_services (player_id) WHERE is_active = TRUE;
CREATE INDEX idx_services_game ON player_services (game_id) WHERE is_active = TRUE;
CREATE INDEX idx_services_price ON player_services (price);
-- 三元组索引用于服务标题模糊搜索
CREATE INDEX idx_services_title_trgm ON player_services USING gin (title gin_trgm_ops)
WHERE is_active = TRUE;
-- 全文搜索索引
CREATE INDEX idx_services_fulltext ON player_services USING gin (
to_tsvector('simple', title || ' ' || coalesce(description, ''))
) WHERE is_active = TRUE;
-- 复合索引优化价格区间查询
CREATE INDEX idx_services_game_price ON player_services (game_id, price, rating DESC)
WHERE is_active = TRUE;
-- 打手+游戏复合索引
CREATE INDEX idx_services_player_game ON player_services (player_id, game_id)
WHERE is_active = TRUE;
-- GIN 索引优化时间段查询
CREATE INDEX idx_services_availability ON player_services USING gin (availability)
WHERE is_active = TRUE;
CREATE TRIGGER trigger_services_updated_at
BEFORE UPDATE
ON player_services
FOR EACH ROW
EXECUTE FUNCTION update_updated_at_column();
@@ -1,7 +1,5 @@
CREATE TABLE players
(
id BIGINT PRIMARY KEY,
CREATE TABLE players (
id BIGINT PRIMARY KEY,
user_id BIGINT NOT NULL UNIQUE,
status VARCHAR(20) NOT NULL DEFAULT 'offline',
@@ -11,12 +9,13 @@ CREATE TABLE players
-- [注意] 此字段为冗余缓存,通过消息队列与 shop_players 表保持一致
shop_id BIGINT,
gender bool default 1 not null ,
tags TEXT[] DEFAULT ARRAY[]::TEXT[],
games BIGINT[] DEFAULT ARRAY[]::BIGINT[],
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
);
-- 基础索引
CREATE INDEX idx_players_user ON players (user_id);
CREATE INDEX idx_players_shop ON players (shop_id) WHERE shop_id IS NOT NULL;
@@ -33,8 +32,8 @@ CREATE INDEX idx_players_tags_gin ON players USING gin(tags);
-- 店铺+状态复合索引
CREATE INDEX idx_players_shop_status ON players (shop_id, status, rating DESC) WHERE shop_id IS NOT NULL;
-- CREATE TRIGGER trigger_players_updated_at
-- BEFORE UPDATE
-- ON players
-- FOR EACH ROW
-- EXECUTE FUNCTION update_updated_at_column();
CREATE TRIGGER trigger_players_updated_at
BEFORE UPDATE
ON players
FOR EACH ROW
EXECUTE FUNCTION update_updated_at_column();
+20
View File
@@ -0,0 +1,20 @@
CREATE TABLE shop_invitations
(
id BIGINT PRIMARY KEY,
shop_id BIGINT NOT NULL REFERENCES shops (id),
player_id BIGINT NOT NULL,
status VARCHAR(20) NOT NULL DEFAULT 'pending',
invited_by BIGINT NOT NULL,
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
responded_at TIMESTAMPTZ,
CONSTRAINT chk_invitation_status CHECK (status IN ('pending', 'accepted', 'rejected', 'cancelled'))
);
CREATE UNIQUE INDEX idx_unique_pending_invitation
ON shop_invitations (shop_id, player_id)
WHERE status = 'pending';
CREATE INDEX idx_invitations_shop ON shop_invitations (shop_id);
CREATE INDEX idx_invitations_player ON shop_invitations (player_id) WHERE status = 'pending';
CREATE INDEX idx_invitations_player_status ON shop_invitations (player_id, status, created_at DESC);
CREATE INDEX idx_invitations_shop_status ON shop_invitations (shop_id, status, created_at DESC);
@@ -3,9 +3,8 @@ CREATE TABLE shop_players
shop_id BIGINT NOT NULL REFERENCES shops (id),
player_id BIGINT NOT NULL,
-- [新增] 标记是否为主店铺。用于个人主页展示和 players.shop_id 缓存源
-- 标记是否为主店铺。用于个人主页展示和 players.shop_id 缓存源
is_primary BOOLEAN DEFAULT FALSE,
joined_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
left_at TIMESTAMPTZ, -- 软删除,表示已离职