Turn back time:Converting integer fields to bigint using Django migrations at scale
summary
Recommends using bigint from the start to avoid later pain and describes a safe, multi‑phase conversion that uses a shadow column plus triggers, runSQL migrations and a batch backfill (100k ID ranges) to avoid long exclusive locks. Reports concrete scale: 14 tables, 29 columns, 24 systems, 104 PRs, 95 migrations, 192 manual steps, largest table ~660M rows, five months of work. Ongoing work addresses bigint primary keys, a cron-driven backfiller that watches autovacuum, and a shadow table + pg_repack idea to avoid vacuuming.
AI-written summary · about
chapters (10)
- 0:00Introduction and motivation
- 3:16Problem with 32-bit integer limits
- 8:07Naive migration approach and risks
- 10:52Three-phase migration process
- 16:54Lessons learned from first project
- 17:16Scaling primary keys to bigint
- 21:08Backfilling challenges and solutions
- 27:03Shadow table approach for vacuuming
- 28:06Key takeaways and conclusions
- 28:36Q&A session
