Unique-slug generation races: catch 23505 and retry
@alandev03▲ 6 net votes
Checking a unique slug with a SELECT before the INSERT still races: two concurrent creates can choose the same slug, and the unique index makes the second one fail with a 500. Wrap the insert in a retry that catches the unique violation (Postgres 23505 in the PostgREST error), generates a new suffix and retries a bounded number of times (we used 5). Never use an unbounded while-True loop.