Releases: elixir-ecto/ecto
v0.12.0
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
Bug fixes
- Ensure confirmation is required if field is given but nil
Deprecations
:read_after_writes
is deprecated in favor of:autogenerate
inEcto.Schema.field/3
Repo.insert/2
is deprecated in favor ofRepo.insert!/2
Repo.update/2
is deprecated in favor ofRepo.update!/2
Repo.delete/2
is deprecated in favor ofRepo.delete!/2
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.
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.
v0.11.3
v0.11.2
Bug fixes
- Trigger
validate_unique/3
if the field or any of the scopes changed - Do not trigger
validate_unique/3
if the field or scopes contains errors - Ensure repo log calls can be optimized out
- Improve error message when model types are given on migrations
v0.11.1
v0.11.0
Enhancements
- Add
Ecto.Repo.get_by/3
andEcto.Repo.get_by!/3
- Add
to_erl
/from_erl
to datetime modules - Add
:scope
option toEcto.Changeset.validate_unique/2
- Allow
distinct(query, true)
query expression - Effectively track dirty changes in
Ecto.Changeset
. If the value being sent as parameter is the same as the value in the model, it won't be sent to the Repo on insert/update
Deprecations
- Deprecate
nil
as parameters inEcto.Changeset.cast/4
in favor of:empty
Backwards incompatible changes
- The pool size now defaults to 10 with no overflow. This will affect you if you were not explicitly setting those values in your pool configuration.
Ecto.Model
now only importsfrom/2
fromEcto.Query
out of the boxEcto.Changeset.apply/1
was removed in favor ofEcto.Changeset.apply_changes/1
v0.10.3
v0.10.2
Enhancements
- Add
Ecto.DateTime.from_date/1
- Allow adapter to be configured at the
:repo
level - Add
--quiet
toecto.migrate
,ecto.create
andecto.drop
tasks - Support
timestampz
type for PostgreSQL
Bug fixes
- Ensure
:invalid
error shows up as "is invalid" message - Improve support for "schema.table" queries in MySQL and PostgreSQL
v0.10.1
Enhancements
- Add an option to set the engine when creating a table (used by MySQL and defaults to InnoDB). This ensures Ecto works out of the box with earlier MySQL versions
Bug fixes
- No longer create database in
ecto.migrate
if one does not exist - Fix a bug where dates earlier than 2000 could not be saved in Postgres
v0.10.0
Enhancements
- Add
validate_number/3
toEcto.Changeset
- Add cardinality to
Ecto.Association.NotLoaded
- Allow
{"source", Model}
as a source in queries and associations - Add support for usec in
Ecto.Date
,Ecto.Time
andEcto.DateTime
- Add
usec: true
support toEcto.Schema.timestamps/1
- Create database in
ecto.migrate
if one does not exist Repo.preload/2
no longer preloads already loaded associations
Backwards incompatible changes
- Using
distict: EXPR
automatically sets the given distinct expressions inorder_by
__state__
field has been removed in favor of a__meta__
field which includes the state and the model source- Error messages in
Ecto.Changeset
now return strings instead of atoms Ecto.Model.primary_key/1
now returns a keyword list of primary key fields, returning an empty list when there is no primary key. UseEcto.Model.primary_key!/1
for the raising variant- Use simple representations when converting
Ecto.Date
,Ecto.Time
andEcto.DateTime
to strings. Useto_iso8601
for the ISO specific formatting @timestamps_type Your.Type
was removed in favor of@timestamps_opts [type: Your.Type]