-- 创建任务队列表
CREATE TABLE IF NOT EXISTS task_queue (
    id BIGINT AUTO_INCREMENT PRIMARY KEY,
    username VARCHAR(100) NOT NULL COMMENT '用户名',
    task_id VARCHAR(50) NOT NULL UNIQUE COMMENT '任务ID',
    task_type ENUM('TEXT_TO_VIDEO', 'IMAGE_TO_VIDEO', 'STORYBOARD_VIDEO') NOT NULL COMMENT '任务类型',
    status ENUM('PENDING', 'PROCESSING', 'COMPLETED', 'FAILED', 'CANCELLED', 'TIMEOUT') NOT NULL DEFAULT 'PENDING' COMMENT '队列状态',
    priority INT NOT NULL DEFAULT 0 COMMENT '优先级，数字越小优先级越高',
    real_task_id VARCHAR(100) COMMENT '外部API返回的真实任务ID',
    last_check_time DATETIME COMMENT '最后一次检查时间',
    check_count INT NOT NULL DEFAULT 0 COMMENT '检查次数',
    max_check_count INT NOT NULL DEFAULT 30 COMMENT '最大检查次数（30次 * 2分钟 = 60分钟）',
    error_message TEXT COMMENT '错误信息',
    created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
    updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
    completed_at DATETIME COMMENT '完成时间',
    
    INDEX idx_username_status (username, status),
    INDEX idx_status_priority (status, priority),
    INDEX idx_last_check_time (last_check_time),
    INDEX idx_created_at (created_at)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='任务队列表';




















