Skip to content

Instantly share code, notes, and snippets.

@whazzmaster
Last active August 14, 2017 14:35
Show Gist options
  • Save whazzmaster/9dffcc5346de4fe2babfa1d2ca0f2ce8 to your computer and use it in GitHub Desktop.
Save whazzmaster/9dffcc5346de4fe2babfa1d2ca0f2ce8 to your computer and use it in GitHub Desktop.
Non-primary key UUIDs in Phoenix
defmodule MyApp.Repo.Migrations.AddTrackerIdToProperty do
use Ecto.Migration
def change do
alter table :properties do
add :tracker_id, :uuid, default: fragment("uuid_generate_v4()")
end
end
end
defmodule MyApp.Analytics.Property do
use Ecto.Schema
import Ecto.Changeset
schema "properties" do
field :name, :string
field :tracker_id, :binary_id, read_after_writes: true
belongs_to :product, MyApp.Analytics.Product
timestamps()
end
# changeset functions, etc.
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment