0.02
No commit activity in last 3 years
No release in over 3 years
Rails-bigint-pk modifies Rails so that it uses 64-bit primary and foreign keys. It works with MySQL and PostgreSQL and has versions for Rails 3 and 4.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
 Dependencies

Development

~> 2.5
~> 2.8
~> 0.3
~> 0.11
~> 4.1
~> 2.14
~> 1.3

Runtime

< 5, >= 4.0
< 5, >= 4.0
 Project Readme

rails-bigint-pk Build Status

Overview

rails-bigint-pk is a simple, transparent way to use 64bit primary keys in MySQL and PostgreSQL.

Requirements

rails-bigint-pk has been tested with rails 4.2.5, which at the time of writing is the latest patch version for 4.2. If you use a higher patch version, we recommend that you run the test suite against your version of rails and activerecord.

Installation & Usage

Rails 4

rails-bigint-pk supports Rails 4.2, 4.1, and 4.0. To install, you can either download releases from Rubygems by adding the following to your Gemfile:

gem 'rails-bigint-pk', '~>1.2.0'

... or, if you enjoy being on the bleeding edge, you can install the newest code directly from git:

gem 'rails-bigint-pk', github: 'caboteria/rails-bigint-pk'

Then run the generator: rails generate bigint_pk:install

This will create an initializer that enables 64 bit primary and foreign keys by changing the default primary key type, and using limit: 8 for foreign keys created via references.

It will also create a migration to update all existing primary and foreign keys.

Rails 3

There is a rails3 branch for support of 3.2.x versions of Rails. To install, you can either download 0.0.x releases from Rubygems by adding the following to your Gemfile:

gem 'rails-bigint-pk', '~>0.0.1'

... or you can install the newest rails3 branch code directly from git:

gem 'rails-bigint-pk', github: 'caboteria/rails-bigint-pk', branch: 'rails3'

Then run the generator: rails generate bigint_pk:install

This will create an initializer that enables 64 bit primary and foreign keys by changing the default primary key type, and using limit: 8 for foreign keys created via references.

It will also create a migration to update all existing primary and foreign keys.

Gotchas

When adding foreign key columns, be sure to use references and not add_column.

change_table :my_table do |t|
  t.references :other_table
end

# Doing this will not use 64bit ints
add_column :my_table, :other_table_id, :int

Running Tests Against Later Versions of Rails

git clone git://github.com/caboteria/rails-bigint-pk.git
cd rails-bigint-pk

# edit spec/fixtures/Gemfile to set the version of activerecord to
# the one you are using

# purge the test fixture
rm -rf tmp/test\_rails\_app

# This will run integration specs against all supported database types, and
# requires running servers for postgres and mysql.
bundle exec rake spec

# verify that tmp/test_rails_app/Gemfile.lock's entry for activerecord
# matches the version you wanted to test against.