fix(BA-6915): drop the column default before retyping sessions.result#12912
Draft
jopemachine wants to merge 2 commits into
Draft
fix(BA-6915): drop the column default before retyping sessions.result#12912jopemachine wants to merge 2 commits into
jopemachine wants to merge 2 commits into
Conversation
jopemachine
force-pushed
the
fix/BA-6914-fk-constraint-name-drift
branch
from
July 20, 2026 04:24
db2ee0a to
1c9d392
Compare
jopemachine
force-pushed
the
fix/BA-6915-sessionresult-downgrade-default
branch
from
July 20, 2026 04:24
9bddfad to
1571ff3
Compare
jopemachine
changed the base branch from
fix/BA-6914-fk-constraint-name-drift
to
fix/BA-6913-fresh-install-missing-indexes
July 20, 2026 04:24
jopemachine
force-pushed
the
fix/BA-6913-fresh-install-missing-indexes
branch
from
July 20, 2026 04:39
04b8764 to
f245ba8
Compare
jopemachine
force-pushed
the
fix/BA-6915-sessionresult-downgrade-default
branch
from
July 20, 2026 04:39
1571ff3 to
6ab9b00
Compare
jopemachine
force-pushed
the
fix/BA-6913-fresh-install-missing-indexes
branch
from
July 20, 2026 04:42
f245ba8 to
d6707d9
Compare
jopemachine
force-pushed
the
fix/BA-6915-sessionresult-downgrade-default
branch
from
July 20, 2026 04:42
6ab9b00 to
296ce72
Compare
jopemachine
force-pushed
the
fix/BA-6913-fresh-install-missing-indexes
branch
from
July 20, 2026 05:20
d6707d9 to
2925811
Compare
jopemachine
force-pushed
the
fix/BA-6915-sessionresult-downgrade-default
branch
from
July 20, 2026 05:20
296ce72 to
13ad05d
Compare
jopemachine
force-pushed
the
fix/BA-6913-fresh-install-missing-indexes
branch
from
July 20, 2026 05:21
2925811 to
9317cef
Compare
jopemachine
force-pushed
the
fix/BA-6915-sessionresult-downgrade-default
branch
from
July 20, 2026 05:21
13ad05d to
eee9ae0
Compare
The downgrade recreates the plural sessionresults type and then retypes sessions.result into it. PostgreSQL cannot cast an existing column default across two unrelated enum types, so the ALTER aborts with DatatypeMismatchError before touching a row. The migration's try/except tolerates a list of expected divergence SQLSTATEs, and 42804 is not on it, so the whole downgrade chain stops here. Drop the default, retype, then restore it -- the order dec0deba5893 already uses for the same conversion. The upgrade path runs the mirror-image ALTER with the same omission, so it gets the same treatment. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
jopemachine
force-pushed
the
fix/BA-6913-fresh-install-missing-indexes
branch
from
July 20, 2026 05:25
c181663 to
e972044
Compare
jopemachine
force-pushed
the
fix/BA-6915-sessionresult-downgrade-default
branch
from
July 20, 2026 05:25
eee9ae0 to
2422038
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
📚 Stacked PRs
BA-6914fix: migrations that drop a foreign key by a name the DB may not useBA-6913fix: indexes that only exist on migrated databasesBA-6915fix: drop the column default before retyping sessions.result ← you are hereMerge in order, top-down. Each PR is based on the one above it, so its diff shows only its own layer. The order is fixed by the alembic chain: #12907's migration takes #12910's parent as its
down_revision.Problem
0b1efbb2db84's downgrade recreates the pluralsessionresultstype and then:sessions.resultcarries a default. PostgreSQL cannot cast an existing default across two unrelated enum types, so this aborts before touching a row:The migration guards its DDL with a
try/exceptover a list of expected-divergence SQLSTATEs — but42804isn't on it, so the error is reraised and the whole downgrade chain stops here.The correct order already exists in this repo
dec0deba5893does the same conversion and succeeds, because it handles the default:0b1efbb2db84just omits it. This PR gives it the same order, on both the downgrade and the mirror-imageALTERinupgrade().Reproduction
On a DB built at head by
mgr schema oneshot, downgraded with no skipped revisions:dec0deba5893's downgrade recreates the singularsessionresultand convertssessions.resultto it.0b1efbb2db84, thehas_singular and not has_pluralbranch fires and aborts.Confirmed by hand that
DROP DEFAULT→ALTER COLUMN TYPE→SET DEFAULTcompletes, leavingresultassessionresultswith default'UNDEFINED'::sessionresults.Verification
With this fix on top of #12881, #12883, #12887, #12907, #12910, a single straight
alembic downgradefrom head tod86417a6bf7b— below the deepest RBAC backfill — now completes:That path previously stopped after 28 steps. Each fix moved it further: 28 → 84 → 150 → 175, target reached.
Found while surveying the downgrade chain for #12881.
🤖 Generated with Claude Code