Saltar a contenido

Schema de Base de Datos

GexCom usa SQLAlchemy 2.0 con soporte dual PostgreSQL 16 (produccion/Docker) y SQLite (desarrollo/tests). Los ENUMs usan native_enum=False para compatibilidad cruzada.

Diagrama ER

erDiagram USUARIO { uuid id PK string nombre string email UK string password_hash string rol "ADMINISTRADOR|NOTIFICADOR" bool activo datetime created_at } JUZGADO { uuid id PK string nombre string codigo UK string email string telefono bool activo } PROCESO { uuid id PK string radicado "CUI 21 o 23 digitos" string radicado_canonico UK "21 digitos: identidad del proceso" string asunto "delito" } SUJETO { uuid id PK string tipo "FISCAL|DEFENSOR_PUBLICO_CONTRACTUAL|PROCESADO|VICTIMA|REPRESENTANTE_VICTIMA|MINISTERIO_PUBLICO" string tipo_documento string dni UK string nombre string email string telefono string direccion string descripcion bool es_menor } REPRESENTACION { uuid id PK uuid representante_id FK uuid representado_id FK,UK "unico: 1 representante por sujeto" string calidad "ABOGADO_CONTRACTUAL|ABOGADO_PUBLICO|REPRESENTANTE_LEGAL" } NOTIFICACION { uuid id PK uuid proceso_id FK uuid sujeto_id FK string canal "EMAIL|WHATSAPP|CORREO_POSTAL|PERSONAL|TELEFONO" string estado "PENDIENTE|EN_PROCESO|ENVIADA..." string observaciones "gestion acumulada por sujeto" datetime fecha_creacion datetime fecha_envio } AUDIENCIA { uuid id PK uuid proceso_id FK string tipo datetime fecha_hora string lugar string estado string descripcion } AUDIT_LOG { int id PK "autoincrement" string tabla string accion uuid usuario_id json detalles datetime timestamp } LOGIN_ATTEMPT { uuid id PK string email int intentos datetime bloqueado_hasta datetime updated_at } JUZGADO_PROCESO { uuid juzgado_id FK uuid proceso_id FK } SUJETO_PROCESO { uuid sujeto_id FK uuid proceso_id FK } USUARIO ||--o{ AUDIT_LOG : "genera" JUZGADO ||--o{ PROCESO : "tiene" PROCESO ||--o{ NOTIFICACION : "tiene" PROCESO ||--o{ AUDIENCIA : "tiene" SUJETO ||--o{ NOTIFICACION : "recibe" SUJETO ||--o| REPRESENTACION : "es representado por (0..1)" SUJETO ||--o{ REPRESENTACION : "representa a (0..N)" JUZGADO }o--o{ PROCESO : "JUZGADO_PROCESO" SUJETO }o--o{ PROCESO : "SUJETO_PROCESO"

Notas de Implementacion

ENUMs

Todos los ENUMs usan native_enum=False para compatibilidad SQLite/PostgreSQL:

Column(SAEnum(EstadoNotificacion, native_enum=False))

Foreign Keys

Relacion ondelete
proceso → notificacion CASCADE
sujeto → notificacion RESTRICT
proceso → audiencia CASCADE

AuditLog (Inmutabilidad)

En PostgreSQL, un trigger impide DELETE y UPDATE en audit_log:

CREATE RULE audit_log_no_delete AS ON DELETE TO audit_log DO INSTEAD NOTHING;
CREATE RULE audit_log_no_update AS ON UPDATE TO audit_log DO INSTEAD NOTHING;

Connection Pooling (PostgreSQL)

pool_size=5, max_overflow=10, pool_pre_ping=True
SQLite usa StaticPool en tests y NullPool en desarrollo local.

Tablas M:N

JUZGADO_PROCESO y SUJETO_PROCESO son tablas junction sin columnas adicionales. Las queries link/unlink usan session.execute(insert(table).values(...)).