bug: alembic migration 029 fails on fresh-DB upgrade head (Enum create_type=False reuse) #516
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#516
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
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?
Type
Bug
Lineage
Discovered 2026-04-25 during dev-agent work on
forgejo_admin/basketball-api#510(migration 048). The C2 dev agent attemptedalembic upgrade headon a fresh local DB to validate the round-trip and hit this pre-existing failure at migration 029. Filed perfeedback_discovered_scope_always_tracked. Reproduces onmain. Does NOT affect prod (already past 029); affects dev-loop only.Repo
forgejo_admin/basketball-apiUser Story
As an engineer
I want
alembic upgrade headto succeed on a fresh local Postgres DBSo that I can validate new migrations end-to-end without manually stamping past broken migrations
What Broke
alembic/versions/029_add_schedule_tables.pyreferences thedivisionenum type twice withEnum(..., create_type=False)(lines ~34 and ~77). On a fresh DB upgrade, the second reference fails withtype "division" already existsbecause the first reference (without explicit.create()) implicitly creates the type, then the second reference tries to create it again undercreate_type=False's "assume it exists" semantics — resulting in a collision.Repro Steps
Expected Behavior
alembic upgrade headsucceeds from an empty DB to current head (047+).Environment
main@ current HEAD (verified 2026-04-25)Likely Fix
Either:
Enumreference in 029 explicit-create (.create(op.get_bind(), checkfirst=True)) and the second reference trulycreate_type=Falseop.execute("CREATE TYPE ...")line and have both references usecreate_type=FalseThe right pattern matches whatever SQLAlchemy 2.0+ recommends for shared enums.
Acceptance Criteria
alembic upgrade headruns to current head with zero errorsalembic downgrade baseround-tripTest Expectations
pytest tests/continues to passpsql -c "DROP DATABASE IF EXISTS basketball_test; CREATE DATABASE basketball_test;" && DATABASE_URL=...basketball_test alembic upgrade headConstraints
029_add_schedule_tables.pyif at all possibledown_revision = "029"in 030Checklist
Related
forgejo_admin/basketball-api#491— sibling pre-existing-CI-red ticket (different tests)forgejo_admin/basketball-api#510— surfaced this bug while validating migration 048forgejo_admin/basketball-api#515— the PR for #510, contains the QA agent's discovery comment