UPDATE gateway_api_keys
SET scopes = '["chat","embedding","rerank","image","video","music","audio"]'::jsonb,
    updated_at = now()
WHERE deleted_at IS NULL
  AND (
    (scopes @> '["chat","image","video"]'::jsonb
      AND scopes <@ '["chat","image","video"]'::jsonb)
    OR
    (scopes @> '["chat","embedding","rerank","image","video"]'::jsonb
      AND scopes <@ '["chat","embedding","rerank","image","video"]'::jsonb)
  );
