I am using Next.js with PostgreSQL (Prisma as ORM).
I need to assign a unique six digit number to my "survey" table in my database when creating a new survey.
Is it better to:
Generate a random number and check if it is already used by another survey in the DB (this seems inefficient).
Prepopulate a table in the database with all the possible numbers between 000000 and 999999 (number needs to be six digits). Then picking one at random when creating a new survey and deleting that record to be certain it can't be used another time.
If option 2: how do I prepopulate a table using next.js and postgresql ?
Or is there a better way?
I haven't tried either solution; I am looking for expert advice on the best option and how to proceed.