This is a simple gem to create big integer primary key for mysql and postgresql so that the auto increment is intact.
Add this line to your application's Gemfile:
gem 'bigint_primary_key'
And then execute:
$ bundle
Or install it yourself as:
$ gem install bigint_primary_key
You can use it in your migration file.
(create table without id)
class CreateCakes < ActiveRecord::Migration
def change
create_table :cakes, id: false do |t|
t.string :name
t.timestamps
end
add_bigint_primary_key :cakes, :id
end
end
(create table with default id)
class CreateCakes < ActiveRecord::Migration
def change
create_table :cakes do |t|
t.string :name
t.timestamps
end
alter_bigint_primary_key :cakes, :id
end
end
You can leave id
out if you have default setting. add_bigint_primary_key :cakes
and alter_bigint_primary_key :cakes
Here are the method definitions:
def add_bigint_primary_key t_name, pk_name = :id
...
end
def alter_bigint_primary_key t_name, pk_name = :id
...
end
- Fork it
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create new Pull Request