Skip to content

Instantly share code, notes, and snippets.

@marceldegraaf
Created March 1, 2016 11:41
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save marceldegraaf/211f5f1909f4c7b2cf94 to your computer and use it in GitHub Desktop.
Save marceldegraaf/211f5f1909f4c7b2cf94 to your computer and use it in GitHub Desktop.
Using UUID as primary key in Phoenix (with PostgreSQL)
defmodule YourApp.Service do
use YourApp.Web, :model
@primary_key {:id, :binary_id, autogenerate: true}
schema "services" do
field :name, :string
field :description, :string
timestamps
end
# ...
end
defmodule YourApp.Repo.Migrations.CreateService do
use Ecto.Migration
def change do
create table(:services, primary_key: false) do
add :id, :uuid, primary_key: true
add :name, :string
add :description, :string
timestamps
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment