37 lines
1.4 KiB
Python
37 lines
1.4 KiB
Python
"""Tablas de la API: solo los logs de búsquedas y descargas.
|
|
|
|
Los archivos y su texto ya no están acá: los indexa FSCrawler en Elasticsearch.
|
|
"""
|
|
from datetime import datetime, timezone
|
|
|
|
from sqlalchemy import DateTime, Integer, String
|
|
from sqlalchemy.orm import Mapped, mapped_column
|
|
|
|
from app.database import Base
|
|
|
|
|
|
def ahora() -> datetime:
|
|
return datetime.now(timezone.utc)
|
|
|
|
|
|
class LogBusqueda(Base):
|
|
__tablename__ = "log_busquedas"
|
|
|
|
id: Mapped[int] = mapped_column(Integer, primary_key=True)
|
|
usuario: Mapped[str] = mapped_column(String(100), index=True)
|
|
criterio: Mapped[str] = mapped_column(String(50)) # ej. "cedula+nombre"
|
|
valor: Mapped[str] = mapped_column(String(300))
|
|
resultados: Mapped[int] = mapped_column(Integer, default=0)
|
|
ip: Mapped[str] = mapped_column(String(64), default="")
|
|
fecha: Mapped[datetime] = mapped_column(DateTime(timezone=True), default=ahora, index=True)
|
|
|
|
|
|
class LogDescarga(Base):
|
|
__tablename__ = "log_descargas"
|
|
|
|
id: Mapped[int] = mapped_column(Integer, primary_key=True)
|
|
usuario: Mapped[str] = mapped_column(String(100), index=True)
|
|
documento_id: Mapped[str] = mapped_column(String(128), index=True) # _id en Elasticsearch
|
|
ruta_relativa: Mapped[str] = mapped_column(String(1000))
|
|
ip: Mapped[str] = mapped_column(String(64), default="")
|
|
fecha: Mapped[datetime] = mapped_column(DateTime(timezone=True), default=ahora, index=True) |