generated from coulomb/repo-seed
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>
This commit is contained in:
19
src/activity_core/db.py
Normal file
19
src/activity_core/db.py
Normal file
@@ -0,0 +1,19 @@
|
||||
"""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)
|
||||
Reference in New Issue
Block a user