Guide for creating and running database migrations. Use when asked to modify database schema, add tables or change columns.
Use Alembic's autogenerated template for new migrations. It includes both upgrade() and downgrade() functions, which should be implemented to ensure reversible migrations.
This skill documents the minimal, repository-specific instructions for creating and applying database migrations for the Task Tracker API using Alembic and the project's uv wrapper.
All commands assume you're in the backend folder.
Create an autogenerated migration:
cd backend
uv run alembic revision --autogenerate -m "describe change here"
Apply migrations to the current DB:
cd backend
uv run alembic upgrade head
Rollback last migration (downgrade one step):
cd backend
uv run alembic downgrade -1
View migration history:
cd backend
uv run alembic history --verbose
alembic upgrade head to prepare schema before running tests.alembic/env.py imports the models or the metadata object used by SQLAlchemy.backend/alembic/versions.backend/app/database.py.Follow the commands above for routine migration work. If you want, I can add a small Makefile target or CI job snippet to automate these steps.