Migration a390332fa722 crashes: drops non-existent team.data_source column #480

Closed
opened 2026-09-06 19:50:04 +02:00 by johnsturgeon · 0 comments
Owner

Summary

Production crashes running Alembic migrations because migration a390332fa722 drops a column that doesn't exist in the schema.

Error

sqlalchemy.exc.ProgrammingError: (psycopg.errors.UndefinedColumn)
column "data_source" of relation "team" does not exist
[SQL: ALTER TABLE team DROP COLUMN data_source]

Root cause

The migration a390332fa722_drop_team_data_source runs an unconditional op.drop_column('team', 'data_source'), but no migration in the chain ever creates that column:

Revision Effect on team.data_source
0c2ed4448b99 (baseline) not created
20469f2897b6 (email_queue) untouched
a390332fa722 drops it → UndefinedColumn

data_source was an ESPN-era field (added in #368) removed from the Team model during the Tank01 refactor (302663c, 2026-08-28). The Alembic baseline was auto-generated on 2026-08-31 — after that removal — so it codifies a team table without the column. Any database built from the chain creates team without data_source and then fails trying to drop it.

Fix

Make the drop idempotent: ALTER TABLE team DROP COLUMN IF EXISTS data_source. It drops the column on any pre-baseline snapshot that still carries it and is a no-op on databases built from the current baseline.

## Summary Production crashes running Alembic migrations because migration `a390332fa722` drops a column that doesn't exist in the schema. ## Error ``` sqlalchemy.exc.ProgrammingError: (psycopg.errors.UndefinedColumn) column "data_source" of relation "team" does not exist [SQL: ALTER TABLE team DROP COLUMN data_source] ``` ## Root cause The migration `a390332fa722_drop_team_data_source` runs an unconditional `op.drop_column('team', 'data_source')`, but no migration in the chain ever creates that column: | Revision | Effect on `team.data_source` | |---|---| | `0c2ed4448b99` (baseline) | not created | | `20469f2897b6` (email_queue) | untouched | | `a390332fa722` | drops it → `UndefinedColumn` | `data_source` was an ESPN-era field (added in #368) removed from the `Team` model during the Tank01 refactor (`302663c`, 2026-08-28). The Alembic baseline was auto-generated on 2026-08-31 — after that removal — so it codifies a `team` table without the column. Any database built from the chain creates `team` without `data_source` and then fails trying to drop it. ## Fix Make the drop idempotent: `ALTER TABLE team DROP COLUMN IF EXISTS data_source`. It drops the column on any pre-baseline snapshot that still carries it and is a no-op on databases built from the current baseline.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
johnsturgeon/tgfp-web#480
No description provided.