Add a backend migration in adepthood¶
Create and apply an Alembic migration for a schema change in
Geoffe-Ga/adepthood. Verified against the repo state of 2026-07-31.
Prerequisites¶
.venvactivated, backend requirements installed- A local PostgreSQL reachable via
DATABASE_URL(or the default inbackend/src/database.py) - Migrations live in
backend/migrations/(alembic.inisetsscript_location = %(here)s/migrations);migrations/env.pyinjects the runtimeDATABASE_URL, normalized for asyncpg
Steps¶
-
Write the test first (TDD is required — adepthood
AGENTS.md): a failing test that exercises the new column/table through the model or endpoint. -
Change or add the SQLModel class under
backend/src/models/(one module per table; export it viamodels/__init__.pyso autogenerate sees it). -
Generate the revision from
backend/:
cd backend
alembic revision --autogenerate -m "add <thing>"
-
Review the generated file in
backend/migrations/versions/— autogenerate output is a draft, not a truth. Ensure bothupgrade()anddowngrade()are correct; follow the existing revision naming style (<hash>_<snake_case_summary>.py). -
Apply and test:
alembic upgrade head
pytest
Verify¶
alembic upgrade headruns cleanly on a fresh database, andalembic downgrade -1reverses it.- Your new test passes; the full gate run (quality gates) stays green.