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.py
to Manage Multiple Engines:- Create two separate SQLAlchemy engines (one for each database) inside the
env.py
script. - Ensure that migrations are applied to both databases.
- Create two separate SQLAlchemy engines (one for each database) inside the
-
Use
run_migrations_online
for Both Databases:- Instead of a single
engine
, define and use two engines. - Use
context.run_migrations()
for each engine.
- Instead of a single