Repository navigation
Expand file tree
/
Copy pathschema.prisma
More file actions
386 lines (313 loc) · 9.78 KB
/
Copy pathschema.prisma
File metadata and controls
386 lines (313 loc) · 9.78 KB
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
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
generator client {
provider = "prisma-client-js"
}
datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
}
// ============================================================================
// Enums
// ============================================================================
enum RequestPriority {
LOW
MEDIUM
HIGH
}
enum UserType {
STAFF
PARTNER
}
enum DonorOfferState {
UNFINALIZED
FINALIZED
ARCHIVED
}
enum ShipmentStatus {
WAITING_ARRIVAL_FROM_DONOR
LOAD_ON_SHIP_AIR
ARRIVED_IN_HAITI
CLEARED_CUSTOMS
ARRIVED_AT_DEPO
INVENTORIES
READY_FOR_DISTRIBUTION
}
enum ItemType {
MEDICATION
MEDICATION_SUPPLEMENT
NON_MEDICATION
}
enum ItemCategory {
NEEDLES_SYRINGES
ALZHEIMERS
ANTIBIOTIC
ANTIFUNGAL
ANTIVIRAL
BOOKS
CANCER
CARDIOVASCULAR
CLOTHING_ACCESSORIES
DENTAL
DERMATOLOGY
DEWORMER
DIABETES
EMERGENCY_RELIEF
ENT
FACILITY
FLUID_REPLENISHMENT
GASTROENTEROLOGY
GENERAL
HIV
HORMONES
HYGIENE
LAB
NEUROLOGICAL
NUTRITION_SUPPLEMENTS
OB_GYN
OFFICE_SUPPLIES
OPHTHALMOLOGY
ORTHO
PAIN_RELIEVERS
PEDIATRIC
PPE
PSYCHIATRIC
RECREATION
RESPIRATORY
STEROID
SURGICAL
THYROID
URINARY_BOWEL
VACCINES
WASH
WOUND_CARE
X_RAY
}
// ============================================================================
// User Management
// ============================================================================
model User {
id Int @id @default(autoincrement())
email String @unique
name String
passwordHash String
type UserType
tag String?
enabled Boolean @default(true)
pending Boolean @default(true)
isSuper Boolean @default(false)
userRead Boolean @default(false)
userWrite Boolean @default(false)
itemNotify Boolean @default(false)
offerWrite Boolean @default(false)
requestRead Boolean @default(false)
requestWrite Boolean @default(false)
allocationRead Boolean @default(false)
allocationWrite Boolean @default(false)
archivedRead Boolean @default(false)
distributionRead Boolean @default(false)
distributionWrite Boolean @default(false)
shipmentRead Boolean @default(false)
shipmentWrite Boolean @default(false)
signoffWrite Boolean @default(false)
wishlistRead Boolean @default(false)
supportRead Boolean @default(false)
supportWrite Boolean @default(false)
supportNotify Boolean @default(false)
donorOfferVisibilities DonorOffer[]
partnerDetails Json?
generalItemRequests GeneralItemRequest[]
allocations Allocation[]
distributions Distribution[]
wishlists Wishlist[]
invite UserInvite?
notifications Notification[]
streamUserId String? @unique
streamUserToken String? @unique
dashboardTutorial Boolean @default(false)
itemsTutorial Boolean @default(false)
requestsTutorial Boolean @default(false)
wishlistsTutorial Boolean @default(false)
}
model UserInvite {
id Int @id @default(autoincrement())
token String @unique
expiration DateTime
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
userId Int @unique
}
// ============================================================================
// Donor Offers
// ============================================================================
model DonorOffer {
id Int @id @default(autoincrement())
state DonorOfferState
offerName String
donorName String
partnerResponseDeadline DateTime
donorResponseDeadline DateTime
archivedAt DateTime?
partnerVisibilities User[]
items GeneralItem[]
embeddings ItemEmbedding[]
}
// ============================================================================
// Items
// ============================================================================
model GeneralItem {
id Int @id @default(autoincrement())
donorOfferId Int
donorOffer DonorOffer @relation(fields: [donorOfferId], references: [id], onDelete: Cascade)
title String
expirationDate DateTime? @db.Date
unitType String
initialQuantity Int
requestQuantity Int?
description String?
type ItemType?
category ItemCategory?
weight Decimal @db.Decimal(10, 2)
requests GeneralItemRequest[]
items LineItem[]
wishlists Wishlist[]
embedding ItemEmbedding? @relation("GeneralItemEmbedding")
@@unique([donorOfferId, title, expirationDate, unitType])
}
// A specific item inside a general item. Ex: a specific box inside a donation of many boxes
model LineItem {
id Int @id @default(autoincrement())
// Columns that define a unique line item
donorName String
quantity Int
lotNumber String
palletNumber String
boxNumber String
unitPrice Decimal @db.Money
maxRequestLimit String?
donorShippingNumber String?
hfhShippingNumber String?
datePosted DateTime @default(now())
ndc String?
notes String?
allowAllocations Boolean
visible Boolean
gik Boolean
generalItemId Int?
generalItem GeneralItem? @relation(fields: [generalItemId], references: [id], onDelete: Cascade)
allocation Allocation? @relation
}
model ItemEmbedding {
id Int @id @default(autoincrement())
generalItemId Int? @unique
wishlistId Int? @unique
donorOfferId Int?
embedding Unsupported("vector")
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
generalItem GeneralItem? @relation("GeneralItemEmbedding", fields: [generalItemId], references: [id], onDelete: Cascade)
wishlist Wishlist? @relation("WishlistEmbedding", fields: [wishlistId], references: [id], onDelete: Cascade)
donorOffer DonorOffer? @relation(fields: [donorOfferId], references: [id], onDelete: Cascade)
@@index([donorOfferId])
@@index([generalItemId])
@@index([wishlistId])
@@map("ItemEmbeddings")
}
// ============================================================================
// Requests
// ============================================================================
model GeneralItemRequest {
id Int @id @default(autoincrement())
generalItemId Int
generalItem GeneralItem @relation(fields: [generalItemId], references: [id], onDelete: Cascade)
partnerId Int
partner User @relation(fields: [partnerId], references: [id], onDelete: Cascade)
quantity Int
finalQuantity Int @default(0)
comments String?
priority RequestPriority?
createdAt DateTime @default(now())
@@unique([generalItemId, partnerId])
}
// ============================================================================
// Allocations & Distributions
// ============================================================================
model Allocation {
id Int @id @default(autoincrement())
partnerId Int?
partner User? @relation(fields: [partnerId], references: [id], onDelete: Cascade)
lineItemId Int @unique
lineItem LineItem @relation(fields: [lineItemId], references: [id], onDelete: Cascade)
distributionId Int
distribution Distribution @relation(fields: [distributionId], references: [id], onDelete: Cascade)
signOffId Int?
signOff SignOff? @relation(fields: [signOffId], references: [id], onDelete: Cascade)
}
model Distribution {
id Int @id @default(autoincrement())
partnerId Int
partner User @relation(fields: [partnerId], references: [id])
pending Boolean @default(false)
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
allocations Allocation[]
}
model SignOff {
id Int @id @default(autoincrement())
staffMemberName String
partnerId Int
partnerName String
partnerSignerName String?
date DateTime
signatureUrl String?
partnerSignatureUrl String?
createdAt DateTime @default(now())
allocations Allocation[]
}
// ============================================================================
// Shipping
// ============================================================================
model ShippingStatus {
id Int @id @default(autoincrement())
donorShippingNumber String?
hfhShippingNumber String?
value ShipmentStatus
@@unique([donorShippingNumber, hfhShippingNumber])
}
// ============================================================================
// Wishlists
// ============================================================================
model Wishlist {
id Int @id @default(autoincrement())
name String
quantity Int?
priority RequestPriority
lastUpdated DateTime @updatedAt
comments String
partnerId Int
partner User @relation(fields: [partnerId], references: [id], onDelete: Cascade)
generalItemId Int?
generalItem GeneralItem? @relation(fields: [generalItemId], references: [id])
embedding ItemEmbedding? @relation("WishlistEmbedding")
}
// ============================================================================
// Miscellaneous
// ============================================================================
model PasswordResetToken {
id Int @id @default(autoincrement())
userId Int
token String @unique
expiresAt DateTime
used Boolean @default(false)
}
model Notification {
id Int @id @default(autoincrement())
title String
action String?
actionText String?
dateCreated DateTime @default(now())
dateViewed DateTime?
isDelivered Boolean @default(false)
template String?
payload Json?
userId Int
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
@@index([userId, dateViewed])
}