Alembic

  • backend
  • shipped in 1 project

Alembic is the migration tool that comes with SQLAlchemy, and once you start using it you wonder how you ever managed database schema changes without it. Before Alembic, I was the kind of person who would just modify tables by hand and hope nothing broke. That stops being an option the moment your project has more than one environment.

The autogenerate feature is what sold me: you update your SQLAlchemy models, run a command, and Alembic diffs the models against the actual database and writes the migration script for you. It's not always perfect, especially with complex constraints or renamed columns, but it gets you 90% of the way there. I learned to always review the generated scripts before running them, the hard way.

It's one of those invisible tools that doesn't get much glory. Nobody looks at a project and says "wow, nice migrations." But the moment you need to roll back a bad deploy or sync a teammate's database to the latest schema, you're very glad it's there.