fix: make migration 020 idempotent to unblock crash-looping app #185
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!185
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "184-fix-migration-020-idempotent"
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
Migration 020 (add
custom_notestoplayers) was applied to the production DB but never stamped inalembic_version. On redeploy, Alembic re-runs 020 and hits "column already exists," crash-looping the pod. This fix wraps theadd_column/drop_columncalls in aninformation_schema.columnsexistence check so the migration is safe to re-run regardless of prior DB state.Changes
alembic/versions/020_add_custom_notes_to_player.py: Added_column_exists()helper that queriesinformation_schema.columns. Wrappedupgrade()in a "column does not exist" guard anddowngrade()in a "column exists" guard.Test Plan
ruff formatandruff checkpasspytest tests/ -xpasses (568/568)Review Checklist
Related Notes
forgejo_admin/basketball-api #184-- the Forgejo issue this PR fixesproject-westside-basketball-- the project this work belongs toQA Review -- PR #185
Diff Summary
Single file change:
alembic/versions/020_add_custom_notes_to_player.py(+17/-2). Adds a_column_exists()helper queryinginformation_schema.columns, then guards bothupgrade()anddowngrade()with existence checks.Findings
Correctness
sa.text()with:table/:columnbind params -- safe against injection.upgrade()skipsadd_columnif column already exists -- handles the "applied but not stamped" production state.downgrade()skipsdrop_columnif column is already gone -- symmetric idempotency.op.get_bind()which is the standard Alembic pattern for raw SQL during migrations.Scope
Nit (non-blocking)
information_schema.columnsquery does not filter bytable_schema. In a multi-schema DB, aplayers.custom_notescolumn in another schema could cause a false positive. Not a concern for this single-schema codebase, but worth noting if schema isolation is ever added.Tests
SOP Compliance
Closes #184present.Refs: #184.VERDICT: APPROVE
Clean, minimal fix that directly addresses the crash-loop. No blockers.