Safely Adding NOT NULL Columns to Your Database Tables - Shopify
Oct 4, 2022

Summary
This post details an investigation into the safety of adding NOT NULL columns to MySQL tables using the Large Hadron Migrator (LHM) gem. It outlines the LHM shadow-table mechanism and defines schema change safety in terms of backward compatibility and data loss. The investigation focuses on the impact of DEFAULT values, UNIQUE indexes, and MySQL's strict/non-strict modes on the safety of adding NOT NULL columns. A results matrix is presented, concluding that adding NOT NULL columns without a DEFAULT value should be avoided, and caution is advised when adding UNIQUE indexes due to the risk of data loss.
More from the Data Store Selection and Usage trail
- We replaced Redis with MySQL for inventory reservations—and it scaled (2026) - Shopify
- Mitigating Deadlocks in high concurrency environments - Shopify
- Double Entry Transition Tables: How We Track State Changes At Shopify - Shopify
- Shopify’s Unique Data Science Hierarchy Of Needs - Shopify
- Upgrading MySQL at Shopify - Shopify