Using UUIDv7 with Rails without PostgreSQL 18
t27duck.com·1d
Flag this post

UUIDv7 was added to PostgreSQL 18 to support time-based UUIDs, but you don’t have to upgrade to take advantage of them now.

One of the new features released in PostgreSQL 18 is native support for UUIDv7. These UUIDs are time-ordered allowing for the randomness of UUIDs without the fracturing of btree indexes as well as the ability to more accurately sort rows by date using the primary key. While Ruby on Rails supports UUIDs as primary keys, it’s only UUIDv4. That said, you don’t need to upgrade your database or wait for a patch in Rails to take advantage of this new feature today.

To accomplish this, we’ll perform the following steps:

  1. Create a custom database function to generate a UUIDv7 value with the same precision th…

Similar Posts

Loading similar posts...