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


-- *************** end tree creation ***************

-- set all the existing name paths and family from APC tree
UPDATE name n
SET name_path = '', family_id = NULL;


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

UPDATE tree_version
SET previous_version_id = id - 1
