I’m developing an e-commerce site for digital goods using Prisma ORM with MongoDB. I’ve set up my schema but I’m not sure about some relationships. Here’s what I’ve got so far:
model Customer {
id String @id @default(auto()) @map("_id") @db.ObjectId
name String
email String @unique
pass String
basket Basket?
purchases Purchase[]
logins Login[]
}
model Basket {
id String @id @default(auto()) @map("_id") @db.ObjectId
items BasketItem[]
customerId String @unique @db.ObjectId
customer Customer @relation(fields: [customerId], references: [id], onDelete: Cascade)
}
model BasketItem {
id String @id @default(auto()) @map("_id") @db.ObjectId
productId String @db.ObjectId
amount Int
basketId String @db.ObjectId
basket Basket @relation(fields: [basketId], references: [id], onDelete: Cascade)
}
model Purchase {
id String @id @default(auto()) @map("_id") @db.ObjectId
state PurchaseState
cost Float
items PurchaseItem[]
customerId String @db.ObjectId
customer Customer @relation(fields: [customerId], references: [id], onDelete: Cascade)
}
enum PurchaseState {
WAITING
VOIDED
FINISHED
}
model PurchaseItem {
id String @id @default(auto()) @map("_id") @db.ObjectId
productId String @db.ObjectId
amount Int
purchaseId String @db.ObjectId
purchase Purchase @relation(fields: [purchaseId], references: [id], onDelete: Cascade)
}
model DigitalProduct {
id String @id @default(auto()) @map("_id") @db.ObjectId
title String
link String
info String
cost Float
}
Do I need to link BasketItem and PurchaseItem directly to DigitalProduct? Any tips to improve this setup? Thanks!