Skip to content

Open source CapCut alternative.

TypeScript
4.3 KB
Raw Blame
model User {
  id            String    @id
  // The name Google gave us at sign-in. Never edited in the product.
  name          String
  // The name the product shows instead, when the user has set one.
  displayName   String?
  email         String    @unique
  emailVerified Boolean   @default(false)
  image         String?
  superUser     Boolean   @default(false)
  // Stripe customer id, one per user, shared across every billing product
  // (Pro, one-time credit top-ups) so a customer is never duplicated.
  stripeCustomerId String? @unique
  // The language the product speaks to this person (UI, chat, emails), one of
  // src/i18n/locales.ts. Set from the browser's language on first visit.
  locale        String?
  createdAt     DateTime  @default(now())
  updatedAt     DateTime  @updatedAt
  sessions      Session[]
  accounts      Account[]
  creditAccount UserCreditAccount?
  creditGrants  UserCreditGrant[]
  creditOffers  CreditOffer[]
  creditLedgerEntries UserCreditLedgerEntry[]
  inferenceUsageEvents InferenceUsageEvent[]
  creditLimits UserCreditLimit[]
  creditAutoReload CreditAutoReload?
  apiKeys       Apikey[]
  chatgptGrants ChatgptGrant[]
  proSubscription ProSubscription?
  introOfferView IntroOfferView?
  avatar        UserAvatar?
  onboarding    UserOnboarding?
  emailSettings UserEmailSettings?
  outreach      UserOutreach[]
  emailSends            EmailSend[]
  experimentAssignments ExperimentAssignment[]
  experimentHoldout ExperimentHoldout?

  @@map("user")
}

// The picture the user uploaded, already cropped and compressed by the client.
// Kept out of `user` so the row every session read touches stays small.
model UserAvatar {
  userId      String   @id
  user        User     @relation(fields: [userId], references: [id], onDelete: Cascade)
  data        Bytes
  contentType String
  updatedAt   DateTime @updatedAt
}

model Session {
  id        String   @id
  expiresAt DateTime
  token     String   @unique
  createdAt DateTime @default(now())
  updatedAt DateTime @updatedAt
  ipAddress String?
  userAgent String?
  userId    String
  user      User     @relation(fields: [userId], references: [id], onDelete: Cascade)

  @@index([userId])
  @@map("session")
}

model Account {
  id                    String    @id
  accountId             String
  providerId            String
  userId                String
  user                  User      @relation(fields: [userId], references: [id], onDelete: Cascade)
  accessToken           String?
  refreshToken          String?
  idToken               String?
  accessTokenExpiresAt  DateTime?
  refreshTokenExpiresAt DateTime?
  scope                 String?
  password              String?
  createdAt             DateTime  @default(now())
  updatedAt             DateTime  @updatedAt

  @@unique([providerId, accountId])
  @@index([userId])
  @@map("account")
}

model Verification {
  id         String   @id
  identifier String
  value      String
  expiresAt  DateTime
  createdAt  DateTime @default(now())
  updatedAt  DateTime @updatedAt

  @@index([identifier])
  @@map("verification")
}

// Developer API keys, held for a future API product. The shape mirrors the
// Better Auth @better-auth/api-key plugin schema (generated via the Better
// Auth CLI) so the plugin can own reads/writes when that product ships; a key
// links to its owner via referenceId (= User.id). The one addition over the
// generated shape is the User relation on referenceId, which gives
// cascade-delete without changing any plugin field.
model Apikey {
  id                  String    @id
  configId            String    @default("default")
  name                String?
  start               String?
  referenceId         String
  user                User      @relation(fields: [referenceId], references: [id], onDelete: Cascade)
  prefix              String?
  key                 String
  refillInterval      Int?
  refillAmount        Int?
  lastRefillAt        DateTime?
  enabled             Boolean?  @default(true)
  rateLimitEnabled    Boolean?  @default(true)
  rateLimitTimeWindow Int?      @default(86400000)
  rateLimitMax        Int?      @default(10)
  requestCount        Int?      @default(0)
  remaining           Int?
  lastRequest         DateTime?
  expiresAt           DateTime?
  createdAt           DateTime
  updatedAt           DateTime
  permissions         String?
  metadata            String?

  @@index([key])
}