-- Warehouse name should be unique within the same branch, not globally.
DROP INDEX IF EXISTS ux_warehouses_name_ci;

CREATE UNIQUE INDEX IF NOT EXISTS ux_warehouses_name_branch_ci
ON warehouses (
  LOWER(name),
  LOWER(COALESCE(NULLIF(TRIM(raw->>'branchName'), ''), ''))
);
