-- 创建任务状态表
CREATE TABLE task_status (
    id BIGINT AUTO_INCREMENT PRIMARY KEY,
    task_id VARCHAR(255) NOT NULL COMMENT '任务ID',
    username VARCHAR(255) NOT NULL COMMENT '用户名',
    task_type VARCHAR(50) NOT NULL COMMENT '任务类型',
    status VARCHAR(50) NOT NULL DEFAULT 'PENDING' COMMENT '任务状态',
    progress INT DEFAULT 0 COMMENT '进度百分比',
    result_url TEXT COMMENT '结果URL',
    error_message TEXT COMMENT '错误信息',
    external_task_id VARCHAR(255) COMMENT '外部任务ID',
    created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
    updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
    completed_at TIMESTAMP NULL COMMENT '完成时间',
    last_polled_at TIMESTAMP NULL COMMENT '最后轮询时间',
    poll_count INT DEFAULT 0 COMMENT '轮询次数',
    max_polls INT DEFAULT 60 COMMENT '最大轮询次数(2小时)',
    
    INDEX idx_task_id (task_id),
    INDEX idx_username (username),
    INDEX idx_status (status),
    INDEX idx_created_at (created_at),
    INDEX idx_last_polled (last_polled_at)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='任务状态表';





















