← ClaudeAtlas

alembic-migrationslisted

Alembic migration setup and patterns for async SQLAlchemy — async engine + run_sync in env.py, autogenerate, RLS/multi-tenant migrations. Use for alembic init, writing migrations, or debugging migration errors.
ajyadav013/claude-kit · ★ 12 · AI & Automation · score 72
Install: claude install-skill ajyadav013/claude-kit
# Alembic Migrations Alembic migration patterns for async SQLAlchemy (asyncpg) from production FastAPI services. ## When to use - Setting up Alembic in a new async SQLAlchemy project (initial migration setup, alembic init) - Writing database migrations (table creation, column changes, constraints, indexes, foreign keys) - Configuring `alembic.ini` and `env.py` for async engines (asyncpg, postgresql+asyncpg) - Implementing autogenerate workflow for model changes (alembic revision --autogenerate) - Adding Row-Level Security (RLS) policies in migrations (multi-tenant isolation, tenant_id filtering) - Filtering out internal/heartbeat tables from autogenerate (include_object callback) - Debugging migration issues (compare_type, down_revision chains, "can't locate revision", "multiple heads", "target database not up to date") - Converting sync migrations to async (async_engine_from_config, connection.run_sync) - Handling migration conflicts in large teams (timestamp-hash revision naming) - Creating data migrations (seed data, backfill columns, complex transformations) ## Core conventions ### Alembic Setup (async SQLAlchemy) **alembic.ini location and URL**: Place `alembic.ini` at project root; leave `sqlalchemy.url` empty (set dynamically in `env.py` from settings). _(observed across multiple production services)_ **env.py async pattern**: Use `async_engine_from_config` + `connection.run_sync(do_run_migrations)` + `asyncio.run(run_async_migrations())` in `run_migrations_onli