MP084CRITICALFree
require-default-for-not-null-column
What It Detects
ADD COLUMN ... NOT NULL without a DEFAULT aborts the migration on any table that already contains rows.
Why It's Dangerous
PostgreSQL has to write a value into the new column for every row that already exists, and without a DEFAULT there is nothing to write — the statement fails with "contains null values" and takes the whole migration with it. What makes this one worth catching in review is where it fails: an empty database accepts the identical statement, so it passes locally, passes in CI, and then aborts in staging or production, the only environments with rows in the table.
Bad Example
ALTER TABLE users ADD COLUMN email TEXT NOT NULL; -- Fine on an empty table, fatal on a populated one
Good Example
-- On PG 11+ a constant default is a catalog-only change, no rewrite. ALTER TABLE users ADD COLUMN email TEXT NOT NULL DEFAULT '';
Configuration
Disable this rule:
# .migrationpilotrc.yml rules: MP084: false
Or change its severity:
# .migrationpilotrc.yml
rules:
MP084:
severity: warning