Review every schema change before it hits production. Catch dangerous migrations, prevent outages, and ship safer SQL.
Don't just review the ALTER TABLE statement. Run it against a copy of production schema and inspect the result. A migration that looks harmless in isolation can break foreign key constraints or indexes.
Dropping columns, tables, or indexes destroys data permanently. Verify the column is unused by application code. Search your entire codebase for references before approving a DROP.
ALTER TABLE ... ADD COLUMN ... NOT NULL without a DEFAULT will fail on tables with existing rows. Add the default first, then apply NOT NULL in a follow-up migration.
Renaming a column with ALTER TABLE ... RENAME COLUMN is safe in PostgreSQL but can cause downtime in MySQL (rebuilds the table). Consider adding a new column, backfilling, and deprecating the old one.
Creating indexes on large tables can lock writes for minutes or hours. Use CREATE INDEX CONCURRENTLY (PostgreSQL) or ALGORITHM=INPLACE, LOCK=NONE (MySQL 5.6+) to avoid blocking.
Adding a foreign key with ALTER TABLE validates all existing rows, which can be slow. On PostgreSQL, add the constraint as NOT VALID first, then validate separately to avoid long locks.
Widening a column (INT → BIGINT) is usually safe. Narrowing (VARCHAR(255) → VARCHAR(50)) can truncate data. Changing TEXT → JSONB may fail on invalid values.
Every foreign key should have a corresponding index for fast JOINs and cascade operations. Without it, DELETEs and UPDATEs on the parent table become full table scans on the child.
TipA migration that runs in 10ms on your local machine with 100 rows might take 30 minutes on a 50M-row production table. Always test migrations on realistic data volumes.
CriticalUse IF NOT EXISTS and IF EXISTS guards. If a migration fails midway and is re-run, it should not crash. This is especially important in CI/CD pipelines.
A DEFAULT '1970-01-01' on a timestamp column or DEFAULT 0 on a price column can silently corrupt data. Defaults should be semantically meaningful or explicitly NULL.
Every migration should be reversible or have a documented manual rollback. In an emergency, you need to restore service in minutes, not hours. Test the rollback before deploying.
CriticalPaste two SQL schemas into SchemaLens and get an instant visual diff, breaking-change warnings, and migration scripts — all in your browser.
Try SchemaLens Free →