The cause was clear: the table needed a new column.
Adding a new column should be simple, but the details matter. Schema changes impact performance, uptime, and deployments. The wrong approach can lock tables, slow queries, or block application code. The right one makes it seamless.
In SQL, adding a new column can be done with:
ALTER TABLE users ADD COLUMN last_login TIMESTAMP;
This works, but in production it can cause downtime if the database needs to rewrite the table. For large datasets, use tools like pt-online-schema-change or native online DDL operations in MySQL, PostgreSQL, or other databases. Always test migration steps in staging with production-scale data.
When creating a new column, consider defaults, nullability, and indexing. A non-null column with no default will fail if data already exists. Adding an index with the column can help queries but may slow inserts. Sometimes it’s better to add the column first, backfill data, then add the index in a separate step.