Database migrations in Flask without SQLAlchemy

Question:

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.

Asked By: Yosry

||

Answers:

In short, “yes.”

There are numerous possibilities. The one you choose will depend on doing some homework to determine which one best suits your needs.

Suggest when asking questions that can be answered with a google search, to be more specific about your situation, to help answerers to understand why Google couldn’t answer your question in the first page of results.

Answered By: Tyler Gannon

If you can bring yourself to do your db migrations outside of the CLR, I’d strongly recommend considering FlyWay. It has been around forever, it’s supported by RedGate, and the community version is free and open source. It has built-in support for all the major db platforms and installs like any other utility you’d use. For a Python app you’d do all of your db migrations via shell scripts or process calls instead of directly in the code.

My team settled on this tech because:

  1. Yoyo is pretty immature and buggy for us
  2. We don’t use SQLAlchemy’s OR framework
  3. Alembic’s syntax and framework seems pretty heavyweight for us
  4. Under FlyWay’s model we just write SQL scripts and check them into a directory. It’s really lightweight.
  5. It’s been proven to work nicely in clustered environments

Give it a look.

Answered By: Jonathan Blackburn