-- Idempotent: safe to run on every audit start
CREATE TABLE IF NOT EXISTS tracksolid.health_checks (
    id          BIGSERIAL PRIMARY KEY,
    checked_at  TIMESTAMPTZ NOT NULL DEFAULT NOW(),
    check_name  TEXT        NOT NULL,
    status      TEXT        NOT NULL CHECK (status IN ('ok', 'warning', 'critical')),
    detail      JSONB,
    row_count   INT
);

-- Index for Grafana time-range queries
CREATE INDEX IF NOT EXISTS health_checks_checked_at_idx
    ON tracksolid.health_checks (checked_at DESC);
