# DB Migrate

> Create and run database migrations for fancai. Use when changing database schema, adding columns, creating tables, or modifying SQLAlchemy models. Use when this capability is needed.

- Skill: `tomevault-io/db-migrate` (Agent Skill, multi-file: 2 files)
- Install (CLI): `npx skillmds@latest add tomevault-io/db-migrate`
- Raw SKILL.md: https://api.skillmd.com/api/skills/tomevault-io/db-migrate/raw
- Safety review: pending (external: skill-scanner PASS, skillspector PASS)
- Works with: Claude Code, Claude.ai, OpenAI Codex
- Category: Coding & Dev Tools
- Author: tomevault-io (https://skillmd.com/u/tomevault-io)
- Updated: 2026-09-17
- Page: https://skillmd.com/skills/tomevault-io/db-migrate

---


# Database Migration Workflow

## Steps

1. **Analyze Change**: Understand what schema change is needed
2. **Update Model**: Modify SQLAlchemy model in `backend/app/models/`
3. **Update Schema**: Modify Pydantic schema in `backend/app/schemas/`
4. **Generate Migration**: `cd backend && alembic revision --autogenerate -m "$ARGUMENTS"`
5. **Review Migration**: Read the generated migration file, verify:
   - Correct upgrade() and downgrade() operations
   - No data loss in downgrade
   - Proper index creation
6. **Test Migration**: `cd backend && alembic upgrade head`
7. **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](https://github.com/sandk0/fancai) — distributed by [TomeVault](https://tomevault.io).
<!-- tomevault:4.0:skill_md:2026-05-29 -->

