MP030CRITICALAuto-fixableFree

require-not-valid-check

What It Detects

CHECK constraint without NOT VALID scans the entire table under ACCESS EXCLUSIVE.

Why It's Dangerous

Adding a CHECK constraint validates all existing rows while holding ACCESS EXCLUSIVE. Use NOT VALID to skip validation, then VALIDATE CONSTRAINT separately with a lighter lock.

Bad Example

ALTER TABLE users ADD CONSTRAINT chk_age
  CHECK (age >= 0);

Good Example

ALTER TABLE users ADD CONSTRAINT chk_age
  CHECK (age >= 0) NOT VALID;
ALTER TABLE users VALIDATE CONSTRAINT chk_age;

Auto-fix

Run migrationpilot analyze file.sql --fix to automatically fix this violation.

Configuration

Disable this rule:

# .migrationpilotrc.yml
rules:
  MP030: false

Or change its severity:

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