Changed upsert query. ParentId resolution had some errors if parents
were inserted after children.