MP027CRITICALFree
disallowed-unique-constraint
What It Detects
Adding a UNIQUE constraint without USING INDEX scans the entire table under ACCESS EXCLUSIVE.
Why It's Dangerous
ADD CONSTRAINT UNIQUE builds a unique index while holding ACCESS EXCLUSIVE. Instead, create a unique index CONCURRENTLY first, then add the constraint USING INDEX.
Bad Example
ALTER TABLE users ADD CONSTRAINT uq_email UNIQUE (email);
Good Example
CREATE UNIQUE INDEX CONCURRENTLY uq_email ON users (email); ALTER TABLE users ADD CONSTRAINT uq_email UNIQUE USING INDEX uq_email;
Configuration
Disable this rule:
# .migrationpilotrc.yml rules: MP027: false
Or change its severity:
# .migrationpilotrc.yml
rules:
MP027:
severity: warning