How to turn off BIGINT primary keys in Rails 5.1

ruby, ruby-on-rails, ruby-on-rails-5.1

Solution

According to pull request, no this is not possible on config level. But you can, in fact, force `id` to be integer, like this:

create_table :users, id: :integer do

On the other hand, you must be aware that changes also affected `references` behavior, so you should be careful with those:

t.references :orders, type: :integer

Seeing as this is too much repeated code, I suggest you write helpers for this, override default methods, or be very radical and fork your database adapter, changing this in it as you like. I'd go with the second option:

- Create anonymous modules for `Migration[5.0]` and `ActiveRecord::ConnectionAdapters::TableDefinition`

- Define `create_table`, `add_reference`, `add_belongs_to` in first one, `references` and `belongs_to` in second one (`belongs_to` ones should be just aliases of `references`)

- In those methods just modify options and call super. Don't forget to handle signatures!

- Prepending those modules to their respective classes will handle everything for you.

- You can go even better and do this for their removal counterparts too.

Problem

Rails 5.1 migrations generates `BIGINT` (instead of `Integer`) for tables' primary keys (changelog). Is it possible to disable that somewhere in the config? If so, how to do disable it?

Original source