api 의존성 추가 및 DB 설정 변경

This commit is contained in:
jaehwang committed 2026-09-08 13:11:53 +09:00
1 parent f008ed4010
commit ab4dc6fb81
5 files changed
+37 -4

No files matched your search

+8 -2
View File
@@ -7,7 +7,7 @@ from collections.abc import AsyncGenerator
from sqlalchemy.ext.asyncio import AsyncSession, async_sessionmaker, create_async_engine
from sqlalchemy.orm import DeclarativeBase
from sqlalchemy.pool import AsyncQueuePool
from sqlalchemy.pool import AsyncAdaptedQueuePool
from settings import settings
@@ -25,7 +25,7 @@ engine = create_async_engine(
settings.mysql_url,
pool_size=POOL_SIZE,
max_overflow=MAX_OVERFLOW,
poolclass=AsyncQueuePool,
poolclass=AsyncAdaptedQueuePool,
pool_timeout=POOL_TIMEOUT,
pool_recycle=POOL_RECYCLE,
pool_pre_ping=True, # 끊긴 연결을 쓰기 전에 걸러낸다
@@ -54,5 +54,11 @@ async def get_session() -> AsyncGenerator[AsyncSession, None]:
raise
async def create_missing_tables() -> None:
"""없는 테이블만 만든다. 컬럼이 바뀐 기존 테이블은 건드리지 않는다"""
async with engine.begin() as connection:
await connection.run_sync(Base.metadata.create_all)
async def close_engine() -> None:
await engine.dispose()