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.begin_test_transaction(Demo.Repo)

by

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, [])
end

by

: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

Share on FacebookShare on Google+Tweet about this on TwitterShare on LinkedInEmail this to someone
  • parth_patil

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

  • 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.

  • parth_patil

    thanks for the clarification!

  • Vanceone

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

  • jamilabreu

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

  • jamilabreu

    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.

  • Vignesh Rajagopalan

    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.

  • Yes, it has been merged already.

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

  • Vignesh Rajagopalan

    Figured that out. Thanks.

    So basically, It used to be

    setup tags do

    end

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

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

    Just wanted to leave it here

  • Lin He

    Thanks for the hard work! Love Ecto.Multi 🙂