3

I would like to run a migration to create a User table that starts counting from 10000 for the user_id column. I would like to avoid using DB specific syntax via the execute method, because my production and development servers aren't the same.

Is there a rails way to do this?

Jonathan Chiu
  • 1,637
  • 2
  • 16
  • 25
  • 2
    http://stackoverflow.com/questions/1427148/how-can-i-set-the-starting-point-for-the-primary-key-id-column-in-postgres-via – fl00r Mar 25 '11 at 11:10

1 Answers1

2

If you need to do this in a database-independent way, I don't see any easier option than creating 10000 Users in your migration, and then doing "truncate table users" or just deleting users with id < 10000. This will probably take a little bit of time.

In postgres you can redefine starting number of the sequence responsible for generating these IDs. In MySQL you can do it also, but differently: "ALTER TABLE theTableInQuestion AUTO_INCREMENT=1234"

Of course you could add this functionality to ActiveRecord::Migration class, and provide implementation in DB-specific drivers.

All depends on how far you want to go with this :)