Skip to content
Festivals & ticketing

referrals

Referrals — ticket referral tracking for the "buy through a friend's link" discount flow. A referral row is created when a dancer opens a checkout via a referral link (?ref=<username>). Status transitions: pending → completed (on successful Stripe payment) or expired (if never paid). The referrer is credited once the referee's payment succeeds.

Columns

ColumnTypeNullDefaultKeys
iduuid nogen_random_uuid()
PK
festival_iduuid no—
referrer_iduuid no—
referee_iduuid no—
discount_centsinteger no0
stripe_session_idtext yes—
statustext
pendingcompletedexpired
no"pending"
created_attimestamp yesnow()
completed_attimestamp yes—
referrer_credit_centsinteger no0
referrer_credit_applied_session_idtext yes—

Value lists come from .$type<'a' | 'b'>() in the schema — enforced in TypeScript only, not by the database.

Keys, constraints & indexes

Unique

  • (festival_id, referee_id) referral_festival_referee_unique

Indexes

  • (referrer_id)
    referrals_referrer_idx

Foreign keys

  • festival_id → festivals.id
    on delete no action
  • referrer_id → dancers.id
    on delete no action
  • referee_id → dancers.id
    on delete no action

Used by

Code that reads or writes this table, found by static analysis of the tRPC routers and API handlers (including helpers they call).

REST & webhooks

  • POST /api/stripe/webhook
  • ANY /mcp
  • ANY /mcp/public

Relations

Rendering diagram…

Diagram source
erDiagram
  dancers {
    uuid id PK
    text email UK
    text neon_auth_id UK
    text username UK
  }
  festivals {
    uuid id PK
    text slug UK
  }
  referrals {
    uuid id PK
    uuid festival_id FK
    uuid referrer_id FK
    uuid referee_id FK
  }
  festivals ||--o{ referrals : "festival_id"
  dancers ||--o{ referrals : "referrer_id"
  dancers ||--o{ referrals : "referee_id"

Defined at server/database/schema.ts:945 as referrals.