The query landed. The data was wrong. The only fix was to add a new column—fast.
Creating a new column in a database is simple in theory, but in production it’s a surgical move. The right approach keeps systems stable, migrations clean, and queries performing at full speed. The wrong approach risks downtime and corrupt data.
A new column starts with schema changes. In SQL, this is often an ALTER TABLE command:
ALTER TABLE users ADD COLUMN signup_source VARCHAR(50) NOT NULL DEFAULT 'web';
This updates the table without dropping it. The NOT NULL constraint with a default value ensures existing rows remain valid, avoiding null insert errors. Always test the migration in staging with a copy of production data to measure how it affects indexes and performance.
For large datasets, adding a new column can lock the table. Use online DDL methods where possible (pt-online-schema-change for MySQL, ALTER TABLE … ADD COLUMN with ONLINE = ON in some databases, or PostgreSQL’s fast-add for nullable columns). This prevents blocking writes during the operation.