Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Database migrations in Flask without SQLAlchemy

Is there any library or tool to perform database migrations in python without SQLAlchemy? I am using a PostgreSQL database and the queries are raw SQL. I use psycopg2 for the database connection.

like image 459
Yosry Avatar asked Mar 10 '26 14:03

Yosry


1 Answers

There are several tools that can be used to version your database with migrations in Python, outside of SQLAlchemy. I can't speak for any of them in particular, so I looked for ones that seem to have some adoption as well as active maintainence.

(as of Apr 14, 2023)

Tool GitHub Stars Maintained Notes
pgmigrate yandex/pgmigrate 562 Feb 3 2023 Postgres only
dbmate amacneil/dbmate 3.3k Mar 2023
Yoyo coobas/yoyo-migrations 0 Mar 2020
Migrate golang/migrate 11.2k Apr 2023 go-lang library & CLI tool

Other resources I've found seem to be tied to one framework or another. Searching the package index turns up a lot of older resources.

If one finds pgmigrate or dbmate to be undesirable, then from there it might be worth asking whether the migration tool really needs to be Python-specific. Typically migrations are a part of the build process and (in my opinion) ideally should require as little coding and configuration as possible.

Juan D. Vega's post, Language and framework agnostic database migrations, highlights the golang/migrate CLI tool, which attempts to offer a way to manage your migrations irrespective of the particulars of the application that the database supports.

like image 103
Tyler Gannon Avatar answered Mar 13 '26 03:03

Tyler Gannon