Stage M8
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
-- NOTE: Prisma's diff wanted to DROP INDEX "search_documents_document_idx" and
|
||||
-- ALTER "search_documents"."document" DROP DEFAULT here. Removed on purpose —
|
||||
-- see the M6 migration: `document` is a GENERATED tsvector column Prisma cannot
|
||||
-- express, so it proposes undoing it in every migration. Applying it destroys
|
||||
-- full-text search.
|
||||
|
||||
-- CreateTable
|
||||
CREATE TABLE "wishlist_items" (
|
||||
"customer_id" UUID NOT NULL,
|
||||
"product_id" UUID NOT NULL,
|
||||
"created_at" TIMESTAMPTZ(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
|
||||
CONSTRAINT "wishlist_items_pkey" PRIMARY KEY ("customer_id","product_id")
|
||||
);
|
||||
|
||||
-- CreateIndex
|
||||
CREATE INDEX "wishlist_items_customer_id_created_at_idx" ON "wishlist_items"("customer_id", "created_at");
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "wishlist_items" ADD CONSTRAINT "wishlist_items_customer_id_fkey" FOREIGN KEY ("customer_id") REFERENCES "customers"("id") ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "wishlist_items" ADD CONSTRAINT "wishlist_items_product_id_fkey" FOREIGN KEY ("product_id") REFERENCES "products"("id") ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
@@ -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")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user