Should this put be outside of the if? What about the case where the DELETE occurs after the UPSERT?