-- 见素起名 - MySQL 5.7 数据库建表语句
-- 创建数据库
CREATE DATABASE IF NOT EXISTS jiansu_db 
  CHARACTER SET utf8mb4 
  COLLATE utf8mb4_unicode_ci;

USE jiansu_db;

-- 用户收藏表
CREATE TABLE IF NOT EXISTS user_favorites (
    id BIGINT AUTO_INCREMENT PRIMARY KEY COMMENT '主键ID',
    openid VARCHAR(100) NOT NULL COMMENT '用户微信openid',
    name VARCHAR(50) NOT NULL COMMENT '名字',
    origin VARCHAR(500) COMMENT '出处/诗词',
    description VARCHAR(1000) COMMENT '解析文案',
    tone VARCHAR(20) COMMENT '声韵',
    score DOUBLE COMMENT '见素评分',
    mode VARCHAR(20) COMMENT '生成模式',
    keyword VARCHAR(100) COMMENT '关键词',
    create_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP COMMENT '收藏时间',
    
    INDEX idx_openid (openid),
    INDEX idx_openid_name (openid, name),
    INDEX idx_create_time (create_time)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='用户收藏表';

-- 可选：创建唯一索引防止重复收藏
-- ALTER TABLE user_favorites ADD UNIQUE INDEX uk_openid_name (openid, name);
