Updating Hex.pm to Ecto 3.0

Ecto 3.0 is just around the corner and as you may already know it reached stable API. To make sure everything works properly I thought I’ll try updating one of the first projects that ever used Ecto: Hex.pm.

The whole upgrade was done in a single pull request, which we will break down below.

First, the required steps:

  1. Update mix.exs to depend on ecto_sql and bump the postgrex dependency. Note: SQL handling have been extracted out into a separate ecto_sql project, so we need to add that new dependency. (6b3b78cf)
  2. DBConnection 2.0 no longer ships with Sojourn and Poolboy pools, so we can remove the pool configuration and use the default pool implementation. (760026f3)
  3. Speaking of pools, we need to make sure pool_size is at least 2 when running migrations.
  4. JSON library is now set on the adapter and not on Ecto (e16ebd8f) and because we were already using the recommended package, Jason, we don’t need that configuration anymore. (66f9cbdf)
  5. Ecto 3.0 makes date/time handling stricter with regards to precision. So we need to either update the types of our schema fields or make sure we truncate date/time values. For example, when we define a field as time we can’t put value with microsecond precision and similarly we can’t put into a time_usec field a value without microsecond precision. (2e34b833)
  6. Constraint handling functions like Ecto.Changeset.unique_constraint/3 are now including in the error metadata the type and the name of the constraint, which broke our test that was overly specific. (3d19f903)

Secondly, we got a couple deprecation warnings so here are the fixes:

  1. Adapter is now set when defining Repo module and not in the configuration. (d3911953)
  2. Ecto.Multi.run/3 now accepts a 2-arity function (first argument is now the Repo) instead of a 1-arity one before. (95d11cc2)

Finally, there were a few minor glitches (or redundancies!) specific to Hex.pm: c4168977, 21eb0bf8, and 0929cd9e.

Overall the update process was pretty straightforward. There were a few minor bugs along the way which were promptly fixed upstream. Having previously updated Hex.pm to Ecto 2.0, which took a few months (we started it early on, which made it a fast moving target back then), I can really appreciate the level of maturity that Ecto achieved and how easy it was to update this time around. 🙂

Update: Add note about pool_size when running migrations.

We are glad to be an active part of the process by contributing to the ecosystem and helping companies adopt Elixir at different stages of their adoption cycle. We would love to work with you too!

Do you think that your company could benefit from our expertise and assistance? Just click the button below.

banner-elixir development subscription

Comments are closed.