Unique primary key increments

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

Giuseppe B. 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

Giuseppe B. 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:

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… :slight_smile:

Any smarter ideas are more than welcome!!
Cheers,
Giuseppe