-- 手动触发日志表
CREATE TABLE IF NOT EXISTS tb_polling_manual_trigger_log (
    id BIGSERIAL PRIMARY KEY,
    task_type VARCHAR(50) NOT NULL,
    trigger_type VARCHAR(50) NOT NULL,
    card_ids TEXT,
    condition_filter TEXT,
    total_count INT NOT NULL DEFAULT 0,
    processed_count INT NOT NULL DEFAULT 0,
    success_count INT NOT NULL DEFAULT 0,
    failed_count INT NOT NULL DEFAULT 0,
    status VARCHAR(20) NOT NULL,
    triggered_by BIGINT NOT NULL,
    triggered_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
    completed_at TIMESTAMP
);

-- 索引
CREATE INDEX idx_polling_manual_trigger_log_task_type ON tb_polling_manual_trigger_log(task_type);
CREATE INDEX idx_polling_manual_trigger_log_triggered_by ON tb_polling_manual_trigger_log(triggered_by);
CREATE INDEX idx_polling_manual_trigger_log_triggered_at ON tb_polling_manual_trigger_log(triggered_at);
CREATE INDEX idx_polling_manual_trigger_log_status ON tb_polling_manual_trigger_log(status);

-- 表注释
COMMENT ON TABLE tb_polling_manual_trigger_log IS '手动触发日志表 - 记录手动触发轮询检查的操作';

-- 列注释
COMMENT ON COLUMN tb_polling_manual_trigger_log.task_type IS '任务类型：realname/carddata/package';
COMMENT ON COLUMN tb_polling_manual_trigger_log.trigger_type IS '触发类型：single/batch/by_condition';
COMMENT ON COLUMN tb_polling_manual_trigger_log.card_ids IS '卡ID列表（JSON数组）';
COMMENT ON COLUMN tb_polling_manual_trigger_log.condition_filter IS '筛选条件（JSON）';
COMMENT ON COLUMN tb_polling_manual_trigger_log.total_count IS '总卡数';
COMMENT ON COLUMN tb_polling_manual_trigger_log.processed_count IS '已处理数';
COMMENT ON COLUMN tb_polling_manual_trigger_log.success_count IS '成功数';
COMMENT ON COLUMN tb_polling_manual_trigger_log.failed_count IS '失败数';
COMMENT ON COLUMN tb_polling_manual_trigger_log.status IS '状态：pending/processing/completed/cancelled';
COMMENT ON COLUMN tb_polling_manual_trigger_log.triggered_by IS '触发人ID';
COMMENT ON COLUMN tb_polling_manual_trigger_log.triggered_at IS '触发时间';
COMMENT ON COLUMN tb_polling_manual_trigger_log.completed_at IS '完成时间';
