Yaltopia-Tickets-Backend/prisma/schema.prisma
debudebuye 98d4bb52c3 Initial commit: Receipt Verification API with universal adapter pattern
- JWT authentication with Supabase integration
- Role-based access control (Admin, Owner, Staff, Auditor)
- Universal database adapter (Prisma/Supabase/MongoDB support)
- User management with hierarchical permissions
- Redis caching service (configured but optional)
- Comprehensive API documentation
- Production-ready NestJS architecture
- Migration scripts for provider switching
- Swagger/OpenAPI documentation
2025-12-21 22:05:22 +03:00

132 lines
3.5 KiB
Plaintext

generator client {
provider = "prisma-client-js"
}
datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
directUrl = env("DIRECT_URL")
}
enum UserRole {
SYSTEM_ADMIN
BUSINESS_OWNER
STAFF
AUDITOR
}
enum ReceiptStatus {
PENDING
VERIFIED
REJECTED
FAILED
}
enum PaymentMethod {
CASH
CARD
MOBILE
OTHER
}
model User {
id String @id @default(uuid())
telegramId String? @unique @map("telegram_id")
externalId String? @unique @map("external_id")
email String? @unique
username String?
role UserRole
passwordHash String? @map("password_hash")
isActive Boolean @default(true) @map("is_active")
// Relations
ownerId String? @map("owner_id")
owner User? @relation("OwnerStaff", fields: [ownerId], references: [id])
staff User[] @relation("OwnerStaff")
receipts Receipt[]
verifications Verification[]
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @updatedAt @map("updated_at")
@@map("users")
@@index([telegramId])
@@index([externalId])
@@index([role])
}
model Receipt {
id String @id @default(uuid())
userId String @map("user_id")
user User @relation(fields: [userId], references: [id])
// Receipt data
imageUrl String @map("image_url")
transactionId String? @map("transaction_id")
merchant String?
date DateTime?
amount Float?
paymentMethod PaymentMethod? @map("payment_method")
// OCR & Status
status ReceiptStatus @default(PENDING)
ocrProcessed Boolean @default(false) @map("ocr_processed")
ocrError String? @map("ocr_error")
ocrProcessingTime Int? @map("ocr_processing_time") // milliseconds
// Verification
isDuplicate Boolean @default(false) @map("is_duplicate")
fraudFlags String[] @default([]) @map("fraud_flags")
verifications Verification[]
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @updatedAt @map("updated_at")
@@map("receipts")
@@index([userId])
@@index([status])
@@index([transactionId])
@@index([createdAt])
}
model Verification {
id String @id @default(uuid())
receiptId String @map("receipt_id")
receipt Receipt @relation(fields: [receiptId], references: [id])
verifiedBy String @map("verified_by")
verifier User @relation(fields: [verifiedBy], references: [id])
status ReceiptStatus
notes String?
createdAt DateTime @default(now()) @map("created_at")
@@map("verifications")
@@index([receiptId])
@@index([verifiedBy])
}
model PerformanceMetric {
id String @id @default(uuid())
date DateTime @default(now())
// OCR Metrics
ocrProcessingTime Float? @map("ocr_processing_time") // average in ms
ocrFailureRate Float? @map("ocr_failure_rate") // percentage
// API Metrics
apiResponseTime Float? @map("api_response_time") // average in ms
apiRequestCount Int? @map("api_request_count")
// System Usage
dailyReceiptCount Int? @map("daily_receipt_count")
dailyUserCount Int? @map("daily_user_count")
createdAt DateTime @default(now()) @map("created_at")
@@map("performance_metrics")
@@index([date])
}