PrismaPostgresIntermediate
TechShop — সম্পূর্ণ Prisma schema
নিজেদের প্রজেক্ট data-model — সব relation সহ।
3টি অংশবাংলা ভাষায়
prisma/schema.prismaprisma
prisma
enum Role {
customer
admin
}
model User {
id Int @id @default(autoincrement())
email String @unique
name String
role Role @default(customer)
orders Order[]
createdAt DateTime @default(now())
}
model Category {
id Int @id @default(autoincrement())
name String @unique
products Product[]
}
model Product {
id Int @id @default(autoincrement())
name String
price Decimal @db.Decimal(10, 2)
qty Int @default(0)
spec Json?
active Boolean @default(true)
category Category? @relation(fields: [categoryId], references: [id], onDelete: SetNull)
categoryId Int?
items OrderItem[]
}
model Order {
id Int @id @default(autoincrement())
total Decimal @default(0) @db.Decimal(10, 2)
status String @default("pending")
user User @relation(fields: [userId], references: [id])
userId Int
items OrderItem[]
createdAt DateTime @default(now())
}
model OrderItem {
order Order @relation(fields: [orderId], references: [id], onDelete: Cascade)
orderId Int
product Product @relation(fields: [productId], references: [id])
productId Int
qty Int
price Decimal @db.Decimal(10, 2)
@@id([orderId, productId])
}- enum → PostgreSQL-এ enum type
- @db.Decimal(10,2) — precision scale
- onDelete: SetNull / Cascade — FK behavior
- @@id([orderId, productId]) — composite key
migrate চালান
সংরক্ষিত schema → npx prisma migrate dev --name techshop_init — table তৈরি হয়ে যাবে।
শেষ প্যারায় নিজে practice করুন — কোড কপি করে নিজের এডিটরে চালিয়ে দেখুন।