---
name: create-migration
description: Create an Alembic migration with auto-detected model changes. Use when creating database migrations.
user-invocable: false
argument-hint: [migration-name]
---

Create Alembic migration: $ARGUMENTS

## Migration Context (Auto-Detected)

- **Current Revision**: !`alembic current 2>/dev/null | head -1 || echo "No current revision"`
- **Recent Model Changes**: !`git diff --name-only HEAD~5 2>/dev/null | grep -E 'models|schema' | head -5 || echo "No recent model changes detected"`
- **Python Version**: !`python --version 2>/dev/null || echo "Python 3.x"`
- **Alembic Version**: !`alembic --version 2>/dev/null || echo "Alembic not found"`

## Your Task

Create an Alembic database migration for: **$ARGUMENTS**

Review the auto-detected migration context above, then customize the template below with your schema changes and rollback logic.

## Migration Template

```python
"""$ARGUMENTS

Revision ID: !`date +%Y%m%d%H%M%S`
Revises: !`alembic current 2>/dev/null | awk '{print $1}' || echo "None"`
Create Date: !`date "+%Y-%m-%d %H:%M:%S"`

"""
from typing import Sequence, Union

from alembic import op
import sqlalchemy as sa

# revision identifiers, used by Alembic.
revision: str = '!`date +%Y%m%d%H%M%S`'
down_revision: Union[str, None] = !`alembic current 2>/dev/null | awk '{print $1}' || echo "None"`
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None


def upgrade() -> None:
    # ### commands auto generated by Alembic - please adjust! ###
    # Add your migration logic here
    pass
    # ### end Alembic commands ###


def downgrade() -> None:
    # ### commands auto generated by Alembic - please adjust! ###
    # Add your rollback logic here
    pass
    # ### end Alembic commands ###
```

## Usage

1. Review detected model changes above
2. Fill in `upgrade()` with your schema changes
3. Fill in `downgrade()` with rollback logic
4. Run: `alembic upgrade head`
