In my app I have users and invoices (amongst other things).
I'm not sure what's the best way to make sure the invoices of every user start with 1 and go up incrementally. For example:
- User 1 makes 2 invoices - ID 1 and ID 2
- User 2 makes 3 invoices - ID 1 ID 2 and ID 3
- User 1 makes 1 invoice - ID 3
I obviously can't use the default id column as it would just increase by one on every entry. The solution I thought about is having a new column in my invoices table called "incrementalId" that I update manually when I save the invoice and make it be 1 more than the maximum count.
Is this the standard way to go about solve this problem? An issue I can think of is that if I delete an invoice, the next one that I generate will most likely have an ID that is already taken. Or is deleting the entry when I delete the invoice not really the way to go?