Hacker News new | ask | show | jobs
by ggregoire 2797 days ago
Same here. Our backend team uses Python, SQLAlchemy and PG. They are looking for a tool to handle migrations and schema versionings. Any recommendations?
2 comments

Alembic. It's made by zzzeek (Mike Bayer), who created SQLA and it's hackable to do custom migrations.

We use it by changing the models in code and then having Alembic automatically create a suitable migration for us. Then we change the migration as required (adding steps for data migrations etc). It's really simple:

    alembic revision --autogenerate -m 'changing something...'
That generates a python file with an upgrade and downgrade function. You can then customise fully as you require.

Then on the db server you can run:

    alembic upgrade head  # or downgrade etc
We use the "forward only" approach, and use a combination of .sql and .py migration scripts and use mschematool[1] to tie the room together.

[1] https://github.com/aartur/mschematool