init project

This commit is contained in:
@kirill.komarov
2026-04-28 11:02:08 +05:00
commit 55480d4aa5
50 changed files with 9241 additions and 0 deletions
@@ -0,0 +1,28 @@
-- CreateTable
CREATE TABLE "Category" (
"id" TEXT NOT NULL PRIMARY KEY,
"name" TEXT NOT NULL,
"slug" TEXT NOT NULL,
"sort" INTEGER NOT NULL DEFAULT 0
);
-- CreateTable
CREATE TABLE "Product" (
"id" TEXT NOT NULL PRIMARY KEY,
"title" TEXT NOT NULL,
"slug" TEXT NOT NULL,
"description" TEXT,
"priceCents" INTEGER NOT NULL,
"imageUrl" TEXT,
"published" BOOLEAN NOT NULL DEFAULT false,
"categoryId" TEXT NOT NULL,
"createdAt" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updatedAt" DATETIME NOT NULL,
CONSTRAINT "Product_categoryId_fkey" FOREIGN KEY ("categoryId") REFERENCES "Category" ("id") ON DELETE CASCADE ON UPDATE CASCADE
);
-- CreateIndex
CREATE UNIQUE INDEX "Category_slug_key" ON "Category"("slug");
-- CreateIndex
CREATE UNIQUE INDEX "Product_slug_key" ON "Product"("slug");
@@ -0,0 +1,3 @@
# Please do not edit this file manually
# It should be added in your version-control system (i.e. Git)
provider = "sqlite"
+32
View File
@@ -0,0 +1,32 @@
generator client {
provider = "prisma-client-js"
}
datasource db {
provider = "sqlite"
url = env("DATABASE_URL")
}
/// Категория изделий (игрушки, сувениры и т.д.)
model Category {
id String @id @default(cuid())
name String
slug String @unique
sort Int @default(0)
products Product[]
}
model Product {
id String @id @default(cuid())
title String
slug String @unique
description String?
/// Цена в копейках (целое число, без дробной части)
priceCents Int
imageUrl String?
published Boolean @default(false)
category Category @relation(fields: [categoryId], references: [id], onDelete: Cascade)
categoryId String
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
}
+57
View File
@@ -0,0 +1,57 @@
import { PrismaClient } from '@prisma/client'
const prisma = new PrismaClient()
async function main() {
const toys = await prisma.category.upsert({
where: { slug: 'igrushki' },
update: {},
create: { name: 'Игрушки', slug: 'igrushki', sort: 1 },
})
const gifts = await prisma.category.upsert({
where: { slug: 'suveniry' },
update: {},
create: { name: 'Сувениры', slug: 'suveniry', sort: 2 },
})
await prisma.product.upsert({
where: { slug: 'myagkaya-sova' },
update: {},
create: {
title: 'Мягкая сова',
slug: 'myagkaya-sova',
description: 'Ручная работа, хлопок и синтепон.',
priceCents: 189000,
imageUrl:
'https://images.unsplash.com/photo-1558618666-fcd25c85cd64?w=600&q=80',
published: true,
categoryId: toys.id,
},
})
await prisma.product.upsert({
where: { slug: 'suvenir-kolokolchik' },
update: {},
create: {
title: 'Колокольчик керамический',
slug: 'suvenir-kolokolchik',
description: 'Глазурь, ручная роспись.',
priceCents: 45000,
imageUrl:
'https://images.unsplash.com/photo-1513519245088-0e12902e5a38?w=600&q=80',
published: true,
categoryId: gifts.id,
},
})
console.log('Seed готов:', { toys: toys.slug, gifts: gifts.slug })
}
main()
.catch((e) => {
console.error(e)
process.exit(1)
})
.finally(async () => {
await prisma.$disconnect()
})