MP002CRITICALFree

require-check-not-null-pattern

What It Detects

ALTER TABLE ... SET NOT NULL requires a full table scan to validate all existing rows.

Why It's Dangerous

SET NOT NULL scans every row under ACCESS EXCLUSIVE lock. On large tables this can take minutes. Use the CHECK constraint pattern: add CHECK (col IS NOT NULL) NOT VALID, then VALIDATE CONSTRAINT separately.

Bad Example

ALTER TABLE users ALTER COLUMN email SET NOT NULL;

Good Example

ALTER TABLE users ADD CONSTRAINT users_email_not_null
  CHECK (email IS NOT NULL) NOT VALID;
ALTER TABLE users VALIDATE CONSTRAINT users_email_not_null;

Configuration

Disable this rule:

# .migrationpilotrc.yml
rules:
  MP002: false

Or change its severity:

# .migrationpilotrc.yml
rules:
  MP002:
    severity: warning