generator client { provider = "prisma-client" output = "../src/generated/prisma" } datasource db { provider = "postgresql" } enum UserRole { engineer admin } enum IngredientCategory { emulsifier humectant thickener preservative antioxidant fragrance colorant ph_adjuster sunscreen surfactant emollient other } model User { id String @id @default(uuid()) username String @unique passwordHash String @map("password_hash") role UserRole @default(engineer) createdAt DateTime @default(now()) @map("created_at") formulas Formula[] @relation("FormulaCreator") colorFormulas ColorFormula[] @relation("ColorFormulaCreator") formulaVersions FormulaVersion[] projects Project[] @@map("users") } model Project { id String @id @default(uuid()) name String description String? createdBy String @map("created_by") createdAt DateTime @default(now()) @map("created_at") creator User @relation(fields: [createdBy], references: [id]) formulas Formula[] @@map("projects") } model Formula { id String @id @default(uuid()) name String description String? projectId String? @map("project_id") currentVersion Int @default(1) @map("current_version") createdBy String @map("created_by") createdAt DateTime @default(now()) @map("created_at") updatedAt DateTime @updatedAt @map("updated_at") embedding Unsupported("vector(1536)")? project Project? @relation(fields: [projectId], references: [id]) creator User @relation("FormulaCreator", fields: [createdBy], references: [id]) versions FormulaVersion[] colorFormulas ColorFormula[] @@index([projectId]) @@index([createdBy]) @@map("formulas") } model FormulaVersion { id String @id @default(uuid()) formulaId String @map("formula_id") versionNumber Int @map("version_number") description String? snapshotData Json @map("snapshot_data") createdBy String @map("created_by") createdAt DateTime @default(now()) @map("created_at") formula Formula @relation(fields: [formulaId], references: [id]) creator User @relation(fields: [createdBy], references: [id]) phases Phase[] ingredients FormulaIngredient[] @@unique([formulaId, versionNumber]) @@index([formulaId]) @@map("formula_versions") } model Ingredient { id String @id @default(uuid()) inciName String @map("inci_name") chineseName String @map("chinese_name") functionCategory IngredientCategory @map("function_category") supplier String? unit String @default("kg") unitPrice Decimal? @map("unit_price") @db.Decimal(10, 2) description String? createdAt DateTime @default(now()) @map("created_at") formulaIngredients FormulaIngredient[] @@index([functionCategory]) @@map("ingredients") } model Phase { id String @id @default(uuid()) name String formulaId String @map("formula_id") sortOrder Int @default(0) @map("sort_order") formulaVersion FormulaVersion @relation(fields: [formulaId], references: [id]) ingredients FormulaIngredient[] @@index([formulaId]) @@map("phases") } model FormulaIngredient { id String @id @default(uuid()) formulaVersionId String @map("formula_version_id") phaseId String? @map("phase_id") ingredientId String @map("ingredient_id") percentage Decimal @db.Decimal(5, 2) processNotes String? @map("process_notes") formulaVersion FormulaVersion @relation(fields: [formulaVersionId], references: [id]) phase Phase? @relation(fields: [phaseId], references: [id]) ingredient Ingredient @relation(fields: [ingredientId], references: [id]) @@index([formulaVersionId]) @@index([ingredientId]) @@map("formula_ingredients") } model ColorFormula { id String @id @default(uuid()) name String targetLab Json @map("target_lab") actualLab Json? @map("actual_lab") deltaE Float? @map("delta_e") colorantComposition Json? @map("colorant_composition") formulaId String? @map("formula_id") createdBy String @map("created_by") createdAt DateTime @default(now()) @map("created_at") formula Formula? @relation(fields: [formulaId], references: [id]) creator User @relation("ColorFormulaCreator", fields: [createdBy], references: [id]) @@index([formulaId]) @@index([createdBy]) @@map("color_formulas") } model AiAuditLog { id String @id @default(uuid()) capability String modelName String @map("model_name") promptHash String @map("prompt_hash") tokensUsed Int? @map("tokens_used") durationMs Int? @map("duration_ms") createdAt DateTime @default(now()) @map("created_at") @@index([capability]) @@index([createdAt]) @@map("ai_audit_logs") }