Within Flask i have setup SQLAlchemy to use multiple databases which are selected upon request as described in https://quanttype.net/posts/2016-03-15-flask-sqlalchemy-and-multitenancy.html
So SQLAlchemy is configured with SQLALCHEMY_BINDS to redirect an incomming request to the correct database.
I'm trying to get Alembic working with multiple databases. Eg. the models in models.py should be identical in all databases.
SO far as i can tell alembic multidb only works with the bind_key in the models to specify which table should be created in which database, but i want to create all tables in all databases in one go. How do i do that?
Alembic provides a template to work with multiple databases:
For your particular use case:
1 - Modify
alembic.ini
with your database names and SQLAlchemy URLsNote: if you don't want to expose the passwords, generate the SQLAlchemy URLs at runtime in
env.py
instead.2 - Point all
target_metadata
inmultidb/env.py
to the same modelNote: If you have many databases, probably it's better to do this programmatically.
3 - Test the Alembic setup