Columns
ADD COLUMN ... REFERENCES ... NOT VALID (inline)
Lock mode ACCESS EXCLUSIVE
Risk LOW
Blocks reads, writes, other DDL
pgfence rule
add-column-inline-foreign-key-not-valid ALTER TABLE orders ADD COLUMN customer_id bigint REFERENCES customers(id) NOT VALID; What this does
Adding NOT VALID to an inline foreign key defers validation of the referenced table. The ACCESS EXCLUSIVE lock on the table being altered is still taken, but it is brief, and the referenced table is not touched until a later VALIDATE CONSTRAINT.
Safe rewrite
Already using the safe pattern. Follow up with VALIDATE CONSTRAINT in the same or a later migration
ALTER TABLE orders VALIDATE CONSTRAINT orders_customer_id_fkey;