-- ──────────────────────────────────────────────────────────────────────────
-- Lead request reservation linkage
-- ──────────────────────────────────────────────────────────────────────────
-- Store the tracecoin_ledger row id that holds the RESERVE entry for each
-- lead_request, so we can release/confirm the exact same ledger row
-- when the request is accepted, rejected, cancelled, or expired.

ALTER TABLE lead_requests
    ADD COLUMN IF NOT EXISTS reserve_ledger_id UUID
    REFERENCES tracecoin_ledger(id);

CREATE INDEX IF NOT EXISTS idx_lead_requests_reserve_ledger_id
    ON lead_requests(reserve_ledger_id)
    WHERE reserve_ledger_id IS NOT NULL;
