Toolkit
Beta

Database Schema

Ready-to-deploy database model with table definitions, relationships, and indexes.

WaitlistSignUps

Stores waitlist registrations with built-in referral tracking and lifecycle management.

schema.prisma
model WaitlistSignUps {
  id           String            @id @default(cuid())
  email        String            @unique
 
  referralCode String            @unique
  referredById String?
  referredBy   WaitlistSignUps?  @relation("referral", fields: [referredById], references: [id], onUpdate: Cascade, onDelete: Cascade)
  referrals    WaitlistSignUps[] @relation("referral")
 
  offboardedAt DateTime?
  discardedAt  DateTime?
 
  updatedAt    DateTime          @default(now())
  createdAt    DateTime          @default(now())
 
  @@index(referralCode)
  @@index(email)
}
FieldDescription
idUnique identifier for each signup, auto-generated using CUID.
emailUser's email address, must be unique across all signups.
referralCodeUnique code generated for this user to share with others.
referredByIdOptional ID linking to the user who referred this signup.
referredByRelation to the user who made the referral.
referralsList of all users this person has referred.
offboardedAtTimestamp when user was removed from waitlist (e.g., got access).
discardedAtTimestamp when user was marked as invalid or removed.
updatedAtTimestamp of last record update, auto-set to current time.
createdAtTimestamp when user signed up, auto-set to current time.

Key Design Decisions

  1. Uses a self-referential relation for tracking referrals, allowing multi-level referral tracking.
  2. Separates offboardedAt and discardedAt to distinguish between successful conversions and removed entries.
  3. Email uniqueness prevents duplicate signups.
  4. Includes database indexes on referralCode and email for faster lookups.
  5. Uses cascade deletion, meaning if a referrer is deleted, all their referral connections are cleaned up.
  6. Uses CUID instead of UUID for IDs, which is better for database performance and URL-friendly.
  7. Keeps track of both creation and update times for audit purposes.
  8. Makes referral tracking optional by having referredById as nullable.

Apply Changes

Remember to apply these changes to your development database and regenerate Prisma client.

npx prisma migrate dev --name create_waitlist_model

Or if you are not using migrations:

npx prisma db push

On this page