---
name: "alembic-database-migration-branches"
description: "Manage schema migrations for SQLAlchemy and SQLModel with autogeneration and branching."
metadata:
  author: "SQLAlchemy"
  version: "1.0.0"
  runtime_compatibility:
    - "codex"
    - "claude-code"
    - "cursor"
    - "windsurf"
triggers:
  - "alembic revision autogenerate"
  - "alembic upgrade head"
  - "resolve alembic merge branches"
permissions:
  fs_read: true
  fs_write: "workspace"
  shell_exec: false
  net_access: false
---

# Alembic Database Migrations & Version Branching

Configures Alembic: env.py configuration, autogenerating migration scripts from model metadata (alembic revision --autogenerate), merging concurrent branches (alembic merge), upgrade/downgrade, and offline SQL generation.

## When to Invoke
Invoke this skill whenever you need to:
- alembic revision autogenerate
- alembic upgrade head
- resolve alembic merge branches

## Execution SOP & Rules
1. Initialize: alembic init alembic.
2. Point target_metadata in alembic/env.py to Base.metadata or SQLModel.metadata.
3. Generate migration: alembic revision --autogenerate -m 'add user status column'.
4. Apply migrations: alembic upgrade head (or inspect SQL with alembic upgrade head --sql for offline review).

## Verification Checklist
- Run local linting, syntax validation, and type-checks before reporting completion.
- Ensure all created or modified files adhere to workspace boundaries and avoid uncommitted secrets.
- Verify tests or build commands exit cleanly with return code 0.
