1
votes

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.

1
you mean migrations without using flask-migrate ? - Rohit
psycopg2 is db connection api, with psycopg2 you have to operate on the database using the standard sql commands, however flask-SQLAlchemy is an ORM wrapper built around SQLAlchemy and gives you a pythonic interface to the database, so if you want to truly manage a database using python you should be using SQLAlchemy or flask-SQLAlchemy. The actual migration library in python is alembic and flask-migrate is a convenient wrapper built over alembic. - Rohit
I know but I am working in a project already not using SQLAlchemt and I need to implement database migration. Any suggestions? - Yosry
you will have to use alembic and run the migration scripts by yourself manually. - Rohit
alembic generates the migration scripts for you, it hides the enormous amount of complexity of updating a schema for an existing table in the database. Updating schema of existing tables in the database is a very complex operation and requires careful planning for tables with large number of columns and imagine if you have to do such thing frequently it is even cumbersome. alembic in combination with flask-migrate makes this task very easy. - Rohit

1 Answers

3
votes

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.