You can configure Alembic to run migrations on two separate PostgreSQL databases in a single alembic upgrade head command by modifying the env.py script. Here's the approach:
-
Modify
env.pyto Manage Multiple Engines:- Create two separate SQLAlchemy engines (one for each database) inside the
env.pyscript. - Ensure that migrations are applied to both databases.
- Create two separate SQLAlchemy engines (one for each database) inside the
-
Use
run_migrations_onlinefor Both Databases:- Instead of a single
engine, define and use two engines. - Use
context.run_migrations()for each engine.
- Instead of a single