The migration script finished in under a second, but the data was gone. All because the new column was defined wrong.
Adding a new column sounds simple. In practice, it can break queries, lock tables, and trigger cascading failures if done carelessly. Whether you are working on PostgreSQL, MySQL, or a cloud-managed database, the steps are the same: precision first.
Define the new column with the correct data type, nullability, and default before touching production. If needed, use ALTER TABLE ... ADD COLUMN in a transaction or behind a feature flag. In PostgreSQL, adding a nullable new column without a default is instant; adding one with a default will rewrite the whole table—impacting performance.
For high-traffic systems, add the column in stages. First, create the nullable column without a default. Then backfill it in batches. Finally, set the default and constraints. This avoids long locks and reduces the risk of downtime.