MP049CRITICALFree
require-partition-key-in-pk
What It Detects
Partitioned table primary key must include all partition key columns. PostgreSQL rejects it otherwise.
Why It's Dangerous
PostgreSQL requires that the primary key (and all unique constraints) on a partitioned table include all partition key columns. Uniqueness can only be enforced per-partition, so the partition key must be part of the constraint. If omitted, the CREATE TABLE will fail at runtime.
Bad Example
CREATE TABLE events ( id bigint PRIMARY KEY, created_at timestamptz NOT NULL, data jsonb ) PARTITION BY RANGE (created_at); -- ERROR: insufficient columns in PRIMARY KEY
Good Example
CREATE TABLE events ( id bigint NOT NULL, created_at timestamptz NOT NULL, data jsonb, PRIMARY KEY (id, created_at) ) PARTITION BY RANGE (created_at);
Configuration
Disable this rule:
# .migrationpilotrc.yml rules: MP049: false
Or change its severity:
# .migrationpilotrc.yml
rules:
MP049:
severity: warning