schema.prisma 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. generator client {
  2. provider = "prisma-client-js"
  3. }
  4. datasource db {
  5. provider = "postgresql"
  6. url = env("POSTGRES_PRISMA_URL")
  7. directUrl = env("POSTGRES_URL_NON_POOLING")
  8. }
  9. model Account {
  10. id String @id @default(cuid())
  11. userId String @map("user_id")
  12. type String
  13. provider String
  14. providerAccountId String @map("provider_account_id")
  15. refresh_token String?
  16. access_token String?
  17. expires_at Int?
  18. token_type String?
  19. scope String?
  20. id_token String?
  21. session_state String?
  22. refresh_token_expires_in Int?
  23. user User @relation(fields: [userId], references: [id], onDelete: Cascade)
  24. @@unique([provider, providerAccountId])
  25. @@map("accounts")
  26. }
  27. model Session {
  28. id String @id @default(cuid())
  29. sessionToken String @unique @map("session_token")
  30. userId String @map("user_id")
  31. expires DateTime
  32. user User @relation(fields: [userId], references: [id], onDelete: Cascade)
  33. @@map("sessions")
  34. }
  35. model User {
  36. id String @id @default(cuid())
  37. name String?
  38. email String? @unique
  39. emailVerified DateTime? @map("email_verified")
  40. image String?
  41. accounts Account[]
  42. sessions Session[]
  43. subscription Subscription[]
  44. @@map("users")
  45. }
  46. model VerificationToken {
  47. identifier String
  48. token String @unique
  49. expires DateTime
  50. @@unique([identifier, token])
  51. @@map("verificationtokens")
  52. }
  53. model Subscription {
  54. id Int @id @default(autoincrement())
  55. lemonSqueezyId Int @unique @map("lemon_squeezy_id")
  56. orderId Int @unique @map("order_id")
  57. name String
  58. email String
  59. status String
  60. renewsAt DateTime? @map("renews_at")
  61. endsAt DateTime? @map("ends_at")
  62. trialEndsAt DateTime? @map("trial_ends_at")
  63. resumesAt DateTime? @map("resumes_at")
  64. price Int
  65. plan Plan @relation(fields: [planId], references: [id])
  66. planId Int @map("plan_id")
  67. user User @relation(fields: [userId], references: [id])
  68. userId String @map("user_id")
  69. isUsageBased Boolean @default(false) @map("is_usage_based")
  70. subscriptionItemId Int? @unique @map("subscription_item_id")
  71. @@index([planId, lemonSqueezyId])
  72. }
  73. model Plan {
  74. id Int @id @default(autoincrement())
  75. productId Int @map("product_id")
  76. variantId Int @unique @map("variant_id")
  77. name String? // Need to get from Product
  78. description String?
  79. variantName String @map("variant_name")
  80. sort Int
  81. status String
  82. price Int
  83. interval String
  84. intervalCount Int @default(1) @map("interval_count")
  85. subscriptions Subscription[]
  86. }
  87. model WebhookEvent {
  88. id Int @id @default(autoincrement())
  89. createdAt DateTime @default(now()) @map("created_at")
  90. eventName String @map("event_name")
  91. processed Boolean @default(false)
  92. body Json
  93. processingError String? @map("processing_error")
  94. }