semillero-INVIMA/diagramas/base-datos.md

4.1 KiB

Base de datos

No se encontro un archivo schema.sql ni una carpeta de migraciones. El esquema activo esta en backend/comando.sql y tambien se crea/ajusta en tiempo de arranque desde ensureAuthTables y ensureInvimaTables.

Modelo activo

erDiagram
  APP_USERS {
    bigserial id PK
    text username UK
    text full_name
    text role
    text password_hash
    boolean is_active
    timestamptz created_at
    timestamptz updated_at
  }

  APP_SESSIONS {
    text token_hash PK
    bigint user_id FK
    timestamptz expires_at
    timestamptz created_at
    timestamptz last_used_at
    text user_agent
    text ip_address
  }

  INVIMA_API_RAW {
    bigserial id PK
    text source_dataset_key UK
    text source_dataset_id
    text source_uid UK
    jsonb raw_payload
    timestamptz fetched_at
    timestamptz created_at
    timestamptz updated_at
  }

  INVIMA_API_CATALOG {
    text source_dataset_key PK
    text source_dataset_id
    text source_uid PK
    text source_dataset_name
    text categoria_linea
    text categoria_canonica
    text categoria_slug
    text expediente
    text registro_sanitario
    text producto
    text titular
    text estado_registro
    date fecha_expedicion
    date fecha_vencimiento
    text modalidad
    text grupo
    text marca
    text principio_activo
    text forma_farmaceutica
    text presentacion_comercial
    text atc
    text rol_nombre
    text rol_tipo
    text ciudad_titular
    text pais_titular
    text fabricante
    text importador
    text vigencia
    text search_text
    jsonb extra
    timestamptz fetched_at
    timestamptz updated_at
  }

  APP_USERS ||--o{ APP_SESSIONS : user_id
  INVIMA_API_RAW ||--o| INVIMA_API_CATALOG : "source_dataset_key_source_uid"

Notas del modelo activo:

  • app_sessions.user_id si tiene FK real hacia app_users(id) con ON DELETE CASCADE.
  • invima_api_raw e invima_api_catalog comparten source_dataset_key y source_uid, pero el codigo no declara una FK entre ellas.
  • invima_api_catalog tiene indices reales para dataset, categoria, estado, registro, expediente, modalidad, grupo, fechas, FTS y trigramas.

Modelo legado en comandos de pgAdmin

erDiagram
  PRODUCTOS {
    text id_producto PK
    text nombre_comercial
    text categoria_general
  }

  REGISTROS_SANITARIOS {
    text id_registro PK
    text id_producto FK
    numeric numero_registro
    text estado
    date fecha_expedicion
    date fecha_vencimiento
    text modalidad
    text titular_registro
    text fabricante
    text observaciones
  }

  ALERTAS_SANITARIAS {
    text id_alerta PK
    text id_producto FK
    date fecha_alerta
    text tipo
    text descripcion
    text estado_alerta
    text url_fuente
  }

  MEDICAMENTOS {
    text id_producto FK
    text categoria_general
    text estado FK
    text subcategoria PK
    text concentracion_base
    text forma_farmaceutica
    text codigo_atc
    text tipo_medicamento
  }

  DISPOSITIVOS {
    text id_producto FK
    text categoria_general
    text estado FK
    text subcategoria PK
    text clase_riesgo
    text uso_previsto_detallado
    text energia_fuente
    boolean software_incluido
    text version_software
    integer vida_util_meses
  }

  ACTORES {
    numeric id_actor PK
    text tipo
    text razon_social
    text nit
    text pais
    text contacto
  }

  EVALUACIONES {
    text estado PK
    text id_producto FK
    numeric id_actor FK
    text id_registro FK
    text id_alerta FK
    date fecha_revision
    text observaciones
  }

  PRODUCTOS ||--o{ REGISTROS_SANITARIOS : id_producto
  PRODUCTOS ||--o{ ALERTAS_SANITARIAS : id_producto
  PRODUCTOS ||--o{ MEDICAMENTOS : id_producto
  PRODUCTOS ||--o{ DISPOSITIVOS : id_producto
  PRODUCTOS ||--o{ EVALUACIONES : id_producto
  ACTORES ||--o{ EVALUACIONES : id_actor
  REGISTROS_SANITARIOS ||--o{ EVALUACIONES : id_registro
  ALERTAS_SANITARIAS ||--o{ EVALUACIONES : id_alerta
  EVALUACIONES ||--o{ MEDICAMENTOS : estado
  EVALUACIONES ||--o{ DISPOSITIVOS : estado

Archivos analizados

  • backend/comando.sql
  • backend/comandos en pgadmin4.txt
  • backend/databasepg.js
  • backend/src/auth/auth.service.js
  • backend/invima/service.js
  • backend/src/db/pool.js