We can't find the internet
Attempting to reconnect
Something went wrong!
Hang in there while we get back on track
Automatically configures your Phoenix application to use UUIDs as primary keys instead of auto-incrementing integers. This feature updates your Ecto configuration and provides a reusable schema module to streamline UUID adoption across your entire application.
Key Benefits
Implementation Details
The feature modifies your config/config.exs
to set type: :binary_id
for migration primary keys and creates a custom Schema
module that sets UUID defaults for all primary and foreign keys. This eliminates the need to specify @primary_key {:id, :binary_id, autogenerate: true}
in every schema.
Usage Example
# Instead of standard Ecto.Schema
defmodule MyApp.Post do
use MyApp.Schema # Uses UUID by default
schema "posts" do
field :title, :string
belongs_to :user, MyApp.User # Automatically uses binary_id
timestamps()
end
end
Configuration
After applying this feature, all new migrations will generate UUID primary keys by default. Existing schemas can be gradually migrated to use the new MyApp.Schema
module instead of Ecto.Schema
to adopt UUID conventions.