-- 告警历史表
CREATE TABLE IF NOT EXISTS tb_polling_alert_history (
    id BIGSERIAL PRIMARY KEY,
    rule_id BIGINT NOT NULL,
    task_type VARCHAR(50) NOT NULL,
    metric_type VARCHAR(50) NOT NULL,
    alert_level VARCHAR(20) NOT NULL,
    current_value DECIMAL(10, 2) NOT NULL,
    threshold DECIMAL(10, 2) NOT NULL,
    alert_message TEXT NOT NULL,
    notification_channels TEXT,
    notification_status VARCHAR(20),
    notification_result TEXT,
    created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP
);

-- 索引
CREATE INDEX idx_polling_alert_history_rule_id ON tb_polling_alert_history(rule_id);
CREATE INDEX idx_polling_alert_history_created_at ON tb_polling_alert_history(created_at);
CREATE INDEX idx_polling_alert_history_task_type ON tb_polling_alert_history(task_type);

-- 表注释
COMMENT ON TABLE tb_polling_alert_history IS '告警历史表 - 记录所有触发的告警';

-- 列注释
COMMENT ON COLUMN tb_polling_alert_history.rule_id IS '告警规则ID';
COMMENT ON COLUMN tb_polling_alert_history.task_type IS '任务类型';
COMMENT ON COLUMN tb_polling_alert_history.metric_type IS '指标类型';
COMMENT ON COLUMN tb_polling_alert_history.alert_level IS '告警级别';
COMMENT ON COLUMN tb_polling_alert_history.current_value IS '当前值';
COMMENT ON COLUMN tb_polling_alert_history.threshold IS '阈值';
COMMENT ON COLUMN tb_polling_alert_history.alert_message IS '告警消息';
COMMENT ON COLUMN tb_polling_alert_history.notification_channels IS '通知渠道（JSON数组）';
COMMENT ON COLUMN tb_polling_alert_history.notification_status IS '通知状态：pending/sent/failed';
COMMENT ON COLUMN tb_polling_alert_history.notification_result IS '通知结果（JSON）';
COMMENT ON COLUMN tb_polling_alert_history.created_at IS '告警时间';
