diff --git a/app/core/database.py b/app/core/database.py index 20a302f..151a750 100644 --- a/app/core/database.py +++ b/app/core/database.py @@ -6,7 +6,14 @@ from .config import settings # Convert sync URL to async DATABASE_URL = settings.DATABASE_URL.replace("postgresql://", "postgresql+asyncpg://") -engine = create_async_engine(DATABASE_URL, echo=settings.DEBUG, pool_size=10, max_overflow=20) +engine = create_async_engine( + DATABASE_URL, + echo=settings.DEBUG, + pool_size=10, + max_overflow=20, + pool_pre_ping=True, # Test connection before using + pool_recycle=3600 # Recycle connections after 1 hour +) async_session = async_sessionmaker(engine, class_=AsyncSession, expire_on_commit=False) Base = declarative_base()