KevinBongart / cards_against_humanity

An unofficial online version of the Cards Against Humanity game.
https://www.cardiganshumility.online
Other
41 stars 13 forks source link

Ensure unique game slugs #24

Open KevinBongart opened 4 years ago

KevinBongart commented 4 years ago

Game slugs are being generated once when creating a game, but the logic doesn't check that its unique before sending it to the database (which does enforce uniqueness). There is no logic rescuing from a non-unique slug.

A loop should generate a slug, check for uniqueness, attempt to store it and rescue (and retry) if it fails.

KevinBongart commented 4 years ago

Here's an example of an issue that happened a few hours ago:

ActiveRecord::RecordNotUnique: PG::UniqueViolation: ERROR:  duplicate key value violates unique constraint "index_games_on_slug"
DETAIL:  Key (slug)=(SJJZK) already exists.