-- concat_task 视频拼接异步任务表
CREATE TABLE IF NOT EXISTS concat_task (
    id BIGSERIAL NOT NULL,
    task_id VARCHAR(64) NOT NULL,
    tenant_id BIGINT NOT NULL DEFAULT 0,
    status VARCHAR(20) NOT NULL DEFAULT 'pending',
    file_url TEXT NOT NULL DEFAULT '',
    file_size BIGINT NOT NULL DEFAULT 0,
    file_name VARCHAR(255) NOT NULL DEFAULT '',
    file_format VARCHAR(32) NOT NULL DEFAULT '',
    file_address_prefix TEXT NOT NULL DEFAULT '',
    method_used VARCHAR(64) NOT NULL DEFAULT '',
    duration_str VARCHAR(32) NOT NULL DEFAULT '',
    error_message TEXT,
    created_at TIMESTAMP WITH TIME ZONE DEFAULT NOW(),
    updated_at TIMESTAMP WITH TIME ZONE DEFAULT NOW(),
    deleted_at TIMESTAMP WITH TIME ZONE,
    PRIMARY KEY (id)
);

COMMENT ON TABLE concat_task IS '视频拼接异步任务表';
COMMENT ON COLUMN concat_task.task_id IS '任务唯一标识';
COMMENT ON COLUMN concat_task.tenant_id IS '租户ID';
COMMENT ON COLUMN concat_task.status IS '任务状态:pending/running/success/failed';
COMMENT ON COLUMN concat_task.file_url IS 'MinIO文件访问路径';
COMMENT ON COLUMN concat_task.file_size IS '文件大小(字节)';
COMMENT ON COLUMN concat_task.file_name IS '文件名';
COMMENT ON COLUMN concat_task.file_format IS '文件格式';
COMMENT ON COLUMN concat_task.file_address_prefix IS 'MinIO地址前缀';
COMMENT ON COLUMN concat_task.method_used IS '实际使用的拼接方式';
COMMENT ON COLUMN concat_task.duration_str IS '拼接后时长';
COMMENT ON COLUMN concat_task.error_message IS '错误信息';
COMMENT ON COLUMN concat_task.created_at IS '创建时间';
COMMENT ON COLUMN concat_task.updated_at IS '更新时间';
COMMENT ON COLUMN concat_task.deleted_at IS '删除时间(软删除)';

CREATE UNIQUE INDEX IF NOT EXISTS idx_concat_task_task_id ON concat_task(task_id);
CREATE INDEX IF NOT EXISTS idx_concat_task_status ON concat_task(status);
CREATE INDEX IF NOT EXISTS idx_concat_task_created_at ON concat_task(created_at);
