In the previous chapter, we learned how to create and apply migrations, and in this chapter we’re going to discuss how to further control Alembic. We’ll explore how to learn the current migration level of the database, how to downgrade from a migration, and how to mark the database at a certain migration level.
Before performing migrations, you should double-check to make sure what migrations have been applied to the database. You can determine what the last migration applied to the database is by using the
alembic current command. It will return the revision ID of the current migration, and tell you whether it is the latest migration (also known as the head). Let’s run the
alembic current command in the CH12/ folder of the sample code for this book:
# alembic current
While this output shows that we are on migration
2e6a6cc63e9, it also tells us we are on the head or latest migration. This was the migration that changed the
cookies table to
new_cookies. We can confirm that with the
alembic history command, which will show ...