owpengram-server/deploy/migrations/0006_sticker_collections.up.sql

18 lines
1.1 KiB
SQL
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.

-- per-user 个人贴纸/GIF 集合:收藏贴纸 / 最近贴纸 / attach 最近贴纸 / 保存的 GIF。
-- 此前 messages.faveSticker/saveRecentSticker/saveGif 未注册(NOT_IMPLEMENTED)、
-- getFaved/getRecent/getSavedGifs 返回空 stub。本表落地真实持久化。
-- used_at 为入列/最近使用时刻,读取按 used_at DESC最新在前document_id 引用
-- documents 表,读路径经 Files.GetDocuments 解析为完整文档。
CREATE TABLE public.user_sticker_collections (
owner_user_id bigint NOT NULL,
kind text NOT NULL,
document_id bigint NOT NULL,
used_at integer DEFAULT 0 NOT NULL,
CONSTRAINT user_sticker_collections_kind_check CHECK ((kind = ANY (ARRAY['faved'::text, 'recent'::text, 'recent_attached'::text, 'gif'::text])))
);
ALTER TABLE ONLY public.user_sticker_collections
ADD CONSTRAINT user_sticker_collections_pkey PRIMARY KEY (owner_user_id, kind, document_id);
-- 读取/截断按 (owner, kind, used_at DESC)。
CREATE INDEX user_sticker_collections_order_idx ON public.user_sticker_collections USING btree (owner_user_id, kind, used_at DESC);