Run upsert as a transaction