Overview of Alembic database migrations
mainAlembic is a database migrations tool designed for SQLAlchemy applications. It provides a system for managing database schema changes through 'migration scripts' that can 'upgrade' a database to a new version or 'downgrade' it by reversing the steps.
Key capabilities include:
- ALTER statement emission: Automatically generates DDL to change table structures and other constructs.
- Transactional DDL support: For databases like PostgreSQL and Microsoft SQL Server, migrations can run within a transaction, allowing for automatic rollback upon failure.
- Minimalist script construction: Use high-level commands like
alter_column(),rename_table(), andadd_constraint()to perform operations without recreating full SQLAlchemy Table structures. - Autogeneration: The
--autogeneratefeature inspects the current database state via SQLAlchemy's schema inspection and compares it to your Python models to generate 'candidate' migration scripts. - SQL script support: Migrations can be output as textual SQL scripts for environments where direct DDL execution is restricted.
- Non-linear versioning: Uses a directed-acyclic graph (DAG) model for versioning, allowing for branches, multiple roots, and mergepoints using UUID identifiers.
- SQLite support via Batch migrations: Accommodates SQLite's limited
ALTERcapabilities using a 'batch' migration concept, which uses a 'move-and-copy' workflow to apply multiple changes to a table.