50ee1f9fed
- Block disabled accounts at login and unimpersonate (C4, C2) - Catch IntegrityError on register commit to return 409 instead of 500 (C5) - Stop _seed_admin from overwriting existing admin password on restart (C8) - Cap public/stats query at 500 users to bound memory usage (C3) - Rate-limit PUT /me/password at 5/minute (C6) - Bump SQLAlchemy to 2.0.50 and aiomysql to 0.3.2; re-enable pool_pre_ping (C7) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
21 lines
645 B
Python
21 lines
645 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_pre_ping=True, 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)
|