datasource db { provider = "mysql" url = env("DATABASE_URL") } generator client { provider = "prisma-client-js" binaryTargets = ["native", "debian-openssl-3.0.x", "debian-openssl-1.1.x"] } model User { id Int @id @default(autoincrement()) username String @unique password String name String? mobile String? roles Json? // e.g. ["COUNTER", "ACCOUNTANT", "SUPERVISOR", "ADMIN"] orgId Int? avatarUrl String? @db.LongText challenge String? @db.Text countings Counting[] authenticators Authenticator[] lockedLocations Location[] @relation("LocationLocks") assignedTasks Task[] @relation("AssignedTasks") createdTasks Task[] @relation("CreatedTasks") actionLogs ActionLog[] // Logs created by this user createdAt DateTime @default(now()) updatedAt DateTime @updatedAt } model Authenticator { id String @id @default(cuid()) credentialID String @unique credentialPublicKey Bytes counter BigInt credentialDeviceType String credentialBackedUp Boolean transports String? userId Int user User @relation(fields: [userId], references: [id], onDelete: Cascade) } model Location { id Int @id @default(autoincrement()) code String @unique floor String region Int sector String row Int warehouse Int? countings Counting[] isLocked Boolean @default(false) lockedById Int? lockedBy User? @relation("LocationLocks", fields: [lockedById], references: [id]) lockedAt DateTime? createdAt DateTime @default(now()) } model Counting { id Int @id @default(autoincrement()) product_id Int product_name String warehouse Int shelfCode String? location Location? @relation(fields: [shelfCode], references: [code]) old_count Int new_count Int user_id Int user User @relation(fields: [user_id], references: [id]) mode String @default("SHELF") // SHELF, ITEM, TASK status String @default("PENDING") // PENDING, APPROVED, REJECTED, CORRECTION_REQUESTED, CANCELLED correctionNote String? @db.Text cancelReason String? @db.Text is_offline Boolean @default(false) createdAt DateTime @default(now()) updatedAt DateTime @updatedAt } model SystemSetting { id Int @id @default(autoincrement()) key String @unique value String @db.Text updatedAt DateTime @updatedAt } model Task { id Int @id @default(autoincrement()) type String // RECOUNT, SUGGESTED_SHELF, SUGGESTED_ITEM targetId String // shelfCode or product_id targetName String? // for UI display status String @default("OPEN") // OPEN, IN_PROGRESS, COMPLETED assignedTo Int? user User? @relation("AssignedTasks", fields: [assignedTo], references: [id]) createdBy Int creator User @relation("CreatedTasks", fields: [createdBy], references: [id]) createdAt DateTime @default(now()) updatedAt DateTime @updatedAt } model ActionLog { id Int @id @default(autoincrement()) userId Int user User @relation(fields: [userId], references: [id]) action String // e.g., "LOGIN", "START_SHELF", "CANCEL_SHELF", "COUNT_ITEM" details String? @db.Text createdAt DateTime @default(now()) }