     jsonb_agg(DISTINCT (node_id)),
     jsonb_agg(v.id),
     jsonb_object_agg(text(v.id), node_id)
-  FROM daily_top_nodes('APC', '2016-01-01') AS dtn,
+  FROM daily_top_nodes('${classificationTreeName}', '2016-01-01') AS dtn,
     tree_version v,
         tree_element_data_from_start_node(dtn.latest_node_id) AS el_data
   WHERE v.published_at = (dtn.year || '-' || dtn.month || '-' || dtn.day) :: TIMESTAMP

     (year || '-' || month || '-' || day) :: TIMESTAMP AS published_at,
     'import'                                          AS published_by,
     a.id                                              AS tree_id
   FROM daily_top_nodes('APC', '2016-01-01'), tree a
   WHERE a.name = 'APC');

UPDATE tree_version
SET previous_version_id = id - 1

SET current_tree_version_id = (SELECT max(id)
                               FROM tree_version v
                               WHERE v.tree_id = t.id)
WHERE name = '${classificationTreeName}';

VACUUM ANALYSE;

