This commit is contained in:
Nông Đức Huy
2026-08-13 23:20:23 +07:00
parent d9f159a8c3
commit cda5d21d0d
53 changed files with 2711 additions and 162 deletions
+26 -1
View File
@@ -210,9 +210,10 @@ model Customer {
createdAt DateTime @default(now()) @map("created_at") @db.Timestamptz(3)
updatedAt DateTime @updatedAt @map("updated_at") @db.Timestamptz(3)
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
addresses Address[]
orders Order[]
wishlist WishlistItem[]
@@map("customers")
}
@@ -525,6 +526,7 @@ model Product {
searchDocuments SearchDocument[]
reviews Review[]
wishlistedBy WishlistItem[]
discounts DiscountProduct[]
brand Brand? @relation(fields: [brandId], references: [id], onDelete: SetNull)
primaryCategory Category? @relation(fields: [primaryCategoryId], references: [id], onDelete: SetNull)
@@ -1346,3 +1348,26 @@ model ContentEntryTranslation {
@@unique([locale, slug])
@@map("content_entry_translations")
}
/// One saved product, per customer.
///
/// Deliberately keyed on the *product*, not a variant. A shopper saving a
/// jacket is saying "this one, later" — not "this one in black, size M". Saving
/// a variant would mean a wishlist entry silently dies when a colourway is
/// discontinued, and would make the same jacket appear five times.
model WishlistItem {
customerId String @map("customer_id") @db.Uuid
productId String @map("product_id") @db.Uuid
createdAt DateTime @default(now()) @map("created_at") @db.Timestamptz(3)
customer Customer @relation(fields: [customerId], references: [id], onDelete: Cascade)
product Product @relation(fields: [productId], references: [id], onDelete: Cascade)
/// The composite key IS the uniqueness rule: adding a product twice is a
/// no-op upsert rather than a duplicate row or an error the client must
/// handle. Double-tapping a heart icon is not a failure.
@@id([customerId, productId])
@@index([customerId, createdAt])
@@map("wishlist_items")
}