Safe Alembic migration workflow for this repository. Use when changing SQLModel table schemas, telemetry/training/model artifact persistence structures, constraints, indexes, or migration-linked API contracts.
Make schema changes safely and reversibly for this PostgreSQL + SQLModel + Alembic project, while keeping API contracts, tests, and docs in sync.
docker compose up -d db mailcatcher
If models changed, run prestart after applying migrations to validate startup flow.
Modify models in backend/app/models.py.
Check field constraints, indexes, and relationship behavior against existing conventions.
Use uv from backend directory:
cd backend && uv run alembic revision --autogenerate -m "describe change" && cd ..
Never trust autogenerated output blindly. Verify:
Either local uv path or container path is acceptable in this repo. Prefer consistency with your current flow.
cd backend && uv run alembic upgrade head && cd ..
or
docker compose exec backend alembic upgrade head
cd backend && uv run bash scripts/prestart.sh && cd ..
cd backend && uv run bash scripts/tests-start.sh && cd ..
cd backend && uv run coverage report --fail-under=90 && cd ..
cd backend && uv run bash scripts/lint.sh && cd ..
If API schemas changed (request/response models, OpenAPI output), regenerate frontend client:
bash ./scripts/generate-client.sh
Update docs based on what changed:
If no docs changed, explicitly document why.
Use alter/rename operations, not drop+add, when intent is a rename.
Telemetry-style tables can be large. Favor migration steps that avoid unnecessary full rewrites or destructive rebuilds.
Before concluding complex migrations, validate downgrade path:
docker compose exec backend alembic downgrade -1
docker compose exec backend alembic upgrade head