Problem
The campaign_snapshots table has a column name mismatch causing snapshot storage to fail:
ERROR: column "campaign_pid" does not exist (SQLSTATE 42703)
Root cause:
- Model field:
CampaignPID string
- GORM snake_case:
campaign_p_id (incorrect due to PID → p_id)
- Expected:
campaign_pid
This is the same issue we had with the campaigns table PK (#24), but we forgot to fix it for the foreign key in campaign_snapshots.
Impact
- ❌ All snapshot inserts fail (5,614 errors on each crawl)
- ❌ Sparkline charts have no historical data
- ❌ Velocity calculations broken
Current State
From logs (2026-02-27 14:12 UTC):
- ✅ 5,614 campaigns upserted successfully
- ❌ 5,614 snapshot inserts failed with
campaign_pid error
Solution
Add idempotent migration in db.go:
- Rename
campaign_p_id → campaign_pid if exists
- Update GORM tag:
gorm:"column:campaign_pid"
Related
Problem
The
campaign_snapshotstable has a column name mismatch causing snapshot storage to fail:Root cause:
CampaignPID stringcampaign_p_id(incorrect due toPID→p_id)campaign_pidThis is the same issue we had with the
campaignstable PK (#24), but we forgot to fix it for the foreign key incampaign_snapshots.Impact
Current State
From logs (2026-02-27 14:12 UTC):
campaign_piderrorSolution
Add idempotent migration in
db.go:campaign_p_id→campaign_pidif existsgorm:"column:campaign_pid"Related
campaigns.pidcolumn name fix