← back to Ventura Claw Leads

db/migrations/003_subscription_events.sql

13 lines

-- Stripe webhook event audit + idempotency lock. The UNIQUE on stripe_event_id
-- prevents double-processing when Stripe retries the same event.

CREATE TABLE IF NOT EXISTS subscription_events (
  id              BIGSERIAL PRIMARY KEY,
  stripe_event_id TEXT UNIQUE NOT NULL,
  event_type      TEXT NOT NULL,
  payload         JSONB NOT NULL,
  created_at      TIMESTAMPTZ NOT NULL DEFAULT now()
);

CREATE INDEX IF NOT EXISTS subscription_events_type_idx ON subscription_events (event_type, created_at DESC);