Adding a new column to a table should be simple, but scale and uptime raise the stakes. The wrong migration locks rows, halts writes, or breaks downstream code. Done right, it’s invisible to users and safe for production.
First, define the column with intent. Choose a type that matches the data and reduces storage without hurting performance. Use NULL or a sensible default to avoid rewriting every row. For example:
ALTER TABLE users ADD COLUMN last_login TIMESTAMP NULL;
Run schema changes behind controlled deployments. In large tables, use tools like pt-online-schema-change or native database features for non-blocking alters. Test on a replica before touching production.