alembic how to merge all revision files to one file?


There are more than 100 files in alembic version directory. How to use alembic command to merge these file into a one file?

I am try to use this:

alembic revision --autogenerate

but doesn’t work! Anyone has good idea?

Asked By: pangpang



If you have all the models in (or whatever you use for models), it should be possible to achieve your goal by recreating migrations in a single file. Like this:

  1. Point Alembic to a different and empty database
  2. run alembic revision --autogenerate
  3. You’ll get the mirroring revision in a single file.
Answered By: Igor

I know that Miguel will kill me, but I always start alembic with an empty model and alembic script. When I want to consolidate I roll back to this one, remove the other migration scripts and create a new migration script that only contains what is currently in the model.

Miguel suggests merging the files by hand. This is a great option, but depending on the dev it could be very error prone as well as difficult to cancel some things out as needed.

Answered By: heplat
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.