nickjj / flask-db

A Flask CLI extension to help migrate and manage your SQL database.
MIT License
76 stars 6 forks source link

Wrap and forward db migrate to alembic commands #1

Closed nickjj closed 3 years ago

nickjj commented 3 years ago

I'm all for using Alembic directly because it's the official database migration tool provided by the same folks who make SQLAlchemy.

From a usability perspective I like the idea of directly calling alembic commands because it means you can follow Alembic's tutorials and documentation straight up. I've been doing this for the last 5+ years and it works out nicely in practice.

But I also really like the idea of being able to run flask db migrate as an alias to alembic just so all of the database related commands are under the same roof. Unlike other extensions that use Alembic under the hood, this new migrate command wouldn't do anything except forward any arguments and options from flask db migrate over to alembic.

Examples of what I would like in a perfect world:

flask db migrate -> alembic upgrade head
flask db migrate revision -m "create account table" -> alembic revision -m "create account table"
flask db migrate --help -> alembic --help

The basic rules would be:

Where I'm getting stuck

Click's documentation has this based on forwarding unknown options: https://click.palletsprojects.com/en/7.x/advanced/#forwarding-unknown-options

But I couldn't get it to work. It wouldn't pass flags with -- and it also required wrapping all of the forwarded options / arguments in a string, so you would have to run things like flask db migrate "revision -m 'create account table'".

I'm not really sure how to do this. I tried a bunch of things unsuccessfully.

Little help!

nickjj commented 3 years ago

This behavior has been added to version 0.2.0.