Database Migration Workflow
Steps
- 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
Conventions
- Migration message format: descriptive snake_case
- Always include downgrade() implementation
- For production: test migration on staging data first
Source: sandk0/fancai — distributed by TomeVault.