Files
bourbonacci/backend/app/database.py
T
derekc ef8b44934c Fix aiomysql pool_pre_ping crash, add rate limiting and security hardening
Remove pool_pre_ping=True to fix startup crash caused by aiomysql 0.2.0
async adapter requiring a reconnect argument SQLAlchemy does not pass.
Add slowapi rate limiting, structured logging, CORS config, backend
health check, and nginx security headers.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-25 00:44:23 -07:00

21 lines
625 B
Python

from sqlalchemy.ext.asyncio import create_async_engine, async_sessionmaker, AsyncSession
from sqlalchemy.orm import DeclarativeBase
from app.config import settings
engine = create_async_engine(settings.database_url, echo=False, pool_recycle=1800)
AsyncSessionLocal = async_sessionmaker(engine, expire_on_commit=False)
class Base(DeclarativeBase):
pass
async def init_db() -> None:
# Import models so their tables are registered on Base.metadata before create_all
from app.models import user, entry # noqa: F401
async with engine.begin() as conn:
await conn.run_sync(Base.metadata.create_all)