Working with migrations
Database migrations let you version control your database schema and keep it consistent across environments. They also help you automate the deployment of your database changes and track the history of your schema evolution.
The recipe shows you how to use Alembic, a popular tool for managing database migrations in Python. You will learn how to create, run, and roll back migrations and how to integrate them with your ticketing system.
Getting ready
To use the recipe, you need to have alembic
in your environment. You can install it with pip,
if you didn’t do it with the requirements.txt
file from the GitHub repository, by typing this on the command line:
$ pip install alembic
You also need to make sure you have at least one class that corresponds to the table in the database you want to create. If you don’t have one, go back to the Setting up SQLAlchemy recipe and make one. If you’re already running the application, delete the...