Ruby on Rails Monday, January 31, 2011

I need to generate a unique serial number in numerical order, but only unique for each user.


For example, each user can create a new credit card and each new credit card must start at a predetermined number and increment by 1 for each new credit card for that user. Thus, credit card numbers are unique for a user but not unique for the CreditCard table. And yes, it is absolutely critical that credit card numbers are always unique for each user.

http://apidock.com/rails/ActiveRecord/Locking/Pessimistic

I'm using PostgreSQL.

Looking through the docs it doesn't appear that I can use either pessimistic locking or optimistic locking. Maybe I'm wrong?

Is my only option to lock the table, find the highest credit card number, add 1, update the new credit card number, save, and release the table lock?

Karl


--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

No comments:

Post a Comment