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?
You need to ensure that you perform each version of migration with all database credentials, you can write your own migration script in order to do it in one go.
Alembic provides a set of command functions to let you synchronize your ORM models with the database(s) programmatically. You can invoke
command.upgrade(...)andcommand.downgrade(...)in your script.For example, you have 2 databases
DB1andDB2mapped to the same set of ORM models inmodels.py, the migration script looks like :