Files
activity-core/src/activity_core/db.py
Bernd Worsch f55f497107 feat(db): init Alembic (async) + SQLAlchemy declarative base — T08
- alembic init -t async migrations
- alembic.ini: dev fallback URL postgresql+asyncpg://…:5433/actcore;
  ACTCORE_DB_URL env var overrides at runtime; src/ added to sys.path
- migrations/env.py: reads ACTCORE_DB_URL, wires target_metadata to Base.metadata
- src/activity_core/db.py: DeclarativeBase subclass + make_engine() helper

Tool choice: Alembic + SQLAlchemy[asyncio] (already declared in pyproject.toml).
Migrations run with: ACTCORE_DB_URL=... alembic upgrade head

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-26 21:45:40 +00:00

20 lines
571 B
Python

"""SQLAlchemy async engine and declarative base for activity-core."""
import os
from sqlalchemy.ext.asyncio import AsyncEngine, create_async_engine
from sqlalchemy.orm import DeclarativeBase
class Base(DeclarativeBase):
pass
def make_engine(url: str | None = None) -> AsyncEngine:
"""Return an async engine. Falls back to ACTCORE_DB_URL, then the dev default."""
resolved = url or os.environ.get(
"ACTCORE_DB_URL",
"postgresql+asyncpg://actcore:actcore@localhost:5433/actcore",
)
return create_async_engine(resolved, echo=False)