-
Notifications
You must be signed in to change notification settings - Fork 0
/
schema.prisma
578 lines (531 loc) · 19 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
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
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
directUrl = env("DIRECT_URL")
}
generator client {
provider = "prisma-client-js"
binaryTargets = "native"
}
model User {
id Int @id @default(autoincrement())
createdAt DateTime @default(now())
updatedAt DateTime @default(now())
email String @unique
person Person @relation(name: "attachedUser", fields: [personId], references: [id])
personId Int @unique
verified Boolean? @default(false)
credentials UserCredential[]
userRoles UserRole[]
groupMemberships GroupMembership[]
listMemberships ListMembership[]
partnershipStatusChanges PartnershipStatusChange[]
partnershipContactsAdded PartnershipContact[]
listViews ListView[]
reservations Reservation[]
giftPreferencesAdded GiftPreferences[]
listItemTags ListItemTag[]
listTags ListTag[]
peopleCreated Person[] @relation(name: "createdPeople")
// START AUTH
hashedPassword String?
salt String?
resetToken String?
resetTokenExpiresAt DateTime?
webAuthnChallenge String? @unique
// END AUTH
partnershipLinkStatusChanges PartnershipLinkStatusChange[]
partnershipLinksCreated PartnershipLink[]
userInvites UserInvite[]
}
model UserCredential {
id String @id
createdAt DateTime @default(now())
updatedAt DateTime @default(now())
userId Int
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
publicKey Bytes
transports String?
counter BigInt
}
model UserRole {
id Int @id @default(autoincrement())
createdAt DateTime @default(now())
updatedAt DateTime @default(now())
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
userId Int
role Role @default(USER)
}
enum Role {
USER
SUPPORT
ADMIN
}
model UserInvite {
id String @id @default(cuid())
createdAt DateTime @default(now())
updatedAt DateTime @default(now())
expiresAt DateTime @default(dbgenerated("(now() + '3 days'::interval)"))
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
userId Int
status InviteStatus @default(PENDING)
name String?
email String?
listMembership ListMembership? @relation(fields: [listMembershipId], references: [id], onDelete: Cascade)
listMembershipId Int?
groupMembership GroupMembership? @relation(fields: [groupMembershipId], references: [id], onDelete: Cascade)
groupMembershipId Int?
}
enum InviteStatus {
PENDING
SENT
OPENED
CLICKED
EXPIRED
COMPLETE
ACCEPTED
DECLINED
}
model GroupMembership {
id Int @id @default(autoincrement())
createdAt DateTime @default(now())
updatedAt DateTime @default(now())
userId Int
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
groupRole GroupRole @default(VIEW)
group Group @relation(fields: [groupId], references: [id], onDelete: Cascade)
groupId Int
userInvites UserInvite[]
}
enum GroupRole {
VIEW
EDIT
ADMIN
OWNER
}
model Group {
id Int @id @default(autoincrement())
createdAt DateTime @default(now())
updatedAt DateTime @default(now())
name String
description String?
listGroupMemberships ListGroupMembership[]
groupMemberships GroupMembership[]
type GroupType @default(GENERIC)
visibility GroupVisibility @default(PRIVATE)
identifier Identifier?
}
enum GroupType {
GENERIC
FRIENDS
FAMILY
COMPANY
NON_PROFIT
}
enum GroupVisibility {
PRIVATE
LINK
PUBLIC
}
model ListGroupMembership {
id Int @id @default(autoincrement())
createdAt DateTime @default(now())
updatedAt DateTime @default(now())
listRole ListRole @default(VIEW)
list List @relation(fields: [listId], references: [id], onDelete: Cascade)
listId Int
group Group @relation(fields: [groupId], references: [id], onDelete: Cascade)
groupId Int
// TODO: add listRole if groups can have more than one role
@@unique([listId, groupId])
}
enum ListRole {
VIEW
CONTRIBUTE
EDIT
ADMIN
OWNER
}
model ListMembership {
id Int @id @default(autoincrement())
createdAt DateTime @default(now())
updatedAt DateTime @default(now())
listRole ListRole @default(VIEW)
list List @relation(fields: [listId], references: [id], onDelete: Cascade)
listId Int
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
userId Int
userInvites UserInvite[]
// TODO: add listRole if users can have more than one role
@@unique([listId, userId])
}
model List {
id Int @id @default(autoincrement())
createdAt DateTime @default(now())
updatedAt DateTime @default(now())
name String
description String?
type ListType @default(WISHLIST)
listGroupMemberships ListGroupMembership[]
listMemberships ListMembership[]
listItems ListItem[]
visibility ListVisibility @default(PRIVATE)
listViews ListView[]
parent List? @relation(name: "listInheritance", fields: [parentId], references: [id])
parentId Int?
children List[] @relation(name: "listInheritance")
order Int?
identifier Identifier?
}
model ListView {
id Int @id @default(autoincrement())
createdAt DateTime @default(now())
user User? @relation(fields: [userId], references: [id])
userId Int?
list List? @relation(fields: [listId], references: [id])
listId Int?
metadata Json?
}
// TODO: ListView: List, Table, Masonry, etc.
enum ListType {
GIFTS
WISHLIST
WEDDING
BABY_SHOWER
TOP
BOOKMARKS
SOCIAL
FAVORITES
AWESOME
INVENTORY
TODO
// Like reddit, voting by default?
// FORUM
// TABLE
LINKTREE
JOBS
SCHOOL
SHOPPING
GROCERIES
IDEAS
INFO
CLASSIFIEDS
LISTINGS
}
enum ListVisibility {
PRIVATE
GROUP
LINK
PUBLIC
}
model ListItem {
id Int @id @default(autoincrement())
createdAt DateTime @default(now())
updatedAt DateTime @default(now())
title String
description String?
url String?
list List @relation(fields: [listId], references: [id], onDelete: Cascade)
listId Int
quantity Int? @default(1)
voting Boolean @default(false)
reservations Reservation[]
parent ListItem? @relation(name: "listItemInheritance", fields: [parentId], references: [id])
parentId Int?
children ListItem[] @relation(name: "listItemInheritance")
images Image[]
order Int?
price Decimal? @db.Money
partnershipLink PartnershipLink?
}
model Image {
id Int @id @default(autoincrement())
createdAt DateTime @default(now())
updatedAt DateTime @default(now())
url String
height Decimal?
width Decimal?
format String?
listItem ListItem? @relation(fields: [listItemId], references: [id])
listItemId Int?
person Person? @relation(fields: [personId], references: [id])
personId Int?
alt String?
}
model Reservation {
id Int @id @default(autoincrement())
createdAt DateTime @default(now())
updatedAt DateTime @default(now())
listItem ListItem @relation(fields: [listItemId], references: [id], onDelete: Cascade)
listItemId Int
quantity Int @default(1)
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
userId Int
comment String?
price Decimal? @db.Money
status ReservationStatus @default(RESERVED)
// purchaseStatus PurchaseStatus?
}
enum ReservationStatus {
RESERVED
RELEASED
FULFILLED
}
// enum PurchaseStatus {
// PENDING
// COMPLETED
// CANCELED
// RETURNED
// REFUNDED
// }
model Partnership {
id Int @id @default(autoincrement())
createdAt DateTime @default(now())
updatedAt DateTime @default(now())
name String
notes String?
status PartnershipStatus @default(QUEUED)
url String
partnershipContacts PartnershipContact[]
partnershipStatusChanges PartnershipStatusChange[]
partnershipLinks PartnershipLink[]
// Example AMAZON_ASSOCIATE_ID
affiliateId String?
// Example: associateId (tag? on Amazon) - need to create link with API after 3 purchases
affiliateIdParam String?
}
enum PartnershipStatus {
QUEUED
CONTACTING
SELLING
NEGOTIATING
SIGNING
SUCCESSFUL
UNSUCCESSFUL
}
model PartnershipStatusChange {
id Int @id @default(autoincrement())
createdAt DateTime @default(now())
from PartnershipStatus
to PartnershipStatus
notes String
changedByUser User? @relation(fields: [changedByUserId], references: [id])
changedByUserId Int?
partnership Partnership @relation(fields: [partnershipId], references: [id])
partnershipId Int
}
model PartnershipContact {
id Int @id @default(autoincrement())
createdAt DateTime @default(now())
updatedAt DateTime @default(now())
person Person @relation(fields: [personId], references: [id], onDelete: Cascade)
personId Int @unique
partnership Partnership? @relation(fields: [partnershipId], references: [id])
partnershipId Int?
addedByUser User? @relation(fields: [addedByUserId], references: [id])
addedByUserId Int?
}
model Person {
id Int @id @default(autoincrement())
createdAt DateTime @default(now())
updatedAt DateTime @default(now())
name String
description String?
pronouns String?
email String? @unique
user User? @relation(name: "attachedUser")
addresses Address[]
defaultAddressId Int?
partnershipContact PartnershipContact?
giftPreferences GiftPreferences[]
images Image[]
createdByUser User? @relation(name: "createdPeople", fields: [createdByUserId], references: [id])
createdByUserId Int?
identifier Identifier?
visibility PersonVisibility @default(PRIVATE)
}
enum PersonVisibility {
PRIVATE
GROUP
PUBLIC
}
// https://medium.com/android-news/international-addresses-7477db08edac
model Address {
id Int @id @default(autoincrement())
createdAt DateTime @default(now())
updatedAt DateTime @default(now())
// Administrative area or district
administrativeArea String
// Alternative administrative area or district
alternativeAdministrativeArea String
// Alternative locality
alternativeLocality String
// Traditional county (GBR only)
alternativeProvince String
// Name of building
buildingName String
// Number of building
buildingNumber String
// Name of company (GBR only)
companyName String
// Country name in local language
countryName String
// Name of department within company (GBR only)
departmentName String
// Sub-locality within town or city
dependentLocality String
// Name of the dependent street or thoroughfare
dependentStreetName String
// Type of dependent street or thoroughfare (e.g street, road, lane, etc.) (GBR only)
dependentStreetSuffix String
// District within sub-locality
doubleDependentLocality String
// Level name or number
levelName String
// Formatted address line 1
line1 String
// Formatted address line 2
line2 String
// Formatted address line 3
line3 String
// Formatted address line 4
line4 String
// Formatted address line 5
line5 String
// Town or city
locality String
// PO Box Number (GBR only)
postOfficeBoxNumber String
// Royal Mail Unique Delivery Point Reference Number (GBR only)
postOfficeReference1 String
// Royal Mail Delivery Point Suffix (GBR only)
postOfficeReference2 String
// Formatted postal code or ZIP code
postalCode String
// Preferred name, abbreviation or acronym for state, province or county
province String
// Abbreviation or acronym for state, province or county
provinceCode String
// Full name of state, province or county
provinceName String
// Name of the street or thoroughfare
streetName String
// Type of street or thoroughfare (e.g street, road, lane, etc.) (GBR only)
streetSuffix String
// Sub-name of building
subBuildingName String
// Unit name or number
unitName String
person Person? @relation(fields: [personId], references: [id])
personId Int?
}
model GiftPreferences {
id Int @id @default(autoincrement())
createdAt DateTime @default(now())
updatedAt DateTime @default(now())
clothingSizes ClothingSizes?
giftNotes GiftNotes?
person Person @relation(fields: [personId], references: [id], onDelete: Cascade)
personId Int
addedByUser User @relation(fields: [addedByUserId], references: [id], onDelete: Cascade)
addedByUserId Int
}
model ClothingSizes {
id Int @id @default(autoincrement())
createdAt DateTime @default(now())
updatedAt DateTime @default(now())
giftPreferences GiftPreferences @relation(fields: [giftPreferencesId], references: [id], onDelete: Cascade)
giftPreferencesId Int @unique
shoeSize String?
shirt String?
pants String?
jacket String?
dress String?
hat String?
}
model GiftNotes {
id Int @id @default(autoincrement())
createdAt DateTime @default(now())
updatedAt DateTime @default(now())
giftPreferences GiftPreferences @relation(fields: [giftPreferencesId], references: [id], onDelete: Cascade)
giftPreferencesId Int @unique
name String
note String
}
model ListTag {
id Int @id @default(autoincrement())
createdAt DateTime @default(now())
updatedAt DateTime @default(now())
// Why was this tag added or changed
note String?
tag Tag @relation(fields: [tagId], references: [id], onDelete: Cascade)
tagId Int
addedByUser User? @relation(fields: [addedByUserId], references: [id])
addedByUserId Int?
}
model ListItemTag {
id Int @id @default(autoincrement())
createdAt DateTime @default(now())
updatedAt DateTime @default(now())
// Why was this tag added or changed
note String?
tag Tag @relation(fields: [tagId], references: [id], onDelete: Cascade)
tagId Int
addedByUser User? @relation(fields: [addedByUserId], references: [id])
addedByUserId Int?
}
model Tag {
id Int @id @default(autoincrement())
createdAt DateTime @default(now())
updatedAt DateTime @default(now())
name String
description String?
listItemTags ListItemTag[]
listTags ListTag[]
parentTag Tag? @relation(name: "tagInheritance", fields: [parentTagId], references: [id])
parentTagId Int?
childTags Tag[] @relation(name: "tagInheritance")
@@unique([parentTagId, name])
}
model Identifier {
id String @id @default(cuid())
createdAt DateTime @default(now())
updatedAt DateTime @default(now())
person Person? @relation(fields: [personId], references: [id], onDelete: Cascade)
personId Int? @unique
list List? @relation(fields: [listId], references: [id], onDelete: Cascade)
listId Int? @unique
group Group? @relation(fields: [groupId], references: [id], onDelete: Cascade)
groupId Int? @unique
}
model PartnershipLink {
id String @id @default(cuid())
createdAt DateTime @default(now())
updatedAt DateTime @default(now())
status PartnershipLinkStatus @default(PENDING)
originalUrl String
partnership Partnership? @relation(fields: [partnershipId], references: [id])
partnershipId Int? @unique
listItem ListItem? @relation(fields: [listItemId], references: [id])
listItemId Int? @unique
createdByUser User? @relation(fields: [createdByUserId], references: [id])
createdByUserId Int?
partnershipLinkStatusChanges PartnershipLinkStatusChange[]
}
enum PartnershipLinkStatus {
PENDING
DIGESTING
SUCCESSFUL
UNSUCCESSFUL
}
model PartnershipLinkStatusChange {
id Int @id @default(autoincrement())
createdAt DateTime @default(now())
from PartnershipLinkStatus
to PartnershipLinkStatus
notes String
changedByUser User? @relation(fields: [changedByUserId], references: [id])
changedByUserId Int?
partnershipLink PartnershipLink @relation(fields: [partnershipLinkId], references: [id])
partnershipLinkId String
}