Schema changes can be risky. A new column isn’t just an extra field. It changes storage, query plans, indexing, and sometimes the application logic itself. Done wrong, it can cause downtime or data loss. Done right, it unlocks new features, better performance, and cleaner code.
When adding a new column, start by defining its purpose. Decide if it should be nullable, have a default value, or use constraints. Nullability affects not just storage size but also query complexity. Defaults help maintain backward compatibility by ensuring existing rows get valid values.
Migrations are the safest way to apply schema changes. Use version-controlled migration files. In PostgreSQL, you might start with:
ALTER TABLE users ADD COLUMN last_login TIMESTAMP DEFAULT NOW();
For large tables, online migrations avoid locking and reduce risk. Many teams use tools like pt-online-schema-change for MySQL or PostgreSQL’s ALTER TABLE ... ADD COLUMN in combination with logical replication for zero downtime.