Search code examples
sqlalchemyalembic

Alembic few modules to single database


We need to build a large application that split to multiple modules,

App
  - Module1    --> AppDb
  - Module2    --> AppDb
  - Module3    --> AppDb

Each module, we would like to add alembic version, all modules connect to single database. But we cannot add revision, because it's conflict to other module's revision (because all version store in same table alembic_version, so the migrations conflict with each other).


Solution

  • If you're using separate simple migrations in each of Module1, Module2 and Module3 each with their own env.py (or similar), the solution could be to use the version_table argument to context.configure, that allows you to override the name of the version table.

    i.e. modify the env.py to something like

    context.configure(
        connection=connection,
        target_metadata=target_metadata,
        version_table='alembic_module1_version'
    )