-- CreateTable
CREATE TABLE "public"."products" (
    "ItemID" BIGINT NOT NULL,
    "ShopID" BIGINT,
    "ModelID" BIGINT,
    "Name" VARCHAR(255),
    "ShopName" VARCHAR(255),
    "Price" DECIMAL(10,2),
    "Sold" INTEGER,
    "Rating" DOUBLE PRECISION,
    "RatingCount" INTEGER,
    "LikedCount" INTEGER,
    "ShopLocation" VARCHAR(100),
    "Brand" VARCHAR(100),
    "Variations" JSONB,
    "ProductLink" TEXT,
    "document_tsvector" tsvector,

    CONSTRAINT "products_pkey" PRIMARY KEY ("ItemID")
);

-- CreateTable
CREATE TABLE "public"."product_images" (
    "ImageID" SERIAL NOT NULL,
    "ItemID" BIGINT NOT NULL,
    "ImageURL" TEXT,

    CONSTRAINT "product_images_pkey" PRIMARY KEY ("ImageID")
);

-- CreateTable
CREATE TABLE "public"."reviews" (
    "ReviewID" SERIAL NOT NULL,
    "ItemID" BIGINT NOT NULL,
    "ReviewerName" VARCHAR(255),
    "Rating" INTEGER,
    "ReviewText" TEXT,
    "ReviewDate" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "ImageURL" TEXT,

    CONSTRAINT "reviews_pkey" PRIMARY KEY ("ReviewID")
);

-- AddForeignKey
ALTER TABLE "public"."product_images" ADD CONSTRAINT "product_images_ItemID_fkey" FOREIGN KEY ("ItemID") REFERENCES "public"."products"("ItemID") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "public"."reviews" ADD CONSTRAINT "reviews_ItemID_fkey" FOREIGN KEY ("ItemID") REFERENCES "public"."products"("ItemID") ON DELETE CASCADE ON UPDATE CASCADE;
