I want to implement tool that will manage migrations from several apps in my project using alembic. With following structure
apps
+- app1
| +- alembic
| | +- versions
| | | +- 0000_initial.py
| | +- __init__.py
| | +- env.py
| | +- script.py.mako
| +- __init__.py
| +- models.py
| +- alembic.ini
+- app2 (same structure as app1)
I wrote script that goes through each app, generates migrations or applies them. For every app different alembic_version table is used. For example app1_alembic_version
, app2_alembic_version
and etc. When I generate initial migrations and applies them everything ok, but when I try to generate second migration conflict appears, because first app see tables that was generated for second app and tries to delete them, same happens with second app.
So, the question what is the best way to manage migrations from different apps using one schema but different migration tables? Maybe there is way to collect tables from other apps and skip them for current app migration.
Example of my code:
for app_name, app in self._get_alembic_apps().items():
config = Config(app.path + "/alembic.ini")
dsn = "postgresql://admin:admin@localhost/test"
config.attributes["version_table_name"] = app_name + "_alembic_version"
engine = create_engine(dsn)
with engine.begin() as conn:
config.attributes['connection'] = conn
command.revision(config, message="test", autogenerate=True)