topfans/backend/scripts/migrate_fix_asset_likes_unique_constraint.sql
2026-05-07 14:07:36 +08:00

9 lines
375 B
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.

-- 修复 asset_likes 表唯一约束,添加 star_id
-- 原约束: (user_id, asset_id)
-- 新约束: (user_id, asset_id, star_id)
-- 删除旧约束
ALTER TABLE asset_likes DROP CONSTRAINT IF EXISTS uk_asset_likes_user_asset;
-- 添加新约束(包含 star_id
ALTER TABLE asset_likes ADD CONSTRAINT uk_asset_likes_user_asset_star UNIQUE (user_id, asset_id, star_id);