-- v8.29  webhook_log: supplier-facing columns
-- Adds: source, status, lead_id, ip_address, created_at
-- Also makes tenant_id nullable (supplier webhook events are platform-level, no tenant context).

ALTER TABLE webhook_log
    ALTER COLUMN tenant_id DROP NOT NULL;

ALTER TABLE webhook_log
    ADD COLUMN IF NOT EXISTS source      VARCHAR(50),
    ADD COLUMN IF NOT EXISTS status      VARCHAR(50),
    ADD COLUMN IF NOT EXISTS lead_id     BIGINT,
    ADD COLUMN IF NOT EXISTS ip_address  INET,
    ADD COLUMN IF NOT EXISTS created_at  TIMESTAMPTZ DEFAULT NOW();

-- Index to speed up status queries
CREATE INDEX IF NOT EXISTS idx_webhook_log_status ON webhook_log(status, created_at DESC);
