Home / Companies / Mergify / Blog / Post Details
Content Deep Dive

We fixed Alembic's multiple-heads error with Git history

Blog post from Mergify

Post Details
Company
Date Published
Author
-
Word Count
890
Language
English
Hacker News Points
-
Summary

Julien Danjou's blog post discusses a solution to the common issue of Alembic's multiple-heads error, which occurs when parallel migrations result in conflicting database histories. By leveraging Git's ability to track the order of file commits, the team developed a library called alembic-git-revisions to dynamically determine the down_revision for each migration, thus eliminating the need for hardcoded guesses. This approach ensures that migration histories remain linear and avoids the frequent occurrence of empty merge migrations. The solution has been successfully implemented in production, reducing errors and maintaining compatibility with existing migrations. Additionally, the library can handle environments where Git history is unavailable by pre-computing migration chains. This method parallels the concept of a merge queue, which tests changes in the actual order they occur, providing a reliable source of truth for both code and database migrations.