Rails + Postgres + UUID

Overview

1. What the heck is UUID?

2. Why would I want to use a UUID?

Steven Seagal gif where someone replaced a gun he was holding with an electric toothbrush
Steven Seagal gif where someone replaced a gun he was holding with an electric toothbrush
Mr. Seagal prepares to brush his teeth in public.
cooldudes.com/users/13
cooldudes.com/users/13/private-messages/7
2016 image of person on plane typing into laptop wearing a knitted garment that obscures the screen and their hands
2016 image of person on plane typing into laptop wearing a knitted garment that obscures the screen and their hands
Mega secure with Becky Stern’s “Compubody Sock”

3. Rails Setup

rails new app-with-uuid-keys --api --database=postgresql
rails generate migration enable_uuid --no-test-framework
database migration code showing the id as a uuid
database migration code showing the id as a uuid
Users migration table

4. Database Setup

console printed text showing successful migrations of pgcrypto extension, users
console printed text showing successful migrations of pgcrypto extension, users
This is what you should see!

5. The Big Reveal

GIF: Drag queen Violet Chachki on RuPaul’s Drag Race walking a runway and revealing a red garment from under a black one
GIF: Drag queen Violet Chachki on RuPaul’s Drag Race walking a runway and revealing a red garment from under a black one
Rails console readout that confirms id is uuid and not an integer
Rails console readout that confirms id is uuid and not an integer

6. Epilogue

a database error stating that function gen_random_uuid() does not exist

Full Stack Software Engineer. Multimedia performance engineer and performer. Through technology, I ❤ to bring ideas to reality–on the stage or in a browser.