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 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.
- https://github.com/amacneil/dbmate
- https://pypi.org/project/yoyo-migrations/
- https://pypi.org/project/alembic/
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.
flask-migrate? - Rohitpsycopg2is db connection api, withpsycopg2you have to operate on the database using the standard sql commands, howeverflask-SQLAlchemyis an ORM wrapper built aroundSQLAlchemyand gives you a pythonic interface to the database, so if you want to truly manage a database using python you should be usingSQLAlchemyorflask-SQLAlchemy. The actual migration library in python isalembicandflask-migrateis a convenient wrapper built overalembic. - Rohitalembicgenerates 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.alembicin combination withflask-migratemakes this task very easy. - Rohit