I think checking is not necessary; you can just proceed with the insert, and, if any unique violation occurs, generate a new key and try inserting again, repeat until it works. That way you make sure it works while not incurring in any penalty on the "happy" path.
Software engineer. Currently working with TypeScript, Ruby and Terraform to build digital solutions! Enthusiast about Elixir, OTP, design patterns and best practices.
I think checking is not necessary; you can just proceed with the insert, and, if any unique violation occurs, generate a new key and try inserting again, repeat until it works. That way you make sure it works while not incurring in any penalty on the "happy" path.
Yes! That would be even better! I’ll update the article at some point to handle it like this. 👍