Hi all, is it possible to force ActiveRecord to use specific offset/increment values for the "id" field of a table? In mysql, for example, if you do: set @@auto_increment_offset = 4; set @@auto_increment_increment =10; then the id of subsequent inserts will look like: 4, 14, 24, 34... Thanks in advance, Giuseppe -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
> Giuseppe Bertini wrote: >> Hi all, >> is it possible to force ActiveRecord to use specific offset/increment >> values for the "id" field of a table? >> >> In mysql, for example, if you do: >> set @@auto_increment_offset = 4; >> set @@auto_increment_increment =10; >> >> then the id of subsequent inserts will look like: >> 4, 14, 24, 34... > > SCARY! Keys are not supposed to hold information. Just a unique > identifier. > > I think the answer is no. It would be good to explain why you want to > do this so people can suggest something else if Rails can''t do it. > > PeterHi Peter, the reason for this scary request was to try to implement circular replication between databases according to the technique proposed here: http://www.onlamp.com/pub/a/onlamp/2006/04/20/advanced-mysql-replication.html Briefly, you have the same database-backed application running on different machines. You can work on any machine, and synchronize your database with the other nodes at regular intervals or whenever possible. This mechanism allows one to use the application even in the absence of a connection to the Internet. The strategy proposed in the above article requires that each node creates records with IDs that cannot be used by any other node. Thus, node #1 might always assign IDs like 1, 11, 21, 31, 41, ...; node #2 would always use 2, 22, 32, ..., and so on. In this case, keys do not really hold any information, except for which node in a replication set generated a given record. Yes, it''s kind of ugly, but so far I have been unable to find alternative solutions that allow different people to work on the same application and rely on a common knowledge base even while disconnected from the net (think for example about collecting survey data on your laptop while out in the woods... :-) Any smarter ideas are more than welcome!! Cheers, Giuseppe -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
why not use an UUID instaed of a numeric ID? you could use this gem for generating them: http://sporkmonger.com/projects/uuidtools/ hth Luca 2007/1/6, Giuseppe Bertini <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org>:> > > Giuseppe Bertini wrote: > >> Hi all, > >> is it possible to force ActiveRecord to use specific offset/increment > >> values for the "id" field of a table? > >> > >> In mysql, for example, if you do: > >> set @@auto_increment_offset = 4; > >> set @@auto_increment_increment =10; > >> > >> then the id of subsequent inserts will look like: > >> 4, 14, 24, 34... > > > > SCARY! Keys are not supposed to hold information. Just a unique > > identifier. > > > > I think the answer is no. It would be good to explain why you want to > > do this so people can suggest something else if Rails can''t do it. > > > > Peter > > Hi Peter, > the reason for this scary request was to try to implement circular > replication between databases according to the technique proposed here: > > http://www.onlamp.com/pub/a/onlamp/2006/04/20/advanced-mysql-replication.html > > Briefly, you have the same database-backed application running on > different machines. You can work on any machine, and synchronize your > database with the other nodes at regular intervals or whenever possible. > This mechanism allows one to use the application even in the absence of > a connection to the Internet. > > The strategy proposed in the above article requires that each node > creates records with IDs that cannot be used by any other node. Thus, > node #1 might always assign IDs like 1, 11, 21, 31, 41, ...; node #2 > would always use 2, 22, 32, ..., and so on. > > In this case, keys do not really hold any information, except for which > node in a replication set generated a given record. > > Yes, it''s kind of ugly, but so far I have been unable to find > alternative solutions that allow different people to work on the same > application and rely on a common knowledge base even while disconnected > from the net (think for example about collecting survey data on your > laptop while out in the woods... :-) > > Any smarter ideas are more than welcome!! > Cheers, > Giuseppe > > -- > Posted via http://www.ruby-forum.com/. > > > >--~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---