-- statistic 服务 refresh_log: 物化视图刷新日志
-- 创建时间: 2026-06-08
-- 关联: spec §3.6
-- 用途: 监控物化视图刷新状态 + 失败告警

CREATE TABLE IF NOT EXISTS statistic.refresh_log (
    id              BIGSERIAL PRIMARY KEY,
    mv_name         VARCHAR(128)  NOT NULL,
    started_at      TIMESTAMPTZ   NOT NULL,
    finished_at     TIMESTAMPTZ,
    row_count       BIGINT,
    status          VARCHAR(16)   NOT NULL,    -- 'running' / 'success' / 'failed'
    error_message   TEXT
);

-- 监控查询主索引
CREATE INDEX IF NOT EXISTS idx_refresh_log_mv_time
  ON statistic.refresh_log (mv_name, started_at DESC);
