alembiclisted
Install: claude install-skill aiskillstore/marketplace
# Alembic Database Migrations
Alembic is a database migration tool for SQLAlchemy projects that provides version control for your database schema.
## Quick Start
### Create Migration (Autogenerate)
```bash
# Generate migration from model changes
uv run alembic revision --autogenerate -m "Add user table"
# Check if there are pending changes
uv run alembic check
```
### Apply Migrations
```bash
# Upgrade to latest version
uv run alembic upgrade head
# Upgrade to specific revision
uv run alembic upgrade ae1027a6acf
# Downgrade one revision
uv run alembic downgrade -1
# Downgrade to base (empty schema)
uv run alembic downgrade base
```
### Check Status
```bash
# Show current database revision
uv run alembic current
# Show all revision history
uv run alembic history
# Show revision details
uv run alembic show ae1027a6acf
```
## Common Patterns
### Autogenerate Configuration
**env.py setup for async SQLAlchemy:**
```python
import asyncio
from logging.config import fileConfig
from sqlalchemy import pool
from sqlalchemy.ext.asyncio import async_engine_from_config
from alembic import context
# Import your models
from app.models import Base
from app.config import get_settings
config = context.config
settings = get_settings()
# Configure database URL for async
database_url = settings.database_url.replace("postgresql://", "postgresql+asyncpg://")
config.set_main_option("sqlalchemy.url", database_url)
target_metadata = Base.metadata
async def run_async_migrations():