Command-line migrations for SQLAlchemy projects: versioned upgrade and downgrade scripts, autogenerate drafts, and SQL script output.
Overview
Alembic is a migrations tool aligned with SQLAlchemy. It applies ALTER-style changes to databases and organizes work as ordered migration scripts, each defining steps to move a schema forward and optionally reverse them.
New environments boot from templates that wire database connectivity and script invocation. Migrations can run inside transactions on databases that support transactional DDL, which simplifies testing failed upgrades. Simple schema edits can use one-line helpers for renames, columns, and constraints without hand-writing full table definitions.
The autogenerate workflow compares live database state to Python models and drafts a new revision for the developer to edit. Teams that need DBA-reviewed SQL can emit migrations as text files instead of applying them directly. Versioning uses UUID-like script identities and explicit dependencies so histories can branch, merge, and form directed acyclic graphs rather than a single linear chain.
DDL helpers are usable outside Alembic’s CLI, and batch migrations address SQLite’s limited ALTER support by staging table rebuilds. Data-oriented helpers aim to stay compatible with offline SQL generation.
Key features
- Upgrade and downgrade migration scripts
- Template-based environment bootstrap
- Transactional DDL where supported
- Schema autogenerate from SQLAlchemy models
- Offline SQL script generation
- Branching and mergeable revision graphs
- One-line ALTER helper operations
- SQLite batch table rebuild workflow
Use cases
- Evolving SQLAlchemy application schemas
- Shipping SQL files for DBA review
- Branching migration histories across teams
- Managing SQLite schema changes safely