Adding a new column in a database sounds simple, but in production it can break queries, overload replication, and stall writes if done without care. The process demands precision.
First, define the column in a way that aligns with your data model. Decide on type, null constraints, default values, and indexing strategy before touching the migration scripts. Every decision here affects performance and integrity.
For relational systems like PostgreSQL or MySQL, use ALTER TABLE with consideration for locking behavior. On large tables, an unbuffered schema change can block reads and writes. Many teams use ALTER TABLE ... ADD COLUMN inside a transactional migration, but for huge datasets, tools like pt-online-schema-change or gh-ost prevent downtime.
If data backfill is required, run it in controlled batches. Avoid writing a single query that updates millions of rows in one transaction. This reduces lock contention and protects query performance.