Skip to main content

What Happened

The golden-press service (Go) was rated 75% complete and appeared production-ready. Deep source analysis revealed the golden_tickets table schema in migration 000001 didn’t match the code in repository.go:
  • Migration: holder_user_id, holder_github, verify_run_sha (9 columns)
  • Code: user_id, github_identity, display_name, avatar_url, merkle_proof, status, idempotency_key (18 columns)
  • Missing table: antigaming_violations (referenced in SQL queries but never created)

Key Insight

Schema drift happens when architecture and implementation are written in different sessions. The initial migration reflected the architecture spec (SRS-002). The service code reflected the implementation spec (with additional fields for display, idempotency, and integrations). Neither session verified the other.

Prevention Pattern

After any session that touches both internal/storage/ and infrastructure/migrations/:
  1. Extract column names from INSERT/SELECT SQL in Go code
  2. Extract column names from CREATE TABLE in migrations
  3. Diff the two lists
  4. Create alignment migration if they diverge
This takes 2 minutes and prevents runtime crashes that would otherwise surface only in integration testing (or worse, production).

Resolution

Created migration 000007 that:
  • Renamed 4 columns (ALTER TABLE RENAME COLUMN)
  • Added 9 new columns with defaults then dropped defaults
  • Added CHECK constraint for status enum
  • Created the missing antigaming_violations table with indexes
Reversible down migration included. Zero data loss path.