Skip to main content

max / makenotwork

862 B · 18 lines History Blame Raw
1 -- Webhook event retry queue.
2 -- Failed webhook events are persisted and retried with exponential backoff.
3
4 CREATE TABLE webhook_events (
5 id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
6 source TEXT NOT NULL, -- 'stripe' or 'postmark'
7 event_type TEXT NOT NULL, -- e.g. 'checkout.session.completed'
8 payload TEXT NOT NULL, -- raw JSON body
9 signature TEXT, -- original signature header (for re-verification)
10 status TEXT NOT NULL DEFAULT 'failed' CHECK (status IN ('failed', 'retrying', 'dead')),
11 attempts INT NOT NULL DEFAULT 0,
12 last_error TEXT,
13 next_retry_at TIMESTAMPTZ NOT NULL DEFAULT NOW() + INTERVAL '60 seconds',
14 created_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
15 );
16
17 CREATE INDEX idx_webhook_events_retry ON webhook_events (next_retry_at) WHERE status IN ('failed', 'retrying');
18