Files
backend_v2/scripts/sql/007_create_favorites.sql
toom1996 1fd9c48f58 update
2026-09-02 21:51:35 +08:00

18 lines
925 B
SQL
Raw Permalink 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.

-- 007: favorites —— 用户收藏(服务端持久化,按用户隔离)
-- 与项目约定一致:表结构由 SQL 托管,不依赖 GORM AutoMigrate。
-- target_uid 存前端卡片的 it.id(编码串),与前端直接对齐;title/cover/brand 为收藏时快照。
CREATE TABLE IF NOT EXISTS `favorites` (
`id` int unsigned NOT NULL AUTO_INCREMENT,
`created_at` int unsigned NOT NULL DEFAULT 0,
`user_id` int unsigned NOT NULL,
`target_type` varchar(16) NOT NULL DEFAULT '',
`target_uid` varchar(64) NOT NULL DEFAULT '',
`title` varchar(255) NOT NULL DEFAULT '',
`cover` varchar(512) NOT NULL DEFAULT '',
`brand` varchar(255) NOT NULL DEFAULT '',
PRIMARY KEY (`id`),
UNIQUE KEY `uniq_user_target` (`user_id`, `target_uid`),
KEY `idx_user` (`user_id`),
KEY `idx_user_created` (`user_id`, `created_at`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;