moved parent upsert before child upsert