feat(ECR-011): 昵称、首页贴士与档案 Self 唯一/合盘交叉校验
每账号仅一条 self(migration 40902);合盘只选 TA;账号昵称可改;首页穿衣/颜色/养生贴士。 Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -0,0 +1,16 @@
|
||||
-- One active self profile per user; soft-delete older duplicates first.
|
||||
|
||||
WITH ranked AS (
|
||||
SELECT id,
|
||||
ROW_NUMBER() OVER (PARTITION BY user_id ORDER BY created_at DESC, id DESC) AS rn
|
||||
FROM profiles
|
||||
WHERE relation = 'self' AND deleted_at IS NULL
|
||||
)
|
||||
UPDATE profiles p
|
||||
SET deleted_at = now(), updated_at = now()
|
||||
FROM ranked r
|
||||
WHERE p.id = r.id AND r.rn > 1 AND p.deleted_at IS NULL;
|
||||
|
||||
CREATE UNIQUE INDEX IF NOT EXISTS idx_profiles_one_self_per_user
|
||||
ON profiles (user_id)
|
||||
WHERE relation = 'self' AND deleted_at IS NULL;
|
||||
Reference in New Issue
Block a user