fix: linearize alembic migration chain to resolve forked 018 revision #181
No reviewers
Labels
No labels
domain:backend
domain:devops
domain:frontend
status:approved
status:in-progress
status:needs-fix
status:qa
type:bug
type:devops
type:feature
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
forgejo_admin/basketball-api!181
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "fix/179-alembic-forked-chain"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
alembic upgrade headfails at revision 018 -- both 019 and 020 haddown_revision = "018", creating a fork alembic cannot traverse from a single DB stampChanges
alembic/versions/020_add_custom_notes_to_player.py: changeddown_revisionfrom"018"to"019", eliminating the fork at 018alembic/versions/022_merge_heads.py: converted from merge migration (down_revision = ("019", "021")) to linear passthrough (down_revision = "021"), since the fork no longer existsTest Plan
python -m pytest tests/ -v)ruff checkandruff formatpass on both modified fileskubectl exec -n basketball-api <pod> -- alembic upgrade headsucceedsSELECT version_num FROM alembic_versionreturns0241/1 Runningwithout CrashLoopBackOffReview Checklist
Related Notes
Review: LGTM
Diff scope: 2 files, +9/-9 lines. Migration-only change, zero application code touched.
Verification
001 -> ... -> 018 -> 019 -> 020 -> 021 -> 022 -> 023 -> 024down_revisionvalues is safe -- alembic will traverse the new linear chain on nextupgrade head005 -> e09c9e678004 -> 007)Findings
No issues found. Minimal, correct fix for a live outage.
PR #181 Review
DOMAIN REVIEW
Tech stack: Python / Alembic (SQLAlchemy migrations)
Critical verification -- migration chain linearity:
I traced every
down_revisionfrom 001 through 024. The full chain post-fix is:Single head at 024. Zero forks. Fully linear. Verified by reading every migration file's
down_revisionvalue.Critical verification -- e09c9e678004 untouched:
e09c9e678004_add_division_column_to_players.pyis NOT in the PR diff. File contents confirmed unchanged (down_revision = '005',revision = 'e09c9e678004'). No catastrophic risk.The fix itself:
020_add_custom_notes_to_player.pydown_revision = "018"down_revision = "019"022_merge_heads.pydown_revision = ("019", "021")down_revision = "021"The 022 migration is correctly converted to a no-op passthrough with
passin bothupgrade()anddowngrade(). This preserves revision numbering continuity without introducing any schema changes.Docstring accuracy: The 022 file's docstring accurately describes the linearized chain:
018 -> 019 -> 020 -> 021 -> 022. This matches what I verified in the files.Import ordering in 022: The PR swaps the import order from
from alembic import op; import sqlalchemy as satoimport sqlalchemy as sa; from alembic import op. This follows PEP 8 (stdlib-style before third-party,importbeforefrom). Both have# noqa: F401since they are unused in the passthrough -- correct.Data safety: PR body correctly notes that migrations 019-024 have not been applied to prod (DB stamped at 018). This means the
down_revisionchanges have zero data impact -- alembic will simply traverse the corrected chain on nextupgrade head.BLOCKERS
None.
This is a metadata-only fix (migration chain pointers). No new functionality is added, so no new test coverage is required. The existing 568 tests passing confirms no regression. The chain verification script described in the Test Plan is the appropriate validation for this type of fix.
NITS
None. The diff is minimal and surgical -- exactly what a critical production fix should look like.
SOP COMPLIANCE
fix/179-alembic-forked-chainreferences #179)Closes #179)PROCESS OBSERVATIONS
DORA impact: This is a MTTR (Mean Time to Recovery) event. The app is in CrashLoopBackOff -- a live outage. The fix is correctly scoped to the minimal change needed: two
down_revisionpointer corrections. No scope creep into "while we're here" improvements.Blocked PRs: PR body correctly identifies three PRs blocked by this fix (#170, #173, #171). Merging this unblocks the deployment pipeline for those features.
Previous attempt: PR #169 (closed) was an earlier fix for the same class of issue (#166). The fact that this recurred as #179 suggests the original fix (merge migration approach in 022) was a band-aid rather than a root cause fix. This PR correctly addresses the root cause by linearizing the chain instead of merging forks.
Post-deploy verification: The Test Plan includes the right post-deploy checks (
alembic upgrade head, version table query, pod health). These should be executed immediately after merge.VERDICT: APPROVED