Alembic is a lightweight migration tool for SQLAlchemy applications. It records database schema changes as ordered revision scripts, allowing a relational database to be upgraded or downgraded reliably. section 23.4.2 section 23.9
A practical Alembic workflow is:
- Initialize an environment with alembic init alembic, then set sqlalchemy.url in alembic.ini to the application database. section 23.4.2
- Create a revision with alembic revision -m, which generates a versioned script containing revision metadata and upgrade() and downgrade() functions. section 23.4.2
Creating and reversing an address table
A revision can call op.create_table() with integer and string columns, primary-key and non-null constraints, then call op.drop_table('address') during downgrade. After upgrade head, the schema contains alembic_version, people, and address; after downgrade -1, address is removed.
