← BackCreate and run database migrations for fancai. Use when changing database schema, adding columns, creating tables, or modifying SQLAlchemy models.
- Analyze Change: Understand what schema change is needed
- Update Model: Modify SQLAlchemy model in
backend/app/models/
- Update Schema: Modify Pydantic schema in
backend/app/schemas/
- Generate Migration:
cd backend && alembic revision --autogenerate -m "$ARGUMENTS"
- Review Migration: Read the generated migration file, verify:
- Correct upgrade() and downgrade() operations
- No data loss in downgrade
- Proper index creation
- Test Migration:
cd backend && alembic upgrade head
- Verify: Run backend tests
cd backend && uv run python -m pytest -v --tb=short
- Migration message format: descriptive snake_case
- Always include downgrade() implementation
- For production: test migration on staging data first