Upsert data to avoid duplicate id errors