UUID:s as Primary id:s

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

  • Better for distributed systems - UUIDs eliminate primary key conflicts when merging databases or working across multiple environments
  • Enhanced security - Prevents enumeration attacks and makes it harder to guess valid record IDs in URLs
  • Microservice-ready - UUIDs work seamlessly when splitting monoliths or integrating with external services
  • Zero manual configuration - Automatically sets up all necessary Ecto configurations and schema defaults

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.