UPDATE node_data
JOIN nodes ON nodes.id = node_data.node_id
SET external = JSON_REMOVE(external, JSON_UNQUOTE(JSON_SEARCH(external, 'one', 'hpm-api', NULL, '$.export_portals')))
WHERE
  JSON_CONTAINS(external, '["hpm-api"]', '$.export_portals')
  AND nodes.available_for_rent = 1;

UPDATE node_data
JOIN nodes ON nodes.id = node_data.node_id
SET external = JSON_REMOVE(external, '$.export_portals')
WHERE
  external->'$.export_portals' = JSON_ARRAY()
  AND nodes.available_for_rent = 1;

UPDATE node_data
JOIN nodes ON nodes.id = node_data.node_id
SET external = NULL
WHERE
  external = JSON_OBJECT()
  AND nodes.available_for_rent = 1;
