Subir todos los cambios recientes a la rama principal
This commit is contained in:
@@ -119,6 +119,18 @@ class Settings(BaseSettings):
|
||||
CELERY_BROKER_URL: str = Field(..., env="CELERY_BROKER_URL")
|
||||
CELERY_RESULT_BACKEND: str = Field(..., env="CELERY_RESULT_BACKEND")
|
||||
|
||||
# ===================================
|
||||
# CAMPOS ADICIONALES
|
||||
# ===================================
|
||||
POSTGRES_DB: str = Field(..., env="POSTGRES_DB")
|
||||
POSTGRES_USER: str = Field(..., env="POSTGRES_USER")
|
||||
POSTGRES_PASSWORD: str = Field(..., env="POSTGRES_PASSWORD")
|
||||
SMTP_USERNAME: Optional[str] = Field(default=None, env="SMTP_USERNAME")
|
||||
MAX_UPLOAD_SIZE: int = Field(default=10485760, env="MAX_UPLOAD_SIZE")
|
||||
UPLOAD_DIR: str = Field(default="./uploads", env="UPLOAD_DIR")
|
||||
RATE_LIMIT_REQUESTS: int = Field(default=100, env="RATE_LIMIT_REQUESTS")
|
||||
RATE_LIMIT_WINDOW: int = Field(default=60, env="RATE_LIMIT_WINDOW")
|
||||
|
||||
def is_production(self) -> bool:
|
||||
"""Check if environment is production."""
|
||||
return self.ENVIRONMENT.lower() == "production"
|
||||
@@ -139,4 +151,7 @@ def get_settings() -> Settings:
|
||||
|
||||
Using lru_cache to create a singleton pattern for settings.
|
||||
"""
|
||||
return Settings()
|
||||
return Settings()
|
||||
|
||||
# Crear una instancia global de Settings
|
||||
settings = Settings()
|
||||
@@ -10,6 +10,7 @@ from sqlalchemy import String, DateTime, func
|
||||
from typing import AsyncGenerator
|
||||
import uuid
|
||||
from datetime import datetime
|
||||
import logging
|
||||
|
||||
from app.core.config import get_settings
|
||||
|
||||
@@ -34,6 +35,8 @@ AsyncSessionLocal = async_sessionmaker(
|
||||
autocommit=False
|
||||
)
|
||||
|
||||
logger = logging.getLogger("database")
|
||||
|
||||
|
||||
class Base(DeclarativeBase):
|
||||
"""Base class para todos los modelos SQLAlchemy."""
|
||||
@@ -57,13 +60,16 @@ async def get_db() -> AsyncGenerator[AsyncSession, None]:
|
||||
"""
|
||||
async with AsyncSessionLocal() as session:
|
||||
try:
|
||||
logger.debug("Intentando crear una nueva sesión de base de datos.")
|
||||
yield session
|
||||
await session.commit()
|
||||
except Exception:
|
||||
except Exception as e:
|
||||
logger.error("Error al crear la sesión de base de datos: %s", str(e))
|
||||
await session.rollback()
|
||||
raise
|
||||
finally:
|
||||
await session.close()
|
||||
logger.debug("Sesión de base de datos cerrada.")
|
||||
|
||||
|
||||
async def create_tables():
|
||||
|
||||
Reference in New Issue
Block a user