uuid-primary-keys

Installation
SKILL.md

UUID Primary Keys for Rails

Implement UUID primary keys correctly in Rails — PostgreSQL native or SQLite binary storage, with UUIDv7 and optional base36 encoding.

Decision: UUIDv7 Over UUIDv4

Always recommend UUIDv7. It's time-ordered, sortable, and has better index performance than UUIDv4. Ruby 3.3+ ships SecureRandom.uuid_v7 — no gems needed.

Feature Auto-increment UUIDv4 UUIDv7
Sortable by time Yes No Yes
Index performance Best Poor (random) Good (sequential)
Collision risk Impossible Very low Very low
Externally guessable Yes No No
Merge-safe No Yes Yes

Use UUIDs when: IDs appear in URLs, APIs, or multi-database sync. Use integers when: internal-only tables with no exposure.

Two Approaches

Related skills

More from thinkoodle/rails-skills

Installs
4
GitHub Stars
4
First Seen
12 days ago