Skip to content

v0.12.0-rc

Compare
Choose a tag to compare
@josevalim josevalim released this 30 May 18:22
· 4149 commits to master since this release

This release includes major changes to Ecto schemas in order to improve UUID support.

In particular, if you were customizing your primary keys to use UUIDs, you will have to change your @primary_key configuration from:

@primary_key {:id, Ecto.UUID, read_after_writes: true}

To:

@primary_key {:id, :binary_id, autogenerate: true}

The :binary_id type means the semantics of the field are specified by the adapter/database. For all SQL databases, it means the field will be treated as Ecto.UUID. The difference is that :binary_id allows other adapters to provide their own logic for generating IDs, be it a RecordID, ObjectID and so on.

Furthermore, the autogenerate: true option is also supported by custom types, so one can write:

field :secret, Ecto.UUID, autogenerate: true

and Ecto will take care of automatically generating a secret before insertion. In this case, there is no need for setting the default in the database.

If you were not customizing your primary key, the default type for primary and foregin keys is now :id, which is synonymous to :integer, so no changes should be required in your application.

Finally, due to such improvements, :read_after_writes is deprecated. Even though the option may not be removed after all, we want to deprecate it in order to push everything to use the new syntax.

CHANGELOG

Enhancements

  • Add put_source/2 function to Ecto.Model
  • Allow binary literal syntax in queries
  • Optimize SQL transactions by reducing the amount of messages passed around
  • Provide Ecto.Adapters.Worker which can work across adapters and provides transactional semantics
  • Support :autogenerate for custom types
  • Introduce new :id and :binary_id types that support autogeneration inside primary keys and are handled by the database

Deprecations

  • :read_after_writes is deprecated in favor of :autogenerate

Backwards incompatible changes

  • Repo.log/2 is no longer invoked. Instead Repo.log/1 is called with an Ecto.LogEntry
  • :auto_field in belongs_to/3 has been renamed to :define_field
  • :uuid type has been removed in favor of Ecto.UUID

Adapters backwards incompatible changes

  • fragment AST now tags each argument as raw or expr
  • Ecto.Adapter.insert now receives an extra argument telling which key to autogenerate. The value may be: {field :: atom, type :: :id | :binary_id, value :: term | nil} | nil. If nil, there is no key to autogenerate. If a tuple, it may have type :id or :binary_id with semantics to be specified by the adapter/database. Finally, if the value is nil, it means no value was supplied by the user and the database MUST return a new one.