232 lines
6.4 KiB
Plaintext
232 lines
6.4 KiB
Plaintext
// HMarket Veritabanı Şeması
|
||
// MySQL için Prisma ORM konfigürasyonu
|
||
|
||
generator client {
|
||
provider = "prisma-client-js"
|
||
}
|
||
|
||
datasource db {
|
||
provider = "mysql"
|
||
url = env("DATABASE_URL")
|
||
}
|
||
|
||
// Kullanıcı modeli
|
||
model User {
|
||
id String @id @default(cuid())
|
||
email String @unique
|
||
username String @unique
|
||
firstName String
|
||
lastName String
|
||
password String? // OAuth kullanıcıları için opsiyonel
|
||
avatar String?
|
||
googleId String? @unique // Google OAuth ID
|
||
authProvider String @default("local") // "local", "google"
|
||
isActive Boolean @default(true)
|
||
isAdmin Boolean @default(false)
|
||
createdAt DateTime @default(now())
|
||
updatedAt DateTime @updatedAt
|
||
lastLoginAt DateTime?
|
||
|
||
// İlişkiler
|
||
ownedLists ShoppingList[] @relation("ListOwner")
|
||
sharedLists ListMember[]
|
||
notifications Notification[]
|
||
deviceTokens DeviceToken[]
|
||
activities Activity[]
|
||
|
||
@@map("users")
|
||
}
|
||
|
||
// Cihaz token'ları (Push notification için)
|
||
model DeviceToken {
|
||
id String @id @default(cuid())
|
||
userId String
|
||
token String @unique
|
||
platform String // "ios", "android", "web"
|
||
isActive Boolean @default(true)
|
||
createdAt DateTime @default(now())
|
||
updatedAt DateTime @updatedAt
|
||
|
||
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
|
||
|
||
@@map("device_tokens")
|
||
}
|
||
|
||
// Alışveriş listesi modeli
|
||
model ShoppingList {
|
||
id String @id @default(cuid())
|
||
name String
|
||
description String?
|
||
color String @default("#2196F3") // Hex renk kodu
|
||
isActive Boolean @default(true)
|
||
ownerId String
|
||
createdAt DateTime @default(now())
|
||
updatedAt DateTime @updatedAt
|
||
|
||
// İlişkiler
|
||
owner User @relation("ListOwner", fields: [ownerId], references: [id], onDelete: Cascade)
|
||
members ListMember[]
|
||
items ListItem[]
|
||
activities Activity[]
|
||
invitations ListInvitation[]
|
||
|
||
@@map("shopping_lists")
|
||
}
|
||
|
||
// Liste üyeleri (çoklu kullanıcı desteği)
|
||
model ListMember {
|
||
id String @id @default(cuid())
|
||
listId String
|
||
userId String
|
||
role String @default("member") // "admin", "member", "viewer"
|
||
joinedAt DateTime @default(now())
|
||
|
||
// İlişkiler
|
||
list ShoppingList @relation(fields: [listId], references: [id], onDelete: Cascade)
|
||
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
|
||
|
||
@@unique([listId, userId])
|
||
@@map("list_members")
|
||
}
|
||
|
||
// Liste davetleri
|
||
model ListInvitation {
|
||
id String @id @default(cuid())
|
||
listId String
|
||
email String
|
||
role String @default("member")
|
||
token String @unique
|
||
isUsed Boolean @default(false)
|
||
expiresAt DateTime
|
||
createdAt DateTime @default(now())
|
||
|
||
list ShoppingList @relation(fields: [listId], references: [id], onDelete: Cascade)
|
||
|
||
@@map("list_invitations")
|
||
}
|
||
|
||
// Ürün kategorileri
|
||
model Category {
|
||
id String @id @default(cuid())
|
||
name String @unique
|
||
description String?
|
||
icon String? // Icon adı veya URL
|
||
color String @default("#757575")
|
||
sortOrder Int @default(0)
|
||
isActive Boolean @default(true)
|
||
createdAt DateTime @default(now())
|
||
updatedAt DateTime @updatedAt
|
||
|
||
// İlişkiler
|
||
products Product[]
|
||
|
||
@@map("categories")
|
||
}
|
||
|
||
// Ürün modeli
|
||
model Product {
|
||
id String @id @default(cuid())
|
||
name String
|
||
description String?
|
||
barcode String? @unique
|
||
brand String?
|
||
unit String? // Ürün varsayılan birimi
|
||
categoryId String?
|
||
image String?
|
||
isActive Boolean @default(true)
|
||
createdAt DateTime @default(now())
|
||
updatedAt DateTime @updatedAt
|
||
|
||
// İlişkiler
|
||
category Category? @relation(fields: [categoryId], references: [id], onDelete: SetNull)
|
||
listItems ListItem[]
|
||
priceHistory PriceHistory[]
|
||
|
||
@@map("products")
|
||
}
|
||
|
||
// Liste öğeleri
|
||
model ListItem {
|
||
id String @id @default(cuid())
|
||
listId String
|
||
productId String?
|
||
customName String? // Ürün yoksa manuel isim
|
||
quantity Float @default(1)
|
||
unit String @default("adet") // "kg", "lt", "adet", vb.
|
||
price Decimal? // SQLite: Decimal stored as String
|
||
note String?
|
||
isPurchased Boolean @default(false)
|
||
purchasedAt DateTime?
|
||
purchasedBy String?
|
||
priority Int @default(0) // 0: normal, 1: önemli, 2: acil
|
||
sortOrder Int @default(0)
|
||
createdAt DateTime @default(now())
|
||
updatedAt DateTime @updatedAt
|
||
|
||
// İlişkiler
|
||
list ShoppingList @relation(fields: [listId], references: [id], onDelete: Cascade)
|
||
product Product? @relation(fields: [productId], references: [id], onDelete: SetNull)
|
||
|
||
@@map("list_items")
|
||
}
|
||
|
||
// Fiyat geçmişi
|
||
model PriceHistory {
|
||
id String @id @default(cuid())
|
||
productId String
|
||
price Decimal // SQLite: Decimal stored as String
|
||
store String? // Mağaza adı
|
||
location String? // Konum bilgisi
|
||
source String @default("user") // "user", "api", "scraping"
|
||
createdAt DateTime @default(now())
|
||
|
||
// İlişkiler
|
||
product Product @relation(fields: [productId], references: [id], onDelete: Cascade)
|
||
|
||
@@map("price_history")
|
||
}
|
||
|
||
// Bildirimler
|
||
model Notification {
|
||
id String @id @default(cuid())
|
||
userId String
|
||
title String
|
||
message String
|
||
type String // "list_shared", "item_added", "item_purchased", "price_alert"
|
||
data String? // Ek veri (JSON format - SQLite String olarak saklanır)
|
||
isRead Boolean @default(false)
|
||
createdAt DateTime @default(now())
|
||
|
||
// İlişkiler
|
||
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
|
||
|
||
@@map("notifications")
|
||
}
|
||
|
||
// Aktivite logu (gerçek zamanlı güncellemeler için)
|
||
model Activity {
|
||
id String @id @default(cuid())
|
||
listId String
|
||
userId String
|
||
action String // "item_added", "item_removed", "item_updated", "item_purchased"
|
||
details String? // Aktivite detayları (JSON - SQLite String olarak saklanır)
|
||
createdAt DateTime @default(now())
|
||
|
||
// İlişkiler
|
||
list ShoppingList @relation(fields: [listId], references: [id], onDelete: Cascade)
|
||
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
|
||
|
||
@@map("activities")
|
||
}
|
||
|
||
// Sistem ayarları
|
||
model Setting {
|
||
id String @id @default(cuid())
|
||
key String @unique
|
||
value String
|
||
type String @default("string") // "string", "number", "boolean", "json"
|
||
createdAt DateTime @default(now())
|
||
updatedAt DateTime @updatedAt
|
||
|
||
@@map("settings")
|
||
} |