Repository navigation
Expand file tree
/
Copy pathschema.prisma
More file actions
1958 lines (1806 loc) · 96.5 KB
/
Copy pathschema.prisma
File metadata and controls
1958 lines (1806 loc) · 96.5 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
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
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// This file is automatically generated by Keystone, do not modify it manually.
// Modify your Keystone config when you want to change this.
datasource postgresql {
url = env("DATABASE_URL")
shadowDatabaseUrl = env("SHADOW_DATABASE_URL")
provider = "postgresql"
}
generator client {
provider = "prisma-client-js"
}
model InventoryConversion {
id String @id @default(cuid())
idempotencyKey String @unique @default("")
inputFingerprint String @default("")
reviewHash String @default("")
quantityCases Int
unitsPerCase Int
destinationQuantity Int
totalCostCents Int
currencyCode String @default("")
reason String @default("")
conditionNote String @default("")
actorId String @default("")
committedAt DateTime?
sourceSnapshot Json?
destinations Json?
sourceInventoryLot InventoryLot? @relation("InventoryConversion_sourceInventoryLot", fields: [sourceInventoryLotId], references: [id])
sourceInventoryLotId String? @map("sourceInventoryLot")
sourceProduct Product? @relation("InventoryConversion_sourceProduct", fields: [sourceProductId], references: [id])
sourceProductId String? @map("sourceProduct")
destinationProduct Product? @relation("InventoryConversion_destinationProduct", fields: [destinationProductId], references: [id])
destinationProductId String? @map("destinationProduct")
store Store @relation("InventoryConversion_store", fields: [storeId], references: [id])
storeId String @map("store")
createdAt DateTime @default(now())
updatedAt DateTime @default(now()) @updatedAt
@@index([sourceInventoryLotId])
@@index([sourceProductId])
@@index([destinationProductId])
@@index([storeId])
}
model CatalogImport {
id String @id @default(cuid())
identityKey String @unique @default("")
idempotencyKey String @unique @default("")
sourceSystem String @default("")
sourceBatchId String @default("")
schemaVersion Int
payloadHash String @default("")
reviewHash String @default("")
currencyCode String @default("")
rowCount Int
rows Json?
result Json?
committedAt DateTime
actorId String @default("")
store Store @relation("CatalogImport_store", fields: [storeId], references: [id])
storeId String @map("store")
createdAt DateTime @default(now())
updatedAt DateTime @default(now()) @updatedAt
@@index([storeId])
}
model CustomerPrivacyRequest {
id String @id @default(cuid())
store Store? @relation("CustomerPrivacyRequest_store", fields: [storeId], references: [id])
storeId String? @map("store")
user User? @relation("CustomerPrivacyRequest_user", fields: [userId], references: [id])
userId String? @map("user")
kind String?
status String? @default("requested")
policyVersion String @default("")
reviewReason String @default("")
reviewedBy User? @relation("CustomerPrivacyRequest_reviewedBy", fields: [reviewedById], references: [id])
reviewedById String? @map("reviewedBy")
reviewedAt DateTime?
eligibleAt DateTime?
completedAt DateTime?
resultSummary Json?
createdAt DateTime @default(now())
updatedAt DateTime @default(now()) @updatedAt
@@index([storeId])
@@index([userId])
@@index([reviewedById])
}
model StaffAccessEvent {
id String @id @default(cuid())
store Store? @relation("StaffAccessEvent_store", fields: [storeId], references: [id])
storeId String? @map("store")
actor User? @relation("StaffAccessEvent_actor", fields: [actorId], references: [id])
actorId String? @map("actor")
subject User? @relation("StaffAccessEvent_subject", fields: [subjectId], references: [id])
subjectId String? @map("subject")
invitation StaffInvitation? @relation("StaffAccessEvent_invitation", fields: [invitationId], references: [id])
invitationId String? @map("invitation")
action String @default("")
reason String @default("")
before Json?
after Json?
createdAt DateTime @default(now())
updatedAt DateTime @default(now()) @updatedAt
@@index([storeId])
@@index([actorId])
@@index([subjectId])
@@index([invitationId])
}
model StaffInvitation {
id String @id @default(cuid())
store Store? @relation("StaffInvitation_store", fields: [storeId], references: [id])
storeId String? @map("store")
email String @default("")
name String @default("")
tokenHash String @unique @default("")
capabilities Json?
status String? @default("pending")
expiresAt DateTime
acceptedAt DateTime?
invitedBy User? @relation("StaffInvitation_invitedBy", fields: [invitedById], references: [id])
invitedById String? @map("invitedBy")
acceptedUser User? @relation("StaffInvitation_acceptedUser", fields: [acceptedUserId], references: [id])
acceptedUserId String? @map("acceptedUser")
createdAt DateTime @default(now())
updatedAt DateTime @default(now()) @updatedAt
from_StaffAccessEvent_invitation StaffAccessEvent[] @relation("StaffAccessEvent_invitation")
@@index([storeId])
@@index([invitedById])
@@index([acceptedUserId])
}
model OrderLineRefund {
id String @id @default(cuid())
idempotencyKey String @unique @default("")
requestKey String @default("")
providerRefundKey String @default("")
inputFingerprint String @default("")
store Store @relation("OrderLineRefund_store", fields: [storeId], references: [id])
storeId String @map("store")
order Order? @relation("OrderLineRefund_order", fields: [orderId], references: [id])
orderId String? @map("order")
payment Payment? @relation("OrderLineRefund_payment", fields: [paymentId], references: [id])
paymentId String? @map("payment")
paymentRefund PaymentRefund? @relation("OrderLineRefund_paymentRefund", fields: [paymentRefundId], references: [id])
paymentRefundId String? @map("paymentRefund")
lineItem OrderLineItem? @relation("OrderLineRefund_lineItem", fields: [lineItemId], references: [id])
lineItemId String? @map("lineItem")
finalSettlementId String @default("")
finalFulfillmentId String @default("")
productId String @default("")
productTitle String @default("")
unitOfMeasure String @default("")
currencyCode String @default("")
quantityMilli Int
quantityBefore Int?
quantityAfter Int?
fulfilledQuantityMilli Int?
subtotalCents Int?
discountCents Int?
netGoodsCents Int?
taxCents Int?
totalCents Int?
taxRateBasisPoints Int?
disposition String
conditionNote String @default("")
returnedLots Json?
reason String @default("")
requestedBy String @default("")
status String? @default("reserved")
failureMessage String @default("")
processedAt DateTime?
events Json?
createdAt DateTime @default(now())
updatedAt DateTime @default(now()) @updatedAt
@@index([requestKey])
@@index([providerRefundKey])
@@index([storeId])
@@index([orderId])
@@index([paymentId])
@@index([paymentRefundId])
@@index([lineItemId])
}
model LoyaltyRedemption {
id String @id @default(cuid())
idempotencyKey String @unique @default("")
points Int
discountCents Int
status String? @default("issued")
store Store? @relation("LoyaltyRedemption_store", fields: [storeId], references: [id])
storeId String? @map("store")
user User? @relation("LoyaltyRedemption_user", fields: [userId], references: [id])
userId String? @map("user")
program LoyaltyProgram? @relation("LoyaltyRedemption_program", fields: [programId], references: [id])
programId String? @map("program")
coupon Coupon? @relation("LoyaltyRedemption_coupon", fields: [couponId], references: [id])
couponId String? @map("coupon")
order Order? @relation("LoyaltyRedemption_order", fields: [orderId], references: [id])
orderId String? @map("order")
usedAt DateTime?
events Json?
createdAt DateTime @default(now())
updatedAt DateTime @default(now()) @updatedAt
@@index([storeId])
@@index([userId])
@@index([programId])
@@index([couponId])
@@index([orderId])
}
model SubscriptionRun {
id String @id @default(cuid())
idempotencyKey String @unique @default("")
subscription Subscription? @relation("SubscriptionRun_subscription", fields: [subscriptionId], references: [id])
subscriptionId String? @map("subscription")
store Store @relation("SubscriptionRun_store", fields: [storeId], references: [id])
storeId String @map("store")
user User? @relation("SubscriptionRun_user", fields: [userId], references: [id])
userId String? @map("user")
dueAt DateTime
status String
product Product? @relation("SubscriptionRun_product", fields: [productId], references: [id])
productId String? @map("product")
productTitle String @default("")
quantity Int?
priceCents Int?
cart Cart? @relation("SubscriptionRun_cart", fields: [cartId], references: [id])
cartId String? @map("cart")
cartItemId String @default("")
order Order? @relation("SubscriptionRun_order", fields: [orderId], references: [id])
orderId String? @map("order")
failureReason String @default("")
events Json?
createdAt DateTime @default(now())
updatedAt DateTime @default(now()) @updatedAt
@@index([subscriptionId])
@@index([storeId])
@@index([userId])
@@index([productId])
@@index([cartId])
@@index([orderId])
}
model SettlementMatch {
id String @id @default(cuid())
sourceKey String @unique @default("")
store Store? @relation("SettlementMatch_store", fields: [storeId], references: [id])
storeId String? @map("store")
recordedBy User? @relation("SettlementMatch_recordedBy", fields: [recordedById], references: [id])
recordedById String? @map("recordedBy")
payment Payment? @relation("SettlementMatch_payment", fields: [paymentId], references: [id])
paymentId String? @map("payment")
providerCode String @default("")
statementReference String @default("")
entryReference String @default("")
paymentReference String @default("")
refundReference String @default("")
payoutReference String @default("")
currencyCode String @default("")
entryType String
amountCents Int
feeCents Int
netCents Int
settledAt DateTime
status String? @default("unresolved")
reason String @default("")
evidence Json?
createdAt DateTime @default(now())
updatedAt DateTime @default(now()) @updatedAt
@@index([storeId])
@@index([recordedById])
@@index([paymentId])
}
model FinancialClose {
id String @id @default(cuid())
idempotencyKey String @unique @default("")
store Store? @relation("FinancialClose_store", fields: [storeId], references: [id])
storeId String? @map("store")
recordedBy User? @relation("FinancialClose_recordedBy", fields: [recordedById], references: [id])
recordedById String? @map("recordedBy")
periodStart DateTime
periodEnd DateTime
timezone String @default("")
cutoff DateTime
status String
note String @default("")
contentHash String @default("")
snapshot Json?
createdAt DateTime @default(now())
updatedAt DateTime @default(now()) @updatedAt
@@index([storeId])
@@index([recordedById])
}
model SupplierCredit {
id String @id @default(cuid())
identityKey String @unique @default("")
responseIdentityKey String @unique @default("")
idempotencyKey String @unique @default("")
kind String? @default("claim")
status String? @default("open")
reference String @default("")
amountCents Int?
claimedAmountCents Int?
currencyCode String @default("")
reason String @default("")
evidence String @default("")
openedBy String @default("")
resolvedBy String @default("")
resolvedAt DateTime?
events Json?
supplier Supplier? @relation("SupplierCredit_supplier", fields: [supplierId], references: [id])
supplierId String? @map("supplier")
invoice SupplierInvoice? @relation("SupplierCredit_invoice", fields: [invoiceId], references: [id])
invoiceId String? @map("invoice")
receipt PurchaseReceipt? @relation("SupplierCredit_receipt", fields: [receiptId], references: [id])
receiptId String? @map("receipt")
store Store @relation("SupplierCredit_store", fields: [storeId], references: [id])
storeId String @map("store")
createdAt DateTime @default(now())
updatedAt DateTime @default(now()) @updatedAt
@@index([supplierId])
@@index([invoiceId])
@@index([receiptId])
@@index([storeId])
}
model SupplierInvoice {
id String @id @default(cuid())
identityKey String @unique @default("")
idempotencyKey String @unique @default("")
invoiceNumber String @default("")
supplierName String @default("")
currencyCode String @default("")
invoiceDate DateTime
dueDate DateTime?
documentReference String @default("")
status String? @default("captured")
lines Json?
subtotalCents Int?
taxCents Int?
freightCents Int?
grossCents Int?
expectedCents Int?
varianceCents Int?
capturedBy String @default("")
approvedBy String @default("")
approvedAt DateTime?
settledBy String @default("")
settledAt DateTime?
settlement Json?
events Json?
inputFingerprint String @default("")
supplier Supplier? @relation("SupplierInvoice_supplier", fields: [supplierId], references: [id])
supplierId String? @map("supplier")
store Store @relation("SupplierInvoice_store", fields: [storeId], references: [id])
storeId String @map("store")
createdAt DateTime @default(now())
updatedAt DateTime @default(now()) @updatedAt
from_SupplierCredit_invoice SupplierCredit[] @relation("SupplierCredit_invoice")
@@index([supplierId])
@@index([storeId])
}
model ProductInformationVersion {
id String @id @default(cuid())
store Store? @relation("ProductInformationVersion_store", fields: [storeId], references: [id])
storeId String? @map("store")
product Product? @relation("ProductInformationVersion_product", fields: [productId], references: [id])
productId String? @map("product")
actor User? @relation("ProductInformationVersion_actor", fields: [actorId], references: [id])
actorId String? @map("actor")
idempotencyKey String @unique @default("")
sourceReference String @default("")
effectiveAt DateTime?
snapshot Json?
createdAt DateTime @default(now())
updatedAt DateTime @default(now()) @updatedAt
@@index([storeId])
@@index([productId])
@@index([actorId])
}
model CustomerMessage {
id String @id @default(cuid())
store Store? @relation("CustomerMessage_store", fields: [storeId], references: [id])
storeId String? @map("store")
eventKey String @unique @default("")
order Order? @relation("CustomerMessage_order", fields: [orderId], references: [id])
orderId String? @map("order")
user User? @relation("CustomerMessage_user", fields: [userId], references: [id])
userId String? @map("user")
recipient String @default("")
subject String @default("")
body String @default("")
channel String @default("email")
status String @default("pending")
attempts Int? @default(0)
providerEvidence Json?
failureMessage String @default("")
sentAt DateTime?
deliveryToken String @default("")
deliveryLeaseExpiresAt DateTime?
createdAt DateTime @default(now())
updatedAt DateTime @default(now()) @updatedAt
@@index([storeId])
@@index([orderId])
@@index([userId])
}
model ContactMessage {
id String @id @default(cuid())
store Store @relation("ContactMessage_store", fields: [storeId], references: [id])
storeId String @map("store")
customer User? @relation("ContactMessage_customer", fields: [customerId], references: [id])
customerId String? @map("customer")
reference String @unique @default("")
subject String @default("")
name String @default("")
email String @default("")
phone String @default("")
topic String @default("")
orderNumber String @default("")
message String @default("")
sourcePath String @default("")
status String @default("new")
staffNotes String @default("")
createdAt DateTime @default(now())
updatedAt DateTime @default(now()) @updatedAt
@@index([storeId])
@@index([customerId])
}
model PurchaseReceipt {
id String @id @default(cuid())
idempotencyKey String @unique @default("")
purchaseOrder PurchaseOrder? @relation("PurchaseReceipt_purchaseOrder", fields: [purchaseOrderId], references: [id])
purchaseOrderId String? @map("purchaseOrder")
poItem POItem? @relation("PurchaseReceipt_poItem", fields: [poItemId], references: [id])
poItemId String? @map("poItem")
inventoryLot InventoryLot? @relation("PurchaseReceipt_inventoryLot", fields: [inventoryLotId], references: [id])
inventoryLotId String? @map("inventoryLot")
supplier Supplier? @relation("PurchaseReceipt_supplier", fields: [supplierId], references: [id])
supplierId String? @map("supplier")
product Product? @relation("PurchaseReceipt_product", fields: [productId], references: [id])
productId String? @map("product")
supplierLotNumber String @default("")
deliveryReference String @default("")
quantity Decimal? @postgresql.Decimal(18, 3)
targetQuantityReceived Decimal? @postgresql.Decimal(18, 3)
unitCostCents Int?
conditionStatus String
inspectionNote String @default("")
receivedBy String @default("")
expirationDate DateTime?
store Store @relation("PurchaseReceipt_store", fields: [storeId], references: [id])
storeId String @map("store")
createdAt DateTime @default(now())
updatedAt DateTime @default(now()) @updatedAt
from_SupplierCredit_receipt SupplierCredit[] @relation("SupplierCredit_receipt")
@@index([purchaseOrderId])
@@index([poItemId])
@@index([inventoryLotId])
@@index([supplierId])
@@index([productId])
@@index([supplierLotNumber])
@@index([storeId])
}
model InventoryCount {
id String @id @default(cuid())
idempotencyKey String @unique @default("")
status String? @default("observed")
inventoryLot InventoryLot? @relation("InventoryCount_inventoryLot", fields: [inventoryLotId], references: [id])
inventoryLotId String? @map("inventoryLot")
product Product? @relation("InventoryCount_product", fields: [productId], references: [id])
productId String? @map("product")
expectedQuantity Decimal? @postgresql.Decimal(18, 3)
observedQuantity Decimal? @postgresql.Decimal(18, 3)
recountQuantity Decimal? @postgresql.Decimal(18, 3)
observedBy String @default("")
recountedBy String @default("")
approvedBy String @default("")
reason String @default("")
events Json?
approvedAt DateTime?
store Store @relation("InventoryCount_store", fields: [storeId], references: [id])
storeId String @map("store")
createdAt DateTime @default(now())
updatedAt DateTime @default(now()) @updatedAt
@@index([inventoryLotId])
@@index([productId])
@@index([storeId])
}
model InventoryRecall {
id String @id @default(cuid())
idempotencyKey String @unique @default("")
reason String @default("")
status String? @default("open")
scope Json?
affectedOrders Json?
events Json?
closure Json?
openedBy String @default("")
closedBy String @default("")
closedAt DateTime?
store Store @relation("InventoryRecall_store", fields: [storeId], references: [id])
storeId String @map("store")
createdAt DateTime @default(now())
updatedAt DateTime @default(now()) @updatedAt
@@index([storeId])
}
model InventoryMovement {
id String @id @default(cuid())
idempotencyKey String @unique @default("")
sequence Int
sourceType String @default("")
sourceId String @default("")
reason String @default("")
actorId String @default("")
quantityBefore Decimal? @postgresql.Decimal(18, 3)
quantityAfter Decimal? @postgresql.Decimal(18, 3)
quantityDelta Decimal? @postgresql.Decimal(18, 3)
productStockBefore Decimal? @postgresql.Decimal(18, 3)
productStockAfter Decimal? @postgresql.Decimal(18, 3)
metadata Json?
product Product? @relation("InventoryMovement_product", fields: [productId], references: [id])
productId String? @map("product")
inventoryLot InventoryLot? @relation("InventoryMovement_inventoryLot", fields: [inventoryLotId], references: [id])
inventoryLotId String? @map("inventoryLot")
order Order? @relation("InventoryMovement_order", fields: [orderId], references: [id])
orderId String? @map("order")
store Store @relation("InventoryMovement_store", fields: [storeId], references: [id])
storeId String @map("store")
createdAt DateTime @default(now())
updatedAt DateTime @default(now()) @updatedAt
@@index([sequence])
@@index([productId])
@@index([inventoryLotId])
@@index([orderId])
@@index([storeId])
}
model OrderSettlement {
id String @id @default(cuid())
order Order? @relation("OrderSettlement_order", fields: [orderId], references: [id])
orderId String? @map("order")
idempotencyKey String @unique @default("")
actualsHash String @default("")
status String? @default("processing")
totalCents Int
snapshot Json?
providerEvidence Json?
failureMessage String @default("")
finalizedBy User? @relation("OrderSettlement_finalizedBy", fields: [finalizedById], references: [id])
finalizedById String? @map("finalizedBy")
createdAt DateTime @default(now())
updatedAt DateTime @default(now()) @updatedAt
@@index([orderId])
@@index([finalizedById])
}
model OrderLineFulfillment {
id String @id @default(cuid())
idempotencyKey String @unique @default("")
lineItemIdSnapshot String @unique @default("")
lineItem OrderLineItem? @relation("OrderLineFulfillment_lineItem", fields: [lineItemId], references: [id])
lineItemId String? @unique @map("lineItem")
product Product? @relation("OrderLineFulfillment_product", fields: [productId], references: [id])
productId String? @map("product")
recordedBy User? @relation("OrderLineFulfillment_recordedBy", fields: [recordedById], references: [id])
recordedById String? @map("recordedBy")
resolution String
productTitle String @default("")
productSku String @default("")
unitOfMeasure String @default("")
quantityMilli Int
grossMilli Int
tareMilli Int
unitPriceCents Int
subtotalCents Int
taxRateBasisPoints Int
allocations Json?
evidence Json?
createdAt DateTime @default(now())
updatedAt DateTime @default(now()) @updatedAt
@@index([productId])
@@index([recordedById])
}
model Address {
id String @id @default(cuid())
firstName String @default("")
lastName String @default("")
company String @default("")
address1 String @default("")
address2 String @default("")
city String @default("")
province String @default("")
postalCode String @default("")
phone String @default("")
isSaved Boolean @default(false)
user User? @relation("Address_user", fields: [userId], references: [id])
userId String? @map("user")
createdAt DateTime @default(now())
updatedAt DateTime @default(now()) @updatedAt
from_Order_shippingAddress Order[] @relation("Order_shippingAddress")
from_Order_billingAddress Order[] @relation("Order_billingAddress")
@@index([userId])
}
model BackInStockAlert {
id String @id @default(cuid())
user User @relation("BackInStockAlert_user", fields: [userId], references: [id])
userId String @map("user")
product String @default("")
productRef Product? @relation("BackInStockAlert_productRef", fields: [productRefId], references: [id])
productRefId String? @map("productRef")
notifiedAt DateTime?
isActive Boolean @default(true)
createdAt DateTime @default(now())
updatedAt DateTime @default(now()) @updatedAt
@@index([userId])
@@index([product])
@@index([productRefId])
}
model Cart {
id String @id @default(cuid())
store Store @relation("Cart_store", fields: [storeId], references: [id])
storeId String @map("store")
customer User? @relation("Cart_customer", fields: [customerId], references: [id])
customerId String? @unique @map("customer")
sessionId String @unique @default("")
items CartItem[] @relation("CartItem_cart")
paymentSessions PaymentSession[] @relation("PaymentSession_cart")
checkoutAttempts CheckoutAttempt[] @relation("CheckoutAttempt_cart")
itemCount Int? @default(0)
subtotal Float? @default(0)
subtotalCents Int @default(0)
expiresAt DateTime?
createdAt DateTime @default(now())
updatedAt DateTime @default(now()) @updatedAt
from_SubscriptionRun_cart SubscriptionRun[] @relation("SubscriptionRun_cart")
@@index([storeId])
@@index([customerId])
}
model CheckoutAttempt {
id String @id @default(cuid())
idempotencyKey String @unique @default("")
providerCode String @default("")
providerPaymentId String @default("")
amountCents Int
currencyCode String @default("")
status CheckoutAttemptStatusType @default(pending)
attempts Int @default(0)
fencingToken Int @default(0)
leaseToken String?
leaseExpiresAt DateTime?
lastError String @default("")
requestData Json? @default("{}")
settledAt DateTime?
finalizedAt DateTime?
compensationAt DateTime?
store Store @relation("CheckoutAttempt_store", fields: [storeId], references: [id])
storeId String @map("store")
cart Cart @relation("CheckoutAttempt_cart", fields: [cartId], references: [id])
cartId String @map("cart")
paymentSession PaymentSession @relation("CheckoutAttempt_paymentSession", fields: [paymentSessionId], references: [id])
paymentSessionId String @map("paymentSession")
order Order? @relation("CheckoutAttempt_order", fields: [orderId], references: [id])
orderId String? @map("order")
createdAt DateTime @default(now())
updatedAt DateTime @default(now()) @updatedAt
@@index([storeId])
@@index([cartId])
@@index([paymentSessionId])
@@index([orderId])
}
model CartItem {
id String @id @default(cuid())
cart Cart @relation("CartItem_cart", fields: [cartId], references: [id])
cartId String @map("cart")
product Product @relation("CartItem_product", fields: [productId], references: [id])
productId String @map("product")
quantity Int @default(1)
subtotal Float? @default(0)
subtotalCents Int @default(0)
substitutionPreference CartItemSubstitutionPreferenceType? @default(allow)
addedAt DateTime @default(now())
createdAt DateTime @default(now())
updatedAt DateTime @default(now()) @updatedAt
@@unique([cartId, productId])
@@index([cartId])
@@index([productId])
}
model Coupon {
id String @id @default(cuid())
code String @unique @default("")
discountType CouponDiscountTypeType @default(percentage)
discountValue Float?
discountValueCents Int @default(0)
minPurchase Float? @default(0)
minPurchaseCents Int @default(0)
maxUses Int? @default(0)
currentUses Int? @default(0)
validFrom DateTime?
validTo DateTime?
productCategories Json?
categoryTaxonomy String @default("department_handle")
excludedProducts Json?
isActive Boolean @default(true)
store Store @relation("Coupon_store", fields: [storeId], references: [id])
storeId String @map("store")
userCoupons UserCoupon[] @relation("UserCoupon_coupon")
createdAt DateTime @default(now())
updatedAt DateTime @default(now()) @updatedAt
from_LoyaltyRedemption_coupon LoyaltyRedemption[] @relation("LoyaltyRedemption_coupon")
@@index([storeId])
}
model Department {
id String @id @default(cuid())
name String @default("")
handle String @unique @default("")
description String @default("")
image_id String?
image_filesize Int?
image_width Int?
image_height Int?
image_extension String?
imageUrl String @default("")
sortOrder Int? @default(0)
isActive Boolean @default(true)
temperatureZone DepartmentTemperatureZoneType? @default(ambient)
requiredLicenses Json @default("[]")
store Store @relation("Department_store", fields: [storeId], references: [id])
storeId String @map("store")
manager User? @relation("Department_manager", fields: [managerId], references: [id])
managerId String? @map("manager")
products Product[] @relation("Product_departmentRef")
createdAt DateTime @default(now())
updatedAt DateTime @default(now()) @updatedAt
@@index([storeId])
@@index([managerId])
}
model DeliveryRoute {
id String @id @default(cuid())
date DateTime
timeWindow DeliveryRouteTimeWindowType
stops Json?
status DeliveryRouteStatusType? @default(planning)
startedAt DateTime?
completedAt DateTime?
store Store @relation("DeliveryRoute_store", fields: [storeId], references: [id])
storeId String @map("store")
driver User? @relation("DeliveryRoute_driver", fields: [driverId], references: [id])
driverId String? @map("driver")
orders Order[] @relation("Order_deliveryRoute")
createdAt DateTime @default(now())
updatedAt DateTime @default(now()) @updatedAt
@@index([storeId])
@@index([driverId])
}
model DeliverySlot {
id String @id @default(cuid())
store Store @relation("DeliverySlot_store", fields: [storeId], references: [id])
storeId String @map("store")
orders Order[] @relation("Order_deliverySlot")
date DateTime
startTime String @default("")
endTime String @default("")
capacity Int @default(10)
currentBookings Int? @default(0)
isActive Boolean @default(true)
deliveryFee Int? @default(0)
createdAt DateTime @default(now())
updatedAt DateTime @default(now()) @updatedAt
@@index([storeId])
@@index([date])
}
model FavoriteProduct {
id String @id @default(cuid())
user User @relation("FavoriteProduct_user", fields: [userId], references: [id])
userId String @map("user")
product String @default("")
productRef Product? @relation("FavoriteProduct_productRef", fields: [productRefId], references: [id])
productRefId String? @map("productRef")
favoritedAt DateTime @default(now())
createdAt DateTime @default(now())
updatedAt DateTime @default(now()) @updatedAt
@@index([userId])
@@index([product])
@@index([productRefId])
}
model GroceryOutboxEvent {
id String @id @default(cuid())
store Store @relation("GroceryOutboxEvent_store", fields: [storeId], references: [id])
storeId String @map("store")
eventKey String @unique @default("")
eventType String @default("")
aggregateType String @default("")
aggregateId String @default("")
schemaVersion Int @default(1)
payload Json?
payloadHash String @default("")
occurredAt DateTime
status String @default("pending")
attempts Int? @default(0)
claimToken String @default("")
claimedAt DateTime?
deliveredAt DateTime?
nextAttemptAt DateTime?
lastError String @default("")
createdAt DateTime @default(now())
updatedAt DateTime @default(now()) @updatedAt
@@index([storeId])
@@index([aggregateId])
@@index([occurredAt])
@@index([status])
}
model InventoryLot {
id String @id @default(cuid())
lotNumber String @unique @default("")
supplierLotNumber String @default("")
safetyStatus String @default("available")
conditionStatus String @default("accepted")
safetyReason String @default("")
expirationDate DateTime
receivedDate DateTime @default(now())
quantity Decimal @postgresql.Decimal(18, 3)
quantityRemaining Decimal @postgresql.Decimal(18, 3)
costPerUnit Float
costPerUnitCents Int @default(0)
location String @default("")
store Store @relation("InventoryLot_store", fields: [storeId], references: [id])
storeId String @map("store")
product Product? @relation("InventoryLot_product", fields: [productId], references: [id])
productId String? @map("product")
supplier Supplier? @relation("InventoryLot_supplier", fields: [supplierId], references: [id])
supplierId String? @map("supplier")
orderLineAllocations OrderLineInventoryAllocation[] @relation("OrderLineInventoryAllocation_inventoryLot")
createdAt DateTime @default(now())
updatedAt DateTime @default(now()) @updatedAt
from_InventoryConversion_sourceInventoryLot InventoryConversion[] @relation("InventoryConversion_sourceInventoryLot")
from_PurchaseReceipt_inventoryLot PurchaseReceipt[] @relation("PurchaseReceipt_inventoryLot")
from_InventoryCount_inventoryLot InventoryCount[] @relation("InventoryCount_inventoryLot")
from_InventoryMovement_inventoryLot InventoryMovement[] @relation("InventoryMovement_inventoryLot")
from_InventoryAdjustment_inventoryLot InventoryAdjustment[] @relation("InventoryAdjustment_inventoryLot")
from_OrderLineItem_inventoryLot OrderLineItem[] @relation("OrderLineItem_inventoryLot")
@@index([supplierLotNumber])
@@index([storeId])
@@index([productId])
@@index([supplierId])
}
model InventoryAdjustment {
id String @id @default(cuid())
idempotencyKey String @unique @default("")
reason InventoryAdjustmentReasonType
quantityBefore Decimal @postgresql.Decimal(18, 3)
quantityAfter Decimal @postgresql.Decimal(18, 3)
quantityDelta Decimal @postgresql.Decimal(18, 3)
productStockBefore Decimal @postgresql.Decimal(18, 3)
productStockAfter Decimal @postgresql.Decimal(18, 3)
note String @default("")
store Store @relation("InventoryAdjustment_store", fields: [storeId], references: [id])
storeId String @map("store")
product Product? @relation("InventoryAdjustment_product", fields: [productId], references: [id])
productId String? @map("product")
inventoryLot InventoryLot? @relation("InventoryAdjustment_inventoryLot", fields: [inventoryLotId], references: [id])
inventoryLotId String? @map("inventoryLot")
adjustedBy User? @relation("InventoryAdjustment_adjustedBy", fields: [adjustedById], references: [id])
adjustedById String? @map("adjustedBy")
createdAt DateTime @default(now())
updatedAt DateTime @default(now()) @updatedAt
@@index([storeId])
@@index([productId])
@@index([inventoryLotId])
@@index([adjustedById])
}
model LoyaltyProgram {
id String @id @default(cuid())
earnPointsPer100Cents Int @default(1)
redeemPointsPer100Cents Int @default(100)
minimumRedemptionPoints Int @default(100)
refundDebtPolicy String @default("offset_future_earnings")
store Store @relation("LoyaltyProgram_store", fields: [storeId], references: [id])
storeId String @map("store")
name String @default("")
pointsPerDollar Float @default(1)
tierConfiguration Json?
redemptionRules Json?
expirationRules Json?
tierBenefits Json?
isActive Boolean @default(true)
createdAt DateTime @default(now())
updatedAt DateTime @default(now()) @updatedAt
from_LoyaltyRedemption_program LoyaltyRedemption[] @relation("LoyaltyRedemption_program")
from_LoyaltyTransaction_program LoyaltyTransaction[] @relation("LoyaltyTransaction_program")
@@index([storeId])
}
model LoyaltyTransaction {
id String @id @default(cuid())
idempotencyKey String @unique @default("")
store Store? @relation("LoyaltyTransaction_store", fields: [storeId], references: [id])
storeId String? @map("store")
program LoyaltyProgram? @relation("LoyaltyTransaction_program", fields: [programId], references: [id])
programId String? @map("program")
sourceId String @default("")
sourceType String @default("")
actorId String @default("")
balanceBefore Int?
metadata Json?
user User? @relation("LoyaltyTransaction_user", fields: [userId], references: [id])
userId String? @map("user")
points Int
type LoyaltyTransactionTypeType
description String @default("")
order Order? @relation("LoyaltyTransaction_order", fields: [orderId], references: [id])
orderId String? @map("order")
balanceAfter Int
transactionDate DateTime @default(now())
expiresAt DateTime?
createdAt DateTime @default(now())
updatedAt DateTime @default(now()) @updatedAt
@@index([storeId])
@@index([programId])
@@index([userId])
@@index([orderId])
}
model NotificationPreference {
id String @id @default(cuid())
user User @relation("NotificationPreference_user", fields: [userId], references: [id])
userId String @map("user")
orderUpdates Boolean @default(true)
deliveryAlerts Boolean @default(true)
priceDrops Boolean @default(false)
backInStock Boolean @default(false)
weeklyDeals Boolean @default(false)
channels Json? @default("[\"email\"]")
createdAt DateTime @default(now())
updatedAt DateTime @default(now()) @updatedAt
@@index([userId])
}