-- 迁移文件: 001_create_models_table.sql
-- 描述: 创建AI模型信息表
-- 需求: 9.1, 9.2, 9.3, 9.4

-- ============================================
-- 正向迁移: 创建表和索引
-- ============================================

-- 创建models表
CREATE TABLE IF NOT EXISTS models (
    id SERIAL PRIMARY KEY,
    title VARCHAR(255) NOT NULL UNIQUE,
    img TEXT NOT NULL,
    name TEXT NOT NULL,
    tag1 VARCHAR(100),
    description TEXT,
    keyword TEXT,
    time VARCHAR(50),
    tag2 VARCHAR(100),
    created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL,
    updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL
);

-- 添加表注释
COMMENT ON TABLE models IS 'AI模型信息表';
COMMENT ON COLUMN models.id IS '主键ID';
COMMENT ON COLUMN models.title IS '模型标识（唯一）';
COMMENT ON COLUMN models.img IS '图标URL';
COMMENT ON COLUMN models.name IS '显示名称';
COMMENT ON COLUMN models.tag1 IS '主标签';
COMMENT ON COLUMN models.description IS '模型描述';
COMMENT ON COLUMN models.keyword IS '关键词（用于搜索）';
COMMENT ON COLUMN models.time IS '发布时间';
COMMENT ON COLUMN models.tag2 IS '次要标签';
COMMENT ON COLUMN models.created_at IS '创建时间';
COMMENT ON COLUMN models.updated_at IS '更新时间';

-- 创建keyword索引（优化搜索性能）
CREATE INDEX IF NOT EXISTS idx_models_keyword ON models(keyword);

-- ============================================
-- 回滚迁移: 删除表和索引
-- ============================================
-- DROP INDEX IF EXISTS idx_models_keyword;
-- DROP TABLE IF EXISTS models;
