v0.12.0-rc
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 toEcto.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. InsteadRepo.log/1
is called with anEcto.LogEntry
:auto_field
inbelongs_to/3
has been renamed to:define_field
:uuid
type has been removed in favor ofEcto.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
. Ifnil
, 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 isnil
, it means no value was supplied by the user and the database MUST return a new one.