Change starting id number

You'll need to do some specialized database-dependent SQL to get this functionality.

If you're using MySQL, you can add the following code to your migration after the create_table code:

execute("ALTER TABLE tbl AUTO_INCREMENT = 1000")

for PostgreSQL:

execute("ALTER SEQUENCE accounts_id_seq START with 1000 RESTART;")

see https://www.postgresql.org/docs/current/static/sql-altersequence.html


For sqlite

sequences are stored in the table sqlite_sequence (name,seq)

  • Check first if the sequence already exists?

    select name,seq from sqlite_sequence where name = 'accounts'

if sequence.empty?

insert into sqlite_sequence(name,seq) values('accounts', 1000);

else

update sqlite_sequence set seq = 1000 where name = 'accounts';