UPDATE node_data
JOIN nodes ON nodes.id = node_data.node_id
SET external = "{}"
WHERE
  node_data.external IS NULL
  AND nodes.available_for_rent = 1;

UPDATE node_data
JOIN nodes ON nodes.id = node_data.node_id
SET external = JSON_SET(external, '$.export_portals', JSON_ARRAY())
WHERE
  NOT JSON_CONTAINS_PATH(external, 'all', '$.export_portals')
  AND nodes.available_for_rent = 1;

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