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:
If you call flask db migrate with no arguments it defaults to passing upgrade head to alembic
If you call flask db migrate with any arguments or options, it passes them directly as is to alembic
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.
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 toalembic
just so all of the database related commands are under the same roof. Unlike other extensions that use Alembic under the hood, this newmigrate
command wouldn't do anything except forward any arguments and options fromflask db migrate
over toalembic
.Examples of what I would like in a perfect world:
The basic rules would be:
flask db migrate
with no arguments it defaults to passingupgrade head
toalembic
flask db migrate
with any arguments or options, it passes them directly as is toalembic
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 likeflask 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!