INTEGER PRIMARY KEY AUTOINCREMENT.Overview
ICL Cotizaciones uses SQLite as the embedded relational database with Drizzle ORM for type-safe schema definitions and queries.- Source of truth:
src/db/schema.ts(Drizzle ORM) - Database file:
data/icl.db - Journal mode: WAL (Write-Ahead Logging)
- Foreign keys: Enabled (
foreign_keys = ON)
v2 Refactor (branch
refactor/core-model): Tables and columns renamed to English. origenes + vias merged into a single locations table with location_type discriminator.Entity Relationship Diagram
locations joins to quotations twice: once as origin (origin_id) and once as route (via_id). The location_type field is either 'origen' or 'via'.Table Schemas
users
User accounts with role-based access control.- Roles
- Constraints
| Role | Type | Description |
|---|---|---|
DIRECTOR | Admin | Full system access |
GERENTE | Admin | Full system access |
ADMINISTRACION | Admin | Full system access |
COMERCIAL | Standard | Access to own quotations only |
OPERACIONES | Standard | Access to own quotations only |
CSV | Standard | Limited access (deprecated role) |
clients
Client companies with optional user assignment.FFWW: Freight forwarderFinal: End clientBoth: Both freight forwarder and end client
locations
Unified table for origins and transit routes (via points).commercial_agreements
Commercial terms and pricing agreements per client.quotations
Core entity: freight quotations with operation, route, cargo, and financial details.- Status Values
- Computed Fields
| Status | Meaning |
|---|---|
ENCOTIZACION | Quote in progress (default) |
SI | Won/Confirmed |
NO | Lost |
PEND | Pending |
PEND A/C | Pending client approval |
pricing_netos
Unified pricing table for FCL and LCL net rates by route and validity period.port_rates
Base rates per port of loading with tiered pricing by CBM volume.Catalog Tables (No Foreign Keys)
pricing_netos and port_rates are catalog tables without formal foreign key constraints. They use text fields for locations that implicitly reference locations.name.Implicit Relationships
| Catalog Table | Field | Implicit Reference | Usage |
|---|---|---|---|
port_rates | port_of_loading | locations.name (where location_type='via') | Auto-suggest quotations.freight_net when load_type='LCL' |
pricing_netos | port | locations.name (where location_type='via') | Pricing form uses locations for cascading Region → Country → Via dropdowns |
Design Notes
Primary Keys
Primary Keys
All IDs are
Date Storage
Date Storage
All dates are stored as
TEXT in ISO 8601 format (YYYY-MM-DD). Timestamps (created_at, updated_at) are also TEXT.Boolean Fields
Boolean Fields
is_active fields are INTEGER with mode: "boolean" in Drizzle (stored as 0/1 in SQLite).Computed Quotation Fields
Computed Quotation Fields
quotations.profitis calculated server-side on every POST/PUTquotations.month,year,weekare derived fromquotations.dateon the server
Location Type Discriminator
Location Type Discriminator
locations.location_type discriminates between origins ('origen') and transit routes ('via'). APIs /api/origenes and /api/vias filter by this field internally.Related Documentation
Schema Definition
View the complete Drizzle schema in
src/db/schema.tsAPI Reference
Explore API endpoints for each table
Migrations
Learn about database migrations with drizzle-kit
Seed Data
Run
npm run db:seed to populate test data