Adding a new column is simple in theory, but execution can make or break performance, stability, and deployment speed. Whether you are working with PostgreSQL, MySQL, or a distributed system like CockroachDB, the process follows the same fundamental steps: define the change, apply it safely, verify the migration, and deploy without downtime.
Start by planning the schema change. A new column should have a clear data type, default values if required, and indexing strategy. Adding a column with a default value on a large table can lock writes and reads if not handled with care. In many production environments, it’s wise to create the column nullable first, backfill data in batches, then enforce constraints.
Use schema migration tools such as Flyway, Liquibase, or Prisma Migrate for version control and repeatable builds. For PostgreSQL, the SQL statement is straightforward:
ALTER TABLE users ADD COLUMN last_login TIMESTAMP;
If you need the new column to be indexed for fast lookups, create the index in a separate migration: