DuOrigin v2 - React + NestJS + Prisma + EUDR API Integration
This commit is contained in:
195
prisma/schema.prisma
Normal file
195
prisma/schema.prisma
Normal file
@@ -0,0 +1,195 @@
|
||||
// DuOrigin v2 - Prisma Schema
|
||||
// EUDR Compliance Platform for Brazilian Agribusiness
|
||||
// Generated from production PostgreSQL database (jarvis-do)
|
||||
|
||||
generator client {
|
||||
provider = "prisma-client-js"
|
||||
}
|
||||
|
||||
datasource db {
|
||||
provider = "postgresql"
|
||||
url = env("DATABASE_URL")
|
||||
}
|
||||
|
||||
// ============================================
|
||||
// Users & Authentication
|
||||
// ============================================
|
||||
|
||||
model User {
|
||||
id Int @id @default(autoincrement())
|
||||
email String @unique
|
||||
hashed_password String
|
||||
full_name String?
|
||||
role String? @default("operator") // admin, operator, viewer
|
||||
is_active Boolean? @default(true)
|
||||
created_at DateTime? @default(now())
|
||||
|
||||
// Relations
|
||||
auditLogs AuditLog[]
|
||||
|
||||
@@index([id])
|
||||
@@map("users")
|
||||
}
|
||||
|
||||
// ============================================
|
||||
// Companies (Empresas)
|
||||
// ============================================
|
||||
|
||||
model Company {
|
||||
id Int @id @default(autoincrement())
|
||||
name String
|
||||
cnpj String? @unique
|
||||
country String? @default("BR")
|
||||
state String?
|
||||
city String?
|
||||
eu_operator_id String? // EU Operator ID for EUDR
|
||||
created_at DateTime? @default(now())
|
||||
|
||||
// Relations
|
||||
producers Producer[]
|
||||
ddsStatements DdsStatement[]
|
||||
|
||||
@@index([id])
|
||||
@@index([cnpj])
|
||||
@@map("companies")
|
||||
}
|
||||
|
||||
// ============================================
|
||||
// Producers (Produtores Rurais)
|
||||
// ============================================
|
||||
|
||||
model Producer {
|
||||
id Int @id @default(autoincrement())
|
||||
name String
|
||||
cpf_cnpj String? @unique
|
||||
company_id Int?
|
||||
state String?
|
||||
city String?
|
||||
car_code String? // CAR - Cadastro Ambiental Rural
|
||||
created_at DateTime? @default(now())
|
||||
|
||||
// Relations
|
||||
company Company? @relation(fields: [company_id], references: [id])
|
||||
areas Area[]
|
||||
lots Lot[]
|
||||
|
||||
@@index([id])
|
||||
@@index([cpf_cnpj])
|
||||
@@map("producers")
|
||||
}
|
||||
|
||||
// ============================================
|
||||
// Areas (Propriedades Rurais / Glebas)
|
||||
// ============================================
|
||||
|
||||
model Area {
|
||||
id Int @id @default(autoincrement())
|
||||
name String
|
||||
producer_id Int?
|
||||
geojson String? @db.Text // GeoJSON polygon
|
||||
area_ha Float? // Area in hectares
|
||||
biome String? // Cerrado, Amazônia, Mata Atlântica, etc.
|
||||
risk_level String? // low, medium, high, critical
|
||||
deforestation_flag String? // none, alert, confirmed
|
||||
lat_center Float? // Latitude center point
|
||||
lon_center Float? // Longitude center point
|
||||
created_at DateTime? @default(now())
|
||||
|
||||
// Relations
|
||||
producer Producer? @relation(fields: [producer_id], references: [id])
|
||||
lots Lot[]
|
||||
|
||||
@@index([id])
|
||||
@@map("areas")
|
||||
}
|
||||
|
||||
// ============================================
|
||||
// Products (Commodities EUDR)
|
||||
// ============================================
|
||||
|
||||
model Product {
|
||||
id Int @id @default(autoincrement())
|
||||
name String
|
||||
hs_code String? // Harmonized System code
|
||||
eudr_category String? // cattle, cocoa, coffee, oil palm, rubber, soya, wood
|
||||
description String?
|
||||
created_at DateTime? @default(now())
|
||||
|
||||
// Relations
|
||||
lots Lot[]
|
||||
|
||||
@@index([id])
|
||||
@@map("products")
|
||||
}
|
||||
|
||||
// ============================================
|
||||
// Lots (Lotes de Produto)
|
||||
// ============================================
|
||||
|
||||
model Lot {
|
||||
id Int @id @default(autoincrement())
|
||||
reference String @unique
|
||||
product_id Int?
|
||||
area_id Int?
|
||||
producer_id Int?
|
||||
quantity_kg Float?
|
||||
harvest_date String?
|
||||
risk_score Float? // 0-100 risk score
|
||||
status String? @default("pending") // pending, approved, rejected, review
|
||||
created_at DateTime? @default(now())
|
||||
|
||||
// Relations
|
||||
product Product? @relation(fields: [product_id], references: [id])
|
||||
area Area? @relation(fields: [area_id], references: [id])
|
||||
producer Producer? @relation(fields: [producer_id], references: [id])
|
||||
|
||||
@@index([id])
|
||||
@@index([reference])
|
||||
@@map("lots")
|
||||
}
|
||||
|
||||
// ============================================
|
||||
// DDS Statements (Due Diligence Statements)
|
||||
// ============================================
|
||||
|
||||
model DdsStatement {
|
||||
id Int @id @default(autoincrement())
|
||||
reference_number String @unique
|
||||
company_id Int?
|
||||
status String? @default("draft") // draft, submitted, approved, rejected
|
||||
risk_assessment String? // low, medium, high
|
||||
lot_ids String? @db.Text // JSON array of lot IDs
|
||||
submission_date String?
|
||||
eu_reference String? // EU system reference after submission
|
||||
notes String? @db.Text
|
||||
created_at DateTime? @default(now())
|
||||
updated_at DateTime? @updatedAt
|
||||
|
||||
// Relations
|
||||
company Company? @relation(fields: [company_id], references: [id])
|
||||
|
||||
@@index([id])
|
||||
@@index([reference_number])
|
||||
@@map("dds_statements")
|
||||
}
|
||||
|
||||
// ============================================
|
||||
// Audit Logs (Trilha de Auditoria)
|
||||
// ============================================
|
||||
|
||||
model AuditLog {
|
||||
id Int @id @default(autoincrement())
|
||||
entity_type String // User, Company, Producer, Area, Lot, DdsStatement
|
||||
entity_id Int?
|
||||
action String // create, update, delete, login, export
|
||||
user_id Int?
|
||||
details String? @db.Text // JSON with additional details
|
||||
ip_address String?
|
||||
created_at DateTime? @default(now())
|
||||
|
||||
// Relations
|
||||
user User? @relation(fields: [user_id], references: [id])
|
||||
|
||||
@@index([id])
|
||||
@@map("audit_logs")
|
||||
}
|
||||
Reference in New Issue
Block a user