/
schema.prisma
315 lines (287 loc) · 12.4 KB
/
schema.prisma
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
generator client {
provider = "prisma-client-js"
previewFeatures = []
binaryTargets = ["rhel-openssl-1.0.x", "native"]
}
datasource db {
provider = "mysql"
url = env("DATABASE_URL")
relationMode = "prisma"
}
model Comment {
id String @id @default(uuid())
userId String
text String @db.Text
context Json?
updatedAt DateTime?
createdAt DateTime @default(now())
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
}
model LessonProgress {
id String @id @default(uuid())
userId String
lessonId String?
sectionId String?
moduleId String?
lessonSlug String?
lessonVersion String?
completedAt DateTime?
updatedAt DateTime?
createdAt DateTime @default(now())
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
@@index(fields: [userId, lessonId])
@@index([completedAt(sort: Desc)])
}
model Account {
id String @id @default(uuid())
type String
provider String
providerAccountId String
refresh_token String?
access_token String?
expires_at BigInt?
token_type String?
scope String?
id_token String?
session_state String?
oauth_token_secret String?
oauth_token String?
userId String
refresh_token_expires_in Int?
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
@@unique([provider, providerAccountId])
}
model Coupon {
id String @id @default(uuid())
code String? @unique
createdAt DateTime @default(now())
expires DateTime?
maxUses Int @default(-1)
default Boolean @default(false)
merchantCouponId String?
status Int @default(0)
usedCount Int @default(0)
percentageDiscount Decimal @db.Decimal(3, 2)
restrictedToProductId String?
bulkPurchaseId String? @unique
bulkPurchase Purchase? @relation("IndividualBulkCoupon", fields: [bulkPurchaseId], references: [id], onDelete: NoAction, onUpdate: NoAction)
merchantCoupon MerchantCoupon? @relation(fields: [merchantCouponId], references: [id], onDelete: Cascade)
product Product? @relation(fields: [restrictedToProductId], references: [id], onDelete: Cascade)
purchases Purchase[] @relation("StandardPurchase")
bulkCouponRedemptionPurchases Purchase[] @relation("RedeemedBulkCoupon")
bulkCouponPurchases Purchase[] @relation("BulkCoupon")
}
model MerchantAccount {
id String @id @default(uuid())
status Int @default(0)
createdAt DateTime @default(now())
label String?
identifier String?
merchantCharges MerchantCharge[]
merchantCoupons MerchantCoupon[]
merchantCustomers MerchantCustomer[]
merchantPrices MerchantPrice[]
merchantProducts MerchantProduct[]
merchantSession MerchantSession[]
}
model MerchantCharge {
id String @id @default(uuid())
status Int @default(0)
identifier String @unique
userId String
merchantAccountId String
merchantProductId String
createdAt DateTime @default(now())
merchantCustomerId String
merchantAccount MerchantAccount @relation(fields: [merchantAccountId], references: [id], onDelete: Cascade)
merchantCustomer MerchantCustomer @relation(fields: [merchantCustomerId], references: [id], onDelete: Cascade)
merchantProduct MerchantProduct @relation(fields: [merchantProductId], references: [id], onDelete: Cascade)
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
purchase Purchase[]
}
model MerchantCoupon {
id String @id @default(uuid())
identifier String? @unique
status Int @default(0)
merchantAccountId String
percentageDiscount Decimal @db.Decimal(3, 2)
type String?
merchantAccount MerchantAccount @relation(fields: [merchantAccountId], references: [id], onDelete: Cascade)
coupon Coupon[]
}
model MerchantCustomer {
id String @id @default(uuid())
userId String
merchantAccountId String
identifier String @unique
createdAt DateTime @default(now())
status Int? @default(0)
merchantAccount MerchantAccount @relation(fields: [merchantAccountId], references: [id], onDelete: Cascade)
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
merchantCharges MerchantCharge[]
}
model MerchantPrice {
id String @id @default(uuid())
merchantAccountId String
merchantProductId String
status Int? @default(0)
identifier String? @unique
createdAt DateTime @default(now())
priceId String?
merchantAccount MerchantAccount @relation(fields: [merchantAccountId], references: [id], onDelete: Cascade)
merchantProduct MerchantProduct @relation(fields: [merchantProductId], references: [id], onDelete: Cascade)
price Price? @relation(fields: [priceId], references: [id], onDelete: Cascade)
}
model MerchantProduct {
id String @id @default(uuid())
merchantAccountId String
productId String
status Int @default(0)
identifier String? @unique
createdAt DateTime @default(now())
merchantAccount MerchantAccount @relation(fields: [merchantAccountId], references: [id], onDelete: Cascade)
product Product @relation(fields: [productId], references: [id], onDelete: Cascade)
merchantCharges MerchantCharge[]
merchantPrices MerchantPrice[]
}
model MerchantSession {
id String @id @default(uuid())
identifier String
merchantAccountId String
merchantAccount MerchantAccount @relation(fields: [merchantAccountId], references: [id], onDelete: Cascade)
purchase Purchase[]
}
model Price {
id String @id @default(uuid())
productId String?
nickname String?
status Int @default(0)
unitAmount Decimal @db.Decimal(10, 2)
createdAt DateTime @default(now())
product Product? @relation(fields: [productId], references: [id], onDelete: Cascade)
merchantPrices MerchantPrice[]
}
model Product {
id String @id @default(uuid())
name String
key String?
createdAt DateTime @default(now())
status Int @default(0)
coupons Coupon[]
merchantProducts MerchantProduct[]
prices Price[]
purchases Purchase[]
quantityAvailable Int @default(-1)
upgradableTo UpgradableProducts[] @relation("UpgradeToProduct")
upgradableFrom UpgradableProducts[] @relation("UpgradeFromProduct")
}
model UpgradableProducts {
upgradableTo Product @relation("UpgradeToProduct", fields: [upgradableToId], references: [id])
upgradableToId String
upgradableFrom Product @relation("UpgradeFromProduct", fields: [upgradableFromId], references: [id])
upgradableFromId String
@@id([upgradableToId, upgradableFromId])
}
model Purchase {
id String @id @default(uuid())
userId String?
createdAt DateTime @default(now())
totalAmount Decimal
ip_address String?
city String?
state String?
country String?
couponId String?
bulkCouponId String?
redeemedBulkCouponId String?
productId String
merchantChargeId String?
merchantSessionId String?
upgradedFromId String? @unique
upgradedFrom Purchase? @relation("UpgradedToPurchase", fields: [upgradedFromId], references: [id], onDelete: NoAction, onUpdate: NoAction)
upgradedTo Purchase? @relation("UpgradedToPurchase")
bulkCoupon Coupon? @relation("BulkCoupon", fields: [bulkCouponId], references: [id])
individualBulkCoupon Coupon? @relation("IndividualBulkCoupon")
coupon Coupon? @relation("StandardPurchase", fields: [couponId], references: [id], onDelete: Cascade)
redeemedBulkCoupon Coupon? @relation("RedeemedBulkCoupon", fields: [redeemedBulkCouponId], references: [id], onDelete: NoAction)
merchantCharge MerchantCharge? @relation(fields: [merchantChargeId], references: [id], onDelete: Cascade)
merchantSession MerchantSession? @relation(fields: [merchantSessionId], references: [id], onDelete: Cascade)
product Product @relation(fields: [productId], references: [id], onDelete: Cascade)
user User? @relation(fields: [userId], references: [id], onDelete: Cascade)
status String @default("Valid")
purchaseUserTransfers PurchaseUserTransfer[]
@@index([userId])
}
model Session {
id String @id @default(uuid())
sessionToken String
userId String?
expires DateTime?
user User? @relation(fields: [userId], references: [id], onDelete: Cascade)
}
model User {
id String @id @default(uuid())
name String?
email String @unique
emailVerified DateTime?
image String?
accounts Account[]
merchantCharges MerchantCharge[]
merchantCustomers MerchantCustomer[]
purchases Purchase[]
sessions Session[]
lessonProgresses LessonProgress[]
sourcePurchaseTransfers PurchaseUserTransfer[] @relation("SourceUser")
targetPurchaseTransfers PurchaseUserTransfer[] @relation("TargetUser")
deviceVerifications DeviceVerification[] @relation("VerifiedByUser")
deviceAccessTokens DeviceAccessToken[] @relation("User")
comments Comment[]
roles String @default("User")
}
model VerificationToken {
token String @id
identifier String
expires DateTime?
createdAt DateTime? @default(now())
@@unique([identifier, token])
}
model DeviceVerification {
deviceCode String @id @default(uuid())
userCode String
expires DateTime
createdAt DateTime? @default(now())
verifiedAt DateTime?
verifiedBy User? @relation("VerifiedByUser", fields: [verifiedByUserId], references: [id], onDelete: Cascade)
verifiedByUserId String?
@@unique([deviceCode])
}
model DeviceAccessToken {
token String @id @default(uuid())
user User @relation("User", fields: [userId], references: [id], onDelete: Cascade)
createdAt DateTime? @default(now())
userId String
}
enum PurchaseUserTransferState {
AVAILABLE
INITIATED
VERIFIED
CANCELED
EXPIRED
CONFIRMED
COMPLETED
}
model PurchaseUserTransfer {
id String @id @default(uuid())
transferState PurchaseUserTransferState @default(AVAILABLE)
purchase Purchase @relation(fields: [purchaseId], references: [id], onDelete: Cascade)
purchaseId String
sourceUser User @relation("SourceUser", fields: [sourceUserId], references: [id], onDelete: Cascade)
sourceUserId String
targetUser User? @relation("TargetUser", fields: [targetUserId], references: [id], onDelete: Cascade)
targetUserId String?
createdAt DateTime @default(now())
expiresAt DateTime?
canceledAt DateTime?
confirmedAt DateTime?
completedAt DateTime?
}