alembic how to merge all revision files to one file?
Question:
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?
Answers:
If you have all the models in models.py (or whatever you use for models), it should be possible to achieve your goal by recreating migrations in a single file. Like this:
- Point Alembic to a different and empty database
- run
alembic revision --autogenerate
- You’ll get the mirroring revision in a single file.
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.
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?
If you have all the models in models.py (or whatever you use for models), it should be possible to achieve your goal by recreating migrations in a single file. Like this:
- Point Alembic to a different and empty database
- run
alembic revision --autogenerate
- You’ll get the mirroring revision in a single file.
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.