nothingworksinc / ticketbeast

Back to the lesson videos:
https://course.testdrivenlaravel.com/lessons
552 stars 11 forks source link

Improvement: Unique constraints for confirmation number and ticket code #52

Closed renedekat closed 7 years ago

renedekat commented 7 years ago

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.

adamwathan commented 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 😁

renedekat commented 7 years ago

@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.