Adding a new column to a database table is never just one step. It touches code, tests, pipelines, and production data. Done wrong, it causes downtime, corrupts data, or forces rollbacks that burn hours. Done right, it ships fast and clean.
First, define the purpose of the new column. Keep the schema consistent. Use clear, lowercase names with underscores. Decide on type and constraints early — nullability, default values, uniqueness. These choices affect queries and indexes for years.
Second, plan the migration. For SQL databases, tools like Liquibase or Flyway keep schema changes in version control. In PostgreSQL, ALTER TABLE with ADD COLUMN is standard, but large tables demand caution. Adding a non-null column without a default can lock the table. Use nullable columns first, backfill data in batches, then set NOT NULL when safe.
Third, update the application layer. Reflect the new column in ORM models or query builders. Adjust API contracts, serializers, and deserializers. Write migrations in your application code to handle historical data. Deploy these changes behind feature flags to control rollout.