Adding a new column is simple in theory. In production, it can bring a live service to its knees if done carelessly. The key is to make the change without downtime, without inconsistent reads, and without corrupting data.
First, decide the column’s purpose. Define its exact data type to prevent future migrations. Avoid generic types like TEXT or VARCHAR(MAX) unless absolutely required. Be precise. Precision makes queries faster and indexes smaller.
In SQL, using ALTER TABLE to add a new column is straightforward:
ALTER TABLE users ADD COLUMN last_login TIMESTAMP WITHOUT TIME ZONE DEFAULT NOW();
But on large datasets, this command can lock the table. In MySQL, older versions copy the table. In PostgreSQL, adding a column with a default can trigger a full table rewrite. For zero-downtime changes, add the column nullable first, then backfill in controlled batches, then add constraints.