Closed renedekat closed 7 years ago
Can totally add the constraint I agree; I don't think we have to regenerate codes though because we intentionally designed the implementations to avoid collisions. It's impossible to generate duplicate ticket codes for example because of the way we used hashids to encode the existing unique ticket ID, and the order confirmation number key space is so large that it's so unlikely to run into a collision that it might as well be an impossibility.
I've implemented that "retry until you generate a unique code" thing before and it grossed me out, which is why we used the solutions we did 😁
@adamwathan I agree that it's a bit gross (and slow). The HashIDs will be unique, but the confirmation number isn't guaranteed, although very likely, to be unique. Anyway, it's kind of beyond the scope of the course anyway.
From a DB perspective I would add a unique constraint to the confirmation number and the ticket code.
Obviously a unique constraint exception needs to be handled gracefully, by generating a new code for X number of times. X because you could possible end up with an infinite loop.