TASK: Add SQLAlchemy async engine and session dependency wiring #11
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Parent
#2
What to build
Introduce centralized async engine/session factory and inject DB sessions through FastAPI dependencies.
Acceptance criteria
Blocked by
Notes
Plan: Async DB Session Wiring for PP-11
Implement a centralized SQLAlchemy async engine/session layer for the backend, inject sessions through FastAPI dependency wiring, and change /health to perform a real DB connectivity check with the new response contract. This keeps ADR001 runtime-policy behavior intact, minimizes surface-area changes, and uses mocked integration coverage for this ticket.
Steps
Phase 1: Dependency and runtime baseline
1.1 Add exact backend runtime pins for SQLAlchemy async support and PostgreSQL async driver.
1.2 Regenerate lockfile under Python 3.14 and verify deterministic resolution.
Phase 2: Database layer primitives
2.1 Add a new backend database module containing:
2.2 Ensure full typing and async safety for all new functions.
Phase 3: App wiring and endpoint behavior
3.1 Update FastAPI lifespan to initialize DB resources at startup and dispose engine at shutdown while preserving runtime policy validation ordering.
3.2 Replace /health behavior to check DB connectivity through injected async session dependency and return the new DB-centric schema.
3.3 Keep root and compatibility endpoint behavior unchanged aside from required imports/refactors.
Phase 4: Tests aligned with selected scope
4.1 Update integration tests to validate:
4.2 Implement mocked dependency override for DB session in tests (no real Postgres integration for PP-11).
4.3 Extend shared test fixtures only if needed, keeping scope minimal to avoid cross-test state.
5.1 Run backend format, lint, type, integration test, and docstring checks.
5.2 Run full project quality gate if feasible to catch cross-stack regressions.
5.3 Confirm coverage remains at configured threshold and runtime startup policy tests still pass.
Relevant files
Verification
Decisions
Further considerations