Recently, I was playing around with Phoenix Framework (version: 0.13.1) with Postgres as the database. Instead of using IDs for primary key, I wanted to use UUIDs.
Since Phoenix and associated projects haven’t hit 1.0 yet, api is still under flux.
Since ecto version 0.12.1 using UUIDs as primary key coudn’t be any easier.
Here is how to do it:
The migration that creates the table will need to be aware of the fact that ID column is going to be of UUID type.
We will also need to update our model definition so that it can auto-generate UUIDs for primary keys.
And that is all you need to use UUIDs from primary keys with ecto and phoenix framework.
As an aside, I really like how these projects are shaping up. Also, the community around Elixir and Phoenix is absolutely fantastic. It took me no more than 5 minutes to figure this out by hopping on Elixir IRC and José Valim himself explaining how to solve this problem.