Adding a new column to a database table sounds simple. It is not. The wrong schema change can lock rows, slow queries, or crash production. Done right, it’s seamless. Done wrong, it’s chaos.
First, define exactly why the new column exists. Every column should have a clear purpose. Name it well. Avoid vague names like “data” or “info.” Use lowercase with underscores for clarity.
Decide on the data type before touching the migration. Use the smallest type that fits. A boolean costs less than an integer. A fixed-length string beats a long text column when you know the limit. This choice affects storage, indexing, and query speed.
When working with large tables, think about how the new column will be initialized. Adding a column with a default can rewrite millions of rows. In PostgreSQL, adding a nullable column without a default is instant. Then you can backfill in small batches. In MySQL, choose algorithms like INPLACE when possible to avoid full table locks.