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?
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 :)
精彩评论