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 UK
        string descripcion
        string estado
        uuid juzgado_id FK
        datetime fecha_creacion
    }

    SUJETO {
        uuid id PK
        string nombre
        string dni UK
        string email
        string telefono
        string tipo "DEMANDANTE|DEMANDADO|TESTIGO..."
    }

    NOTIFICACION {
        uuid id PK
        uuid proceso_id FK
        uuid sujeto_id FK
        string canal "EMAIL|WHATSAPP|PRESENCIAL..."
        string estado "PENDIENTE|EN_PROCESO|ENVIADA..."
        string observacion
        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"
    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(...)).