-- 创建成功任务导出表
CREATE TABLE IF NOT EXISTS completed_tasks_archive (
    id BIGINT AUTO_INCREMENT PRIMARY KEY,
    task_id VARCHAR(255) NOT NULL,
    username VARCHAR(255) NOT NULL,
    task_type VARCHAR(50) NOT NULL,
    prompt TEXT,
    aspect_ratio VARCHAR(20),
    duration INT,
    hd_mode BOOLEAN DEFAULT FALSE,
    result_url TEXT,
    real_task_id VARCHAR(255),
    progress INT DEFAULT 100,
    created_at TIMESTAMP NOT NULL,
    completed_at TIMESTAMP NOT NULL,
    archived_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
    points_cost INT DEFAULT 0,
    INDEX idx_username (username),
    INDEX idx_task_type (task_type),
    INDEX idx_created_at (created_at),
    INDEX idx_completed_at (completed_at),
    INDEX idx_archived_at (archived_at)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='成功任务归档表';

-- 创建失败任务清理日志表
CREATE TABLE IF NOT EXISTS failed_tasks_cleanup_log (
    id BIGINT AUTO_INCREMENT PRIMARY KEY,
    task_id VARCHAR(255) NOT NULL,
    username VARCHAR(255) NOT NULL,
    task_type VARCHAR(50) NOT NULL,
    error_message TEXT,
    created_at TIMESTAMP NOT NULL,
    failed_at TIMESTAMP NOT NULL,
    cleaned_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
    INDEX idx_username (username),
    INDEX idx_task_type (task_type),
    INDEX idx_cleaned_at (cleaned_at)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='失败任务清理日志表';
