Skip to content

westonganger/rails_uuid_to_integer_primary_keys

master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Rails UUID to Integer Primary Keys

So you inherited a Rails app that is currently using UUID’s but now its causing size or speed problems with your app.

Now its time to convert your UUID primary keys back to integer / bigint primary keys, however it is not trivial to do this because all references / belongs_to associations must be kept intact.

I have gone through the hard work of creating a migration that is able to handle this for you mostly automatically.

Requirements

  • All models to convert must inherit from ApplicationRecord
  • All belongs_to or has_and_belongs_to_many must be correctly defined so that reference keys can be located and updated.

Migration

Credits

Created by Weston Ganger - @westonganger

About

A Rails Migration to convert your UUID primary keys back to integer / bigint primary keys

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages