Adding a new column is one of the most common schema changes, but it comes with trade-offs. The wrong approach can lock a table, stall writes, or break production queries. The right approach makes the change seamless and safe.
Define the column with a clear name and an explicit type. Avoid relying on defaults without reason. If you need non-null constraints, decide whether to run a background migration to backfill the data first. Adding a NOT NULL column with no default will fail if rows already exist.
On relational databases like PostgreSQL and MySQL, ALTER TABLE is simple in syntax but can be expensive in large datasets. For PostgreSQL, adding a column with a constant default in newer versions is fast because it stores the default in metadata. On MySQL, large tables may still require online schema change tools like pt-online-schema-change or gh-ost to avoid downtime.
When adding a new column in production, always: