fix: sort hybrid migrations after their target to prevent multiple heads#14
Conversation
Merge ProtectionsYour pull request matches the following merge protections and will not be merged until they are valid. 🟢 🤖 Continuous IntegrationWonderful, this rule succeeded.
🟢 👀 Review RequirementsWonderful, this rule succeeded.
🟢 Enforce conventional commitWonderful, this rule succeeded.Make sure that we follow https://www.conventionalcommits.org/en/v1.0.0/
🟢 🔎 ReviewsWonderful, this rule succeeded.
🟢 📕 PR descriptionWonderful, this rule succeeded.
|
There was a problem hiding this comment.
Pull request overview
This PR fixes an Alembic migration ordering edge case where a later-merged “hybrid” (static down_revision pointing to a dynamic revision) could cause the dynamic chain builder to produce multiple heads. The fix adjusts ordering so hybrids are placed immediately after their dynamic target, preventing concurrent-branch insertions from forking the chain.
Changes:
- Add a regression test covering the “dynamic inserted before hybrid” multiple-heads scenario.
- Update dynamic participant sorting so hybrids are ordered by their target’s
git_sequencerather than their own.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
alembic_git_revisions/_chain.py |
Changes sort order in _build_dynamic_chain to place hybrid migrations right after their dynamic target revision. |
tests/test_chain.py |
Adds a regression test ensuring the chain avoids multiple heads when a dynamic migration appears in git order before a later-merged hybrid. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
When two branches fork from the same dynamic head and one adds a dynamic migration while the other adds a hybrid (static with hardcoded down_revision), the first-merged dynamic and the later-merged hybrid both pointed to the same predecessor, creating a fork and MultipleHeads. Fix by sorting hybrids by their target's git_sequence instead of their own, placing them immediately after their target in the chain. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> Change-Id: I3b68dc315a9abaa0cb76c90951b2d8e4d9a663b4 Claude-Session-Id: f2902019-6258-4c62-9887-f23b8128665f
19b3c4a to
74e157c
Compare
Merge Queue StatusRule:
This pull request spent 8 seconds in the queue, with no time running CI. Required conditions to merge
|
When two branches fork from the same dynamic head and one adds a
dynamic migration while the other adds a hybrid (static with hardcoded
down_revision), the first-merged dynamic and the later-merged hybrid
both pointed to the same predecessor, creating a fork and MultipleHeads.
Fix by sorting hybrids by their target's git_sequence instead of their
own, placing them immediately after their target in the chain.
Co-Authored-By: Claude Opus 4.6 noreply@anthropic.com