Elixir Mix Conf 2026 is the flagship Elixir community conference. UUID v7 fits Elixir’s functional model — generation is a pure function call, no global state, no coordination. See UUID in Elixir for the implementation guide.
Ecto schema with UUID v7
defmodule Shop.Orders.Order do
use Ecto.Schema
import Ecto.Changeset
@primary_key {:id, :string, autogenerate: false}
@foreign_key_type :string
schema "orders" do
field :customer_id, :string
field :total, :decimal
field :status, :string, default: "pending"
timestamps()
end
def changeset(order, attrs) do
order
|> cast(attrs, [:customer_id, :total])
|> validate_required([:customer_id, :total])
|> put_change(:id, Uniq.UUID.uuid7()) # UUID v7
end
end
Ash Framework resource with UUID v7
defmodule Shop.Orders.Order do
use Ash.Resource, domain: Shop.Orders
attributes do
attribute :id, :string do
primary_key? true
allow_nil? false
default &Uniq.UUID.uuid7/0 # UUID v7
end
attribute :customer_id, :string, allow_nil?: false
attribute :total, :decimal, allow_nil?: false
attribute :status, :string, default: "pending"
end
actions do
defaults [:read, :destroy]
create :create, primary?: true
end
end
Keyset pagination with UUID v7
def list_orders(cursor \\ nil, limit \\ 20) do
base = from o in Order, order_by: [asc: o.id], limit: ^(limit + 1)
query = case cursor do
nil -> base
cursor -> from o in base, where: o.id > ^cursor
end
orders = Repo.all(query)
has_more = length(orders) > limit
items = Enum.take(orders, limit)
next = if has_more, do: List.last(items).id, else: nil
{items, next}
end
Further reading
- UUID in Elixir — Full Guide
- UUID v7 in Phoenix LiveView
- ElixirConf EU 2026 — UUID v7 in Elixir
- UUID v4 vs UUID v7
External references
Frequently asked questions
How does Ash Framework use UUID v7?
Ash Framework resources declare a primary key type. Override the default UUID v4 with UUID v7 using the uniq hex package: attribute :id, :string, default: &Uniq.UUID.uuid7/0, primary_key?: true. Ash's built-in pagination integrates with UUID v7 keyset pagination via keyset_page_size and custom sort fields. See UUID in Elixir.
Can Phoenix LiveView use UUID v7 stream keys?
Yes. Phoenix LiveView streams use the record's primary key as the DOM stream key. UUID v7 strings are valid stream keys. The time-ordered property means stream_insert(socket, :orders, order, at: -1) appends new records in chronological order without explicit sorting. See UUID v7 in Phoenix LiveView.
What is the uniq hex package?
uniq is an Elixir hex package implementing UUID v6 and UUID v7 per RFC 9562. Add {:uniq, "~> 0.6"} to mix.exs and call Uniq.UUID.uuid7(). It also provides Uniq.UUID.to_raw/1 for 16-byte binary storage and Uniq.UUID.info!/1 for parsing. See What is a UUID.