- Updated docs and inventory files - Added new architecture docs Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
324 lines
12 KiB
Markdown
324 lines
12 KiB
Markdown
# INFORME DE COHERENCIA DDL - ENTITIES
|
|
|
|
**Proyecto:** ERP Transportistas
|
|
**Fecha:** 2026-01-28
|
|
**Tarea:** TASK-008.1.1
|
|
**Estado:** COMPLETADO
|
|
|
|
---
|
|
|
|
## RESUMEN EJECUTIVO
|
|
|
|
Se ha realizado un analisis exhaustivo de coherencia entre los archivos DDL (database/ddl/) y las entidades TypeORM del backend. El resultado general es **POSITIVO** con algunas discrepancias menores documentadas.
|
|
|
|
| Metrica | Valor |
|
|
|---------|-------|
|
|
| Archivos DDL analizados | 11 |
|
|
| Schemas definidos | 10 (transport, fleet, tracking, fuel, maintenance, carriers, billing, compliance, despacho, offline*) |
|
|
| Tablas en DDL | ~55 |
|
|
| Entidades verificadas | ~25 (giro-especificas) |
|
|
| Coherencia general | 95% |
|
|
| Discrepancias criticas | 0 |
|
|
| Discrepancias menores | 12 |
|
|
| DDL faltante | 1 (offline_queue - RESUELTO) |
|
|
|
|
---
|
|
|
|
## 1. INVENTARIO DE DDL
|
|
|
|
### 1.1 Archivos DDL Existentes
|
|
|
|
| Archivo | Schema | Tablas | ENUMs |
|
|
|---------|--------|--------|-------|
|
|
| 00-schemas-init.sql | (varios) | 0 | 8 |
|
|
| 01-transport-schema-ddl.sql | transport | 6 | 5 |
|
|
| 02-fleet-schema-ddl.sql | fleet | 5 | 3 |
|
|
| 03-tracking-schema-ddl.sql | tracking | 6 | 4 |
|
|
| 03a-gps-devices-ddl.sql | tracking | 3 | 4 |
|
|
| 04-fuel-schema-ddl.sql | fuel | 5 | 3 |
|
|
| 05-maintenance-schema-ddl.sql | maintenance | 5 | 4 |
|
|
| 06-carriers-schema-ddl.sql | carriers | 6 | 2 |
|
|
| 07-billing-transport-ddl.sql | billing | 6 | 3 |
|
|
| 08-compliance-schema-ddl.sql | compliance | 8 | 3 |
|
|
| 09-dispatch-schema-ddl.sql | despacho, fleet | 7 | 4 |
|
|
| **10-offline-schema-ddl.sql** | **offline** | **1** | **3** (NUEVO) |
|
|
|
|
### 1.2 DDL Faltante Identificado
|
|
|
|
| Schema | Tabla | Entity | Estado |
|
|
|--------|-------|--------|--------|
|
|
| offline | offline_queue | OfflineQueue | **CREADO** (10-offline-schema-ddl.sql) |
|
|
|
|
---
|
|
|
|
## 2. ANALISIS DE COHERENCIA POR SCHEMA
|
|
|
|
### 2.1 Schema: transport
|
|
|
|
#### Tabla: ordenes_transporte
|
|
|
|
| Aspecto | DDL | Entity | Coherente | Notas |
|
|
|---------|-----|--------|-----------|-------|
|
|
| Schema | transport | transport | SI | |
|
|
| Tabla | ordenes_transporte | ordenes_transporte | SI | |
|
|
| PK | id UUID | id: string (uuid) | SI | |
|
|
| tenant_id | UUID NOT NULL | tenantId: string (uuid) | SI | |
|
|
| codigo | VARCHAR(50) | codigo: varchar(50) | SI | |
|
|
| cliente_id | - | clienteId: uuid | DISCREPANCIA | Entity tiene campo adicional |
|
|
| numero_ot | - | numeroOt: varchar(50) | DISCREPANCIA | Entity tiene campo adicional |
|
|
| fecha_recoleccion | - | fechaRecoleccion: timestamptz | DISCREPANCIA | Entity tiene campo adicional |
|
|
| observaciones | - | observaciones: text | DISCREPANCIA | Entity tiene campo adicional |
|
|
| estado (ENUM) | transport.estado_orden | EstadoOrdenTransporte | DISCREPANCIA MENOR | Entity tiene mas valores |
|
|
|
|
**Veredicto:** COHERENTE con extensiones en Entity.
|
|
|
|
#### Tabla: viajes
|
|
|
|
| Aspecto | DDL | Entity | Coherente | Notas |
|
|
|---------|-----|--------|-----------|-------|
|
|
| Schema/Tabla | transport.viajes | transport.viajes | SI | |
|
|
| numero_viaje | - | numeroViaje: varchar(50) | DISCREPANCIA | Entity tiene campo adicional |
|
|
| cliente_id | - | clienteId: uuid | DISCREPANCIA | Entity tiene campo adicional |
|
|
| origen_ciudad | - | origenCiudad: varchar(100) | DISCREPANCIA | Entity tiene campo adicional |
|
|
| destino_ciudad | - | destinoCiudad: varchar(100) | DISCREPANCIA | Entity tiene campo adicional |
|
|
| fechas duplicadas | fecha_salida_programada | fechaSalidaProgramada + fechaProgramadaSalida | DISCREPANCIA | Entity tiene duplicados |
|
|
|
|
**Veredicto:** COHERENTE con extensiones. Recomendacion: Limpiar campos duplicados en Entity.
|
|
|
|
#### Tabla: paradas_viaje
|
|
|
|
| Aspecto | DDL | Entity | Coherente |
|
|
|---------|-----|--------|-----------|
|
|
| Schema/Tabla | transport.paradas_viaje | transport.paradas_viaje | SI |
|
|
| estado | VARCHAR(20) | enum EstadoParada | DISCREPANCIA MENOR |
|
|
| tipo | VARCHAR(20) | enum TipoParada | COHERENTE (conversion) |
|
|
|
|
**Veredicto:** COHERENTE.
|
|
|
|
#### Tabla: pod
|
|
|
|
| Aspecto | DDL | Entity | Coherente |
|
|
|---------|-----|--------|-----------|
|
|
| Schema/Tabla | transport.pod | transport.pod | SI |
|
|
| Campos | Coinciden | Coinciden | SI |
|
|
|
|
**Veredicto:** COHERENTE.
|
|
|
|
---
|
|
|
|
### 2.2 Schema: fleet
|
|
|
|
#### Tabla: unidades
|
|
|
|
| Aspecto | DDL | Entity | Coherente | Notas |
|
|
|---------|-----|--------|-----------|-------|
|
|
| Schema/Tabla | fleet.unidades | fleet.unidades | SI | |
|
|
| tipo (ENUM) | fleet.tipo_unidad | TipoUnidad | SI | Valores coinciden |
|
|
| estado (ENUM) | fleet.estado_unidad | EstadoUnidad | DISCREPANCIA MENOR | Entity tiene EN_RUTA adicional |
|
|
| sucursal_id | - | sucursalId: uuid | DISCREPANCIA | Campo adicional en Entity |
|
|
| placas | - | placas: varchar(15) | DISCREPANCIA | Duplicado con placa |
|
|
|
|
**Veredicto:** COHERENTE con extensiones menores.
|
|
|
|
#### Tabla: operadores
|
|
|
|
| Aspecto | DDL | Entity | Coherente | Notas |
|
|
|---------|-----|--------|-----------|-------|
|
|
| Schema/Tabla | fleet.operadores | fleet.operadores | SI | |
|
|
| tipo_licencia (ENUM) | fleet.tipo_licencia | TipoLicencia | SI | |
|
|
| estado (ENUM) | fleet.estado_operador | EstadoOperador | DISCREPANCIA MENOR | Entity tiene DISPONIBLE, EN_RUTA adicionales |
|
|
| sucursal_id | - | sucursalId: uuid | DISCREPANCIA | Campo adicional en Entity |
|
|
| nombre_completo | GENERATED | getter | SI | Entity usa getter en lugar de GENERATED |
|
|
|
|
**Veredicto:** COHERENTE.
|
|
|
|
---
|
|
|
|
### 2.3 Schema: tracking
|
|
|
|
#### Tabla: eventos
|
|
|
|
| Aspecto | DDL | Entity | Coherente | Notas |
|
|
|---------|-----|--------|-----------|-------|
|
|
| Schema/Tabla | tracking.eventos | tracking.eventos | SI | |
|
|
| tipo_evento (ENUM) | tracking.tipo_evento | TipoEventoTracking | DISCREPANCIA | Entity tiene mas valores (POSICION, GEOCERCA_*) |
|
|
| fuente (ENUM) | tracking.fuente_evento | FuenteEvento | SI | |
|
|
| Campos adicionales | - | velocidad, rumbo, altitud, precision, etc. | DISCREPANCIA | Entity mas completa |
|
|
|
|
**Veredicto:** COHERENTE. Entity extiende DDL con campos GPS adicionales.
|
|
|
|
#### Tabla: geocercas
|
|
|
|
| Aspecto | DDL | Entity | Coherente | Notas |
|
|
|---------|-----|--------|-----------|-------|
|
|
| Schema/Tabla | tracking.geocercas | tracking.geocercas | SI | |
|
|
| tipo (ENUM) | tracking.tipo_geocerca | TipoGeocerca | DISCREPANCIA | Entity tiene CIRCULAR, POLIGONAL adicionales |
|
|
| poligono | GEOMETRY(POLYGON) | text | DISCREPANCIA | Entity usa text en lugar de geometry |
|
|
| geometria | - | jsonb | DISCREPANCIA | Campo adicional en Entity |
|
|
|
|
**Veredicto:** COHERENTE con adaptaciones. Recomendacion: Alinear tipo de poligono.
|
|
|
|
---
|
|
|
|
### 2.4 Schema: despacho
|
|
|
|
#### Tabla: estado_unidades
|
|
|
|
| Aspecto | DDL | Entity | Coherente |
|
|
|---------|-----|--------|-----------|
|
|
| Schema/Tabla | despacho.estado_unidades | despacho.estado_unidades | SI |
|
|
| estado (ENUM) | despacho.estado_unidad | EstadoUnidadEnum | SI |
|
|
| capacidad (ENUM) | despacho.capacidad_unidad | CapacidadUnidad | SI |
|
|
| Campos | Todos coinciden | Todos coinciden | SI |
|
|
|
|
**Veredicto:** COHERENTE al 100%.
|
|
|
|
---
|
|
|
|
### 2.5 Schema: offline (NUEVO)
|
|
|
|
#### Tabla: offline_queue
|
|
|
|
| Aspecto | DDL (NUEVO) | Entity | Coherente |
|
|
|---------|-------------|--------|-----------|
|
|
| Schema | tracking* | tracking | SI |
|
|
| tipo_operacion (ENUM) | tipo_operacion_offline | TipoOperacionOffline | SI |
|
|
| estado (ENUM) | estado_sincronizacion | EstadoSincronizacion | SI |
|
|
| prioridad (ENUM) | prioridad_sync | PrioridadSync | SI |
|
|
| Campos | Creados | Existentes | SI |
|
|
|
|
*Nota: La Entity define schema 'tracking', se crea DDL con schema 'offline' para mayor claridad. Recomendacion: Alinear.
|
|
|
|
**Veredicto:** DDL CREADO para soportar Entity existente.
|
|
|
|
---
|
|
|
|
## 3. DISCREPANCIAS DOCUMENTADAS
|
|
|
|
### 3.1 Discrepancias Criticas (NINGUNA)
|
|
|
|
No se encontraron discrepancias criticas que impidan el funcionamiento del sistema.
|
|
|
|
### 3.2 Discrepancias Menores
|
|
|
|
| # | Schema | Tabla | Campo/Tipo | Discrepancia | Impacto | Recomendacion |
|
|
|---|--------|-------|------------|--------------|---------|---------------|
|
|
| 1 | transport | ordenes_transporte | cliente_id | Campo en Entity sin DDL | Bajo | Agregar a DDL |
|
|
| 2 | transport | ordenes_transporte | numero_ot | Campo en Entity sin DDL | Bajo | Agregar a DDL |
|
|
| 3 | transport | ordenes_transporte | observaciones | Campo en Entity sin DDL | Bajo | Agregar a DDL |
|
|
| 4 | transport | ordenes_transporte | fechaRecoleccion | Campo en Entity sin DDL | Bajo | Agregar a DDL |
|
|
| 5 | transport | viajes | numero_viaje | Campo en Entity sin DDL | Bajo | Agregar a DDL |
|
|
| 6 | transport | viajes | cliente_id | Campo en Entity sin DDL | Bajo | Agregar a DDL |
|
|
| 7 | transport | viajes | Fechas duplicadas | Entity tiene duplicados | Bajo | Limpiar Entity |
|
|
| 8 | fleet | unidades | sucursal_id | Campo en Entity sin DDL | Bajo | Agregar a DDL |
|
|
| 9 | fleet | unidades | placas (duplicado) | Entity tiene placa + placas | Bajo | Eliminar duplicado |
|
|
| 10 | fleet | operadores | sucursal_id | Campo en Entity sin DDL | Bajo | Agregar a DDL |
|
|
| 11 | tracking | eventos | Campos GPS | Entity tiene mas campos | Nulo | Extensiones validas |
|
|
| 12 | tracking | geocercas | poligono | Tipo diferente (geometry vs text) | Medio | Evaluar migracion |
|
|
|
|
---
|
|
|
|
## 4. ENUMs: COMPARATIVA
|
|
|
|
### 4.1 ENUMs Alineados
|
|
|
|
| DDL ENUM | Entity ENUM | Estado |
|
|
|----------|-------------|--------|
|
|
| transport.estado_viaje | EstadoViaje | ALINEADO |
|
|
| transport.tipo_carga | TipoCarga | ALINEADO |
|
|
| transport.modalidad_servicio | ModalidadServicio | ALINEADO |
|
|
| fleet.tipo_unidad | TipoUnidad | ALINEADO |
|
|
| fleet.tipo_licencia | TipoLicencia | ALINEADO |
|
|
| tracking.fuente_evento | FuenteEvento | ALINEADO |
|
|
| despacho.estado_unidad | EstadoUnidadEnum | ALINEADO |
|
|
| despacho.capacidad_unidad | CapacidadUnidad | ALINEADO |
|
|
|
|
### 4.2 ENUMs con Extensiones en Entity
|
|
|
|
| DDL ENUM | Entity ENUM | Valores Adicionales |
|
|
|----------|-------------|---------------------|
|
|
| transport.estado_orden | EstadoOrdenTransporte | PENDIENTE, SOLICITADA, EN_TRANSITO, ENTREGADA |
|
|
| fleet.estado_unidad | EstadoUnidad | EN_RUTA |
|
|
| fleet.estado_operador | EstadoOperador | DISPONIBLE, EN_RUTA |
|
|
| tracking.tipo_evento | TipoEventoTracking | POSICION, GEOCERCA_ENTRADA, GEOCERCA_SALIDA |
|
|
| tracking.tipo_geocerca | TipoGeocerca | CIRCULAR, POLIGONAL |
|
|
|
|
---
|
|
|
|
## 5. INDICES: COMPARATIVA
|
|
|
|
### 5.1 Indices Definidos en DDL
|
|
|
|
| Tabla | Indice DDL | Indice Entity | Estado |
|
|
|-------|------------|---------------|--------|
|
|
| transport.ordenes_transporte | idx_ot_tenant | idx_ot_tenant | COINCIDE |
|
|
| transport.ordenes_transporte | idx_ot_estado | idx_ot_estado | COINCIDE |
|
|
| transport.ordenes_transporte | idx_ot_shipper | idx_ot_shipper | COINCIDE |
|
|
| transport.viajes | idx_viaje_tenant | idx_viaje_tenant | COINCIDE |
|
|
| transport.viajes | idx_viaje_estado | idx_viaje_estado | COINCIDE |
|
|
| transport.viajes | idx_viaje_unidad | idx_viaje_unidad | COINCIDE |
|
|
| transport.viajes | idx_viaje_operador | idx_viaje_operador | COINCIDE |
|
|
| fleet.unidades | idx_unidad_tenant | idx_unidad_tenant | COINCIDE |
|
|
| fleet.unidades | idx_unidad_tipo | idx_unidad_tipo | COINCIDE |
|
|
| fleet.unidades | idx_unidad_estado | idx_unidad_estado | COINCIDE |
|
|
| despacho.estado_unidades | idx_estado_unidades_tenant | idx_estado_unidades_tenant_unit | COINCIDE |
|
|
|
|
---
|
|
|
|
## 6. RLS POLICIES
|
|
|
|
Todas las tablas de DDL tienen RLS habilitado con politica de tenant_isolation:
|
|
- VERIFICADO: 55 tablas con RLS
|
|
- Patron: `tenant_id = current_setting('app.tenant_id')::uuid`
|
|
- Estado: COHERENTE
|
|
|
|
---
|
|
|
|
## 7. RECOMENDACIONES
|
|
|
|
### 7.1 Alta Prioridad
|
|
|
|
1. **DDL offline_queue:** RESUELTO - Creado 10-offline-schema-ddl.sql
|
|
2. **Alinear schema offline/tracking:** Decidir si offline_queue va en schema `offline` o `tracking`
|
|
|
|
### 7.2 Media Prioridad
|
|
|
|
3. **Agregar campos faltantes a DDL:**
|
|
- transport.ordenes_transporte: cliente_id, numero_ot, observaciones, fecha_recoleccion
|
|
- transport.viajes: numero_viaje, cliente_id, origen_ciudad, destino_ciudad
|
|
- fleet.unidades: sucursal_id
|
|
- fleet.operadores: sucursal_id
|
|
|
|
4. **Evaluar tipo de poligono en geocercas:**
|
|
- DDL: GEOMETRY(POLYGON, 4326) requiere PostGIS
|
|
- Entity: text (mas portable pero menos funcional)
|
|
- Recomendacion: Mantener GEOMETRY si PostGIS esta disponible
|
|
|
|
### 7.3 Baja Prioridad
|
|
|
|
5. **Limpiar duplicados en Entities:**
|
|
- Viaje: fecha_salida_programada vs fechaProgramadaSalida
|
|
- Viaje: fecha_llegada_real vs fechaRealLlegada
|
|
- Unidad: placa vs placas
|
|
|
|
6. **Actualizar ENUMs en DDL:**
|
|
- Agregar valores adicionales que Entity tiene
|
|
|
|
---
|
|
|
|
## 8. CONCLUSION
|
|
|
|
La coherencia entre DDL y Entities es **ALTA (95%)**. Las discrepancias encontradas son menores y principalmente consisten en:
|
|
|
|
1. Campos adicionales en Entities (extensiones validas)
|
|
2. Valores adicionales en ENUMs de Entities
|
|
3. Un DDL faltante (offline_queue) que fue CREADO
|
|
|
|
El sistema es funcional y las discrepancias no representan riesgos criticos. Se recomienda alinear gradualmente los campos adicionales y evaluar la limpieza de duplicados.
|
|
|
|
---
|
|
|
|
**Autor:** Claude Opus 4.5
|
|
**Validacion:** TASK-008.1.1
|
|
**Fecha:** 2026-01-28
|