-- 2026-05-18 PR-Worker-Pool-Registry-1A: worker_heartbeats 테이블 신규.
-- worker 가 30~60s 주기로 status 발신 (worker-pool-policy §7).
-- append-only. 운영 alive 판정 = (worker_id 별 최신 row).heartbeat_at > now() - interval '10 min'.
-- retention 정책은 별 PR (PR-LLM-Router-Observability-1 또는 동등).
-- 1A 단계: schema only (heartbeat endpoint 503 stub). 활성화 = 1B.
-- current_job_id 는 1A 단계에서 plain BIGINT (FK 없음). 1B 의 worker_jobs 마이그레이션 후 FK 추가 검토.

CREATE TABLE IF NOT EXISTS worker_heartbeats (
    id              BIGSERIAL PRIMARY KEY,
    worker_id       TEXT NOT NULL REFERENCES worker_capabilities(worker_id) ON DELETE CASCADE,
    heartbeat_at    TIMESTAMPTZ NOT NULL DEFAULT now(),
    status          TEXT NOT NULL,
    current_job_id  BIGINT,
    battery         TEXT,
    thermal         TEXT,
    raw_payload     JSONB NOT NULL DEFAULT '{}'::jsonb
);
