Last active
August 14, 2017 14:35
-
-
Save whazzmaster/9dffcc5346de4fe2babfa1d2ca0f2ce8 to your computer and use it in GitHub Desktop.
Non-primary key UUIDs in Phoenix
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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