Implementating auto-incrementing/sequence fields in Ash Resources
I'm working on a project and I need to implement auto-incrementing fields, for example an Issue Number, Invoice Number, Service Number etc.
I was thinking of creating a sequence table to keep track of multiple auto-increment field counts.
issue_number
counts, invoice_number
counts, service_number
counts, etc.
I want to make sure that the implementation is consistent and that the sequence table will not leave gaps, as some database implementations leave gaps when a transaction fails.
I want to hear your ideas on the best way to implement in Ash, and it would be cool if there was an extension for this, like AshSequence
😄
Thank you in advance for your help!2 Replies
Hello! That's an interesting question 🙂 I'd have to do some research to see how people do sequences guaranteeing no gaps. Ideally it would be leveraging a database feature, perhaps even database triggers. I personally wouldn't want to implement it in application logic, I think. However, something like
AshSequence
could react to the ash_postgres
extension existing, and add custom_statement
s to the migrations, and if its a different data layer it could implement it in application logic.Thanks for your feedback. I will also do some research regarding database triggers. For the sake of making progress 😄, will try to implement what I mentioned previously then do proper implementation later.