Handling multiple merge heads in Alembic migrations #1696
-
Hi, I’ve encountered a situation where I had to merge multiple Alembic heads, but after that, the heads diverged again. I managed to fix it by deleting the previous merge revision and creating a new one, as long as I didn’t create any new revisions after the original merge. However, I wonder if there’s a simpler or more straightforward way to avoid dealing with multiple merge heads repeatedly. Something like “basing” or a simpler approach, but I haven’t found anything clear in the Alembic docs yet. Does Alembic support any alternative workflow or command to handle this more efficiently? I’d appreciate any insights or guidance. Thanks! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Hi, I don't think there is anything integrated in alembic, but you can create another merge migration if you prefer. Regarding alternative workflow, at work we usually manually "rebase" migrations. We found that this workflow tends to work fine for the most part, assuming migrations do not overlap too much where you would need a merge migration to harmonize them. |
Beta Was this translation helpful? Give feedback.
Hi,
I don't think there is anything integrated in alembic, but you can create another merge migration if you prefer.
Regarding alternative workflow, at work we usually manually "rebase" migrations.
Say you have this case: two feature branches create a new migrations in parallel, both starting from
Mx
, for exampleMx -> Ma
andMx -> Mb
. After one of the feature branches is merged, let's say the one with migrationMb
, we would merge develop into the remaining feature branch and "rebase"Ma
to be afterMb
, so that the actual migrations history once merged in develop would beMx -> Mb -> Ma
. This is done manually by modifying thedown_revision
ofMa
to point toMb
instead ofMx
.We found that…