Ecto 2.0.0-beta.0 is out!

Hello everyone,

We are really glad to announce that Ecto 2.0.0-beta.0 has been released. The upcoming Ecto version packs many goodies:

  • We have migrated to DBConnection, which considerably improves the performance of how Ecto manages connections to the database as a whole. Improved pool management, faster encoding/decoding, support for prepared queries and more
  • The effective deprecation of Ecto.Model in favor of a more data-oriented approach

  • Support for many_to_many associations and a more flexible approach to associations in general, including parallel preloading of associations

  • Introduction of a new SQL sandbox that allows developers to run database concurrent tests

  • Support for subqueries, composite primary keys, insert_all (alongside update_all and delete_all) and more

There are many more features, bug fixes and improvements. There are also backwards incompatible changes (hence the 2.0.0 version). We recommend you to check the CHANGELOG for more information.

We appreciate developers to give this beta version a try. Keep in mind this is a beta release: bugs and regressions may exist. If you encounter an unexpected behaviour, please open up an issue report.

When trying the beta version, please pay close attention to performance. We have measured performance improvements up to 50% in some situations, but other use cases may have degraded. Please let us know of any performance measurement you run, for both positive and negative net outcomes.

This release supports only the Postgrex adapter, for PostgreSQL. MySQL support and a couple extra features, like structure loading and dumping, will be added before 2.0.0 is released.

Using Ecto 2.0 in Phoenix projects

Using Ecto 2.0 in Phoenix projects is relatively straight-forward. For a newly generated project, changes should be made to your dependencies and test files.

The first step is to update your Phoenix.Ecto dependency to 3.0.0-beta in your mix.exs. This dependency will effectively depend on Ecto 2.0 and integrate it with Phoenix:

{:phoenix_ecto, "~> 3.0.0-beta"}

Phoenix projects by default use test transactions in the test environment. Ecto 2.0 replaces test transactions by the new SQL sandbox. In your test/test_helper.exs, replace the following



Ecto.Adapters.SQL.Sandbox.mode(Demo.Repo, :manual)

Then, in each test/support/*_case.ex file, replace:

unless tags[:async] do
  Ecto.Adapters.SQL.restart_test_transaction(Demo.Repo, [])


:ok = Ecto.Adapters.SQL.Sandbox.checkout(Demo.Repo)

Notice the new version no longer needs to guard against tags[:async]. With Ecto 2.0, you can run tests that depend on the database concurrently. For running acceptance tests via tools like Hound, you will currently need to use the shared mode but we will tackle it before the final 2.0 release. That’s all powered by and documented in the new SQL sandbox.

And that’s it! Of course, your project may have used other Ecto features that have been deprecated, so don’t forget to read the CHANGELOG.

We are also planning to release a series of blog posts, detailing and explaining the new Ecto 2.0 features, so keep posted!

Subscribe to Elixir Radar

11 responses to “Ecto 2.0.0-beta.0 is out!”

  1. parth_patil says:

    the line to include ecto 2.0 beta in mix.exs should be {:phoenix_ecto, “~> 2.0.0-beta”}

  2. josevalim says:

    The line is correct. phoenix_ecto 3.0.0-beta depends on ecto 2.0.0-beta. I will make this clearer in the blog post.

  3. parth_patil says:

    thanks for the clarification!

  4. Vanceone says:

    Is Ecto.Multi going to happen for version 2.0? I’ve not seen anything happen since December.

  5. jamilabreu says:

    Just a heads up for all the early learners out there: “Demo.Repo” should be changed to “[YourAppNameHere].Repo” 🙂

  6. jamilabreu says:

    Heads up, also need to add:

    {:ecto, github: “elixir-lang/ecto”, override: true}

    to mix.exs. Otherwise throws:

    ** (UndefinedFunctionError) undefined function XXXX.Repo.__adapter__/0

    on create.

  7. Vignesh Rajagopalan says:

    Does this mean, the setup block in the *_case.ex files is no more necessary?

    because the block in on the variable tags which is unused essentially.

  8. josevalim says:

    Yes, it has been merged already.

  9. josevalim says:

    No, you need to call “:ok = Ecto.Adapters.SQL.Sandbox.checkout(Demo.Repo)” as shown above in every setup.

  10. Vignesh Rajagopalan says:

    Figured that out. Thanks.

    So basically, It used to be

    setup tags do


    Now since there’s no need to check on tags, it’s just

    setup do
    :ok = Ecto.Adapters.SQL.Sandbox.checkout(Demo.Repo)

    Just wanted to leave it here

  11. Lin He says:

    Thanks for the hard work! Love Ecto.Multi 🙂