Building on top of @dimmg's answer:
You can overwrite the sqlalchemy.url
specified in alembic.ini
in the env.py
file.
Single Database
env.py
Insert
config.set_main_option('sqlalchemy.url', <db_uri>)
where <db_uri> can be loaded from the environment or config file.
Multi-Database
env.py
Assuming you a have multi-database setup with databases db_a
and db_b
, insert
config.set_section_option('db_a', 'sqlalchemy.url', <db_uri_a>)
config.set_section_option('db_b', 'sqlalchemy.url', <db_uri_b>)
where <db_uri_a> and <db_uri_b> are the database URI for db_a
and db_b
, respectively, and can be loaded from the environment or config file.
Note
Make sure to also indicate in the alembic.ini
file that the parameters specified there are overwritten in in the env.py
file. The section in which the sqlalchemy.url
s are specified could even be removed entirely for all DB's for which the URI is overwritten in env.py
.
This will hopefully save you or collaborators some confusion when returning to the project later.
sqlalchemy.url = $(DB_SERVICE):/$(DB_USER):$(DB_PASS)@$(DB_HOST)/$(DB_NAME)
– HighamsFlask-Migrate
is compatible only withFlask-SQLAlchemy
– Highamssqlachemy.url
inenv.py
instead? – Pitiful