Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
Warnings:

- You are about to drop the column `price` on the `products` table. All the data in the column will be lost.

*/
-- AlterTable
ALTER TABLE "products" DROP COLUMN "price";

-- CreateTable
CREATE TABLE "variants_attributes" (
"id" SERIAL NOT NULL,
"name" TEXT NOT NULL,
"created_at" TIMESTAMP(0) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updated_at" TIMESTAMP(0) NOT NULL DEFAULT CURRENT_TIMESTAMP,

CONSTRAINT "variants_attributes_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "variants_attributes_values" (
"id" SERIAL NOT NULL,
"attribute_id" INTEGER NOT NULL,
"product_id" INTEGER NOT NULL,
"value" TEXT NOT NULL,
"price" DECIMAL(10,2) NOT NULL,
"created_at" TIMESTAMP(0) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updated_at" TIMESTAMP(0) NOT NULL DEFAULT CURRENT_TIMESTAMP,

CONSTRAINT "variants_attributes_values_pkey" PRIMARY KEY ("id")
);

-- CreateIndex
CREATE UNIQUE INDEX "variants_attributes_name_key" ON "variants_attributes"("name");

-- CreateIndex
CREATE UNIQUE INDEX "variants_attributes_values_attribute_id_product_id_value_key" ON "variants_attributes_values"("attribute_id", "product_id", "value");

-- AddForeignKey
ALTER TABLE "variants_attributes_values" ADD CONSTRAINT "variants_attributes_values_attribute_id_fkey" FOREIGN KEY ("attribute_id") REFERENCES "variants_attributes"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "variants_attributes_values" ADD CONSTRAINT "variants_attributes_values_product_id_fkey" FOREIGN KEY ("product_id") REFERENCES "products"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
35 changes: 31 additions & 4 deletions prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -55,21 +55,48 @@ model Product {
title String
imgSrc String @map("img_src")
alt String?
price Decimal @db.Decimal(10, 2)
description String?
categoryId Int? @map("category_id")
isOnSale Boolean @default(false) @map("is_on_sale")
features String[]
createdAt DateTime @default(now()) @map("created_at") @db.Timestamp(0)
updatedAt DateTime @default(now()) @map("updated_at") @db.Timestamp(0)

category Category? @relation(fields: [categoryId], references: [id], onDelete: SetNull)
cartItems CartItem[]
orderItems OrderItem[]
category Category? @relation(fields: [categoryId], references: [id], onDelete: SetNull)
cartItems CartItem[]
orderItems OrderItem[]
variantAttributeValues VariantAttributeValue[]

@@map("products")
}

model VariantAttribute {
id Int @id @default(autoincrement())
name String @unique
createdAt DateTime @default(now()) @map("created_at") @db.Timestamp(0)
updatedAt DateTime @default(now()) @map("updated_at") @db.Timestamp(0)

variantsAttributeValue VariantAttributeValue[]

@@map("variants_attributes")
}

model VariantAttributeValue {
id Int @id @default(autoincrement())
attributeId Int @map("attribute_id")
productId Int @map("product_id")
value String
price Decimal @db.Decimal(10, 2)
createdAt DateTime @default(now()) @map("created_at") @db.Timestamp(0)
updatedAt DateTime @default(now()) @map("updated_at") @db.Timestamp(0)

variantAttribute VariantAttribute @relation(fields: [attributeId], references: [id])
product Product @relation(fields: [productId], references: [id])

@@unique([attributeId, productId, value], name: "unique_attribute_product_value")
@@map("variants_attributes_values")
}

model Cart {
id Int @id @default(autoincrement())
sessionCartId String @unique @default(dbgenerated("gen_random_uuid()")) @map("session_cart_id") @db.Uuid
Expand Down