Skip to content

Latest commit

 

History

History
43 lines (28 loc) · 1.01 KB

README.md

File metadata and controls

43 lines (28 loc) · 1.01 KB

Alembic

From the docs:

Alembic is a lightweight database migration tool for usage with the SQLAlchemy Database Toolkit for Python.

It allows us to generate database schemas from Python SQLAlchemy code, found in each models.py file.

Usage

Here are some of the most commonly used commands you might need.

Automatically generate a revision script after modifying database models in Python:

alembic revision --autogenerate -m "my_revision_name"

Make sure to review the generated script in alembic/versions and make adjustments if needed.

Run a migration: this will upgrade the database schema to the most recent revision.

alembic upgrade head

Undo the most recent revision:

alembic downgrade -1

Reset the database to its initial (empty) state:

alembic downgrade base

For more examples, see the official Alembic tutorial.