-- pulse-agent writes the newest bounded telemetry snapshot per capability here and -- pulse-api reads it. There is exactly one row per (agent, capability): history lives in -- Prometheus, not in this table, so the transport cannot grow without bound. CREATE TABLE agent_snapshots ( agent_id text NOT NULL CHECK (char_length(agent_id) BETWEEN 1 AND 128), capability text NOT NULL CHECK (capability IN ('host', 'processes', 'containers', 'array', 'disks', 'pools', 'shares')), observed_at timestamptz NOT NULL, received_at timestamptz NOT NULL DEFAULT now(), -- The authoritative size bound is enforced by the writer against the encoded payload -- (agentstore.MaxPayloadBytes). This check is a storage backstop against a writer that -- bypasses the store; pg_column_size reports the stored, possibly compressed size. payload jsonb NOT NULL CHECK (jsonb_typeof(payload) = 'object' AND pg_column_size(payload) <= 2097152), PRIMARY KEY (agent_id, capability) ); -- The API reads the newest snapshot for one capability across agents on every request. CREATE INDEX agent_snapshots_capability_freshness_idx ON agent_snapshots (capability, observed_at DESC);