new commit

This commit is contained in:
54CHA
2025-07-19 17:56:06 +03:00
commit 4153e2c00a
140 changed files with 66097 additions and 0 deletions

View File

@ -0,0 +1,61 @@
-- CreateTable
CREATE TABLE "SearchQuery" (
"id" SERIAL NOT NULL,
"query" TEXT NOT NULL,
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updatedAt" TIMESTAMP(3) NOT NULL,
CONSTRAINT "SearchQuery_pkey" PRIMARY KEY ("id")
);
-- CreateTable
CREATE TABLE "Product" (
"id" SERIAL NOT NULL,
"article" TEXT NOT NULL,
"title" TEXT,
"price" DOUBLE PRECISION,
"imageUrl" TEXT,
"isCompetitor" BOOLEAN NOT NULL DEFAULT false,
"searchQueryId" INTEGER NOT NULL,
CONSTRAINT "Product_pkey" PRIMARY KEY ("id")
);
-- CreateTable
CREATE TABLE "Position" (
"id" SERIAL NOT NULL,
"city" TEXT NOT NULL,
"position" INTEGER NOT NULL,
"page" INTEGER NOT NULL,
"productId" INTEGER NOT NULL,
"searchQueryId" INTEGER NOT NULL,
CONSTRAINT "Position_pkey" PRIMARY KEY ("id")
);
-- CreateIndex
CREATE UNIQUE INDEX "Product_article_key" ON "Product"("article");
-- CreateIndex
CREATE INDEX "Product_article_idx" ON "Product"("article");
-- CreateIndex
CREATE INDEX "Product_searchQueryId_idx" ON "Product"("searchQueryId");
-- CreateIndex
CREATE INDEX "Position_productId_idx" ON "Position"("productId");
-- CreateIndex
CREATE INDEX "Position_searchQueryId_idx" ON "Position"("searchQueryId");
-- CreateIndex
CREATE INDEX "Position_city_idx" ON "Position"("city");
-- AddForeignKey
ALTER TABLE "Product" ADD CONSTRAINT "Product_searchQueryId_fkey" FOREIGN KEY ("searchQueryId") REFERENCES "SearchQuery"("id") ON DELETE CASCADE ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "Position" ADD CONSTRAINT "Position_productId_fkey" FOREIGN KEY ("productId") REFERENCES "Product"("id") ON DELETE CASCADE ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "Position" ADD CONSTRAINT "Position_searchQueryId_fkey" FOREIGN KEY ("searchQueryId") REFERENCES "SearchQuery"("id") ON DELETE CASCADE ON UPDATE CASCADE;

View File

@ -0,0 +1,3 @@
# Please do not edit this file manually
# It should be added in your version-control system (i.e. Git)
provider = "postgresql"

61
prisma/schema.prisma Normal file
View File

@ -0,0 +1,61 @@
// This is your Prisma schema file,
// learn more about it in the docs: https://pris.ly/d/prisma-schema
// Looking for ways to speed up your queries, or scale easily with your serverless or edge functions?
// Try Prisma Accelerate: https://pris.ly/cli/accelerate-init
generator client {
provider = "prisma-client-js"
output = "../src/generated/prisma"
}
datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
}
model SearchQuery {
id Int @id @default(autoincrement())
query String
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
// Связь с товарами
products Product[]
// Связь с позициями
positions Position[]
}
model Product {
id Int @id @default(autoincrement())
article String @unique
title String?
price Float?
imageUrl String?
isCompetitor Boolean @default(false)
searchQueryId Int
searchQuery SearchQuery @relation(fields: [searchQueryId], references: [id], onDelete: Cascade)
// Связь с позициями
positions Position[]
@@index([article])
@@index([searchQueryId])
}
model Position {
id Int @id @default(autoincrement())
city String
position Int // Позиция товара в выдаче
page Int // Страница, на которой найден товар
productId Int
searchQueryId Int
// Связи
product Product @relation(fields: [productId], references: [id], onDelete: Cascade)
searchQuery SearchQuery @relation(fields: [searchQueryId], references: [id], onDelete: Cascade)
@@index([productId])
@@index([searchQueryId])
@@index([city])
}