-- Enforce case-insensitive uniqueness on product shape names
CREATE UNIQUE INDEX IF NOT EXISTS ux_product_shapes_name_ci
  ON product_shape_definitions (LOWER(name));

-- Add unique index on item_number (shape reference) where not null/empty
CREATE UNIQUE INDEX IF NOT EXISTS ux_product_shapes_item_number
  ON product_shape_definitions ((NULLIF(TRIM(item_number), '')))
  WHERE NULLIF(TRIM(item_number), '') IS NOT NULL;
