The schema is tight. The query runs fast. But the client asks for one more field, and you need a new column now.
Adding a new column sounds simple. In practice, it can break production if done wrong, especially on large tables with millions of rows. Performance, locking, and backward compatibility all matter. This is where a disciplined approach pays off.
Start with the database. In PostgreSQL, use ALTER TABLE with ADD COLUMN to introduce the change. Specify defaults carefully—adding a default to a non-null column will rewrite the table, which can lock reads and writes for a long time. If possible, create the column as nullable first, then backfill data in controlled batches.
For MySQL, the same principle applies. Avoid full table rewrites by skipping default constraints initially. MySQL will lock the table during ALTER TABLE, so run it during low traffic windows or use tools like gh-ost or pt-online-schema-change to migrate live without downtime.