CHANGELOG.md (37139B)
1 # Changelog for v3.x 2 3 ## v3.9.1 (2022-10-06) 4 5 ### Enhancements 6 7 * [Ecto.Query] Allow `selected_as` at the root of `dynamic/2` 8 * [Ecto.Query] Allow `selected_as` to be used with `type/2` 9 * [Ecto.Query] Allow `selected_as` to be used with `select_merge` 10 11 ### Bug fixes 12 13 * [Ecto.Changeset] Reenable support for embedded schemas in `unsafe_validate_unique/4` 14 * [Ecto.Query] Ensure `join_where` conditions preload correctly in `many_to_many` or with queries with one or many joins 15 16 ## v3.9.0 (2022-09-27) 17 18 ### Enhancements 19 20 * [Ecto.Changeset] Add `:force_changes` option to `cast/4` 21 * [Ecto.Enum] Allow enum fields to be embed either as their values or their dumped versions 22 * [Ecto.Query] Support `^%{field: dynamic(...)}` in `select` and `select_merge` 23 * [Ecto.Query] Support `%{field: subquery(...)}` in `select` and `select_merge` 24 * [Ecto.Query] Support select aliases through `selected_as/1` and `selected_as/2` 25 * [Ecto.Query] Allow `parent_as/1` in `type/2` 26 * [Ecto.Query] Add `with_named_binding/3` 27 * [Ecto.Query] Allow fragment sources in keyword queries 28 * [Ecto.Repo] Support `idle_interval` query parameter in connection URL 29 * [Ecto.Repo] Log human-readable UUIDs by using pre-dumped query parameters 30 * [Ecto.Schema] Support preloading associations in embedded schemas 31 32 ### Bug fix 33 34 * [Ecto.Changeset] Raise when schemaless changeset or embedded schema is used in `unsafe_validate_unique/4` 35 * [Ecto.Query] Respect virtual field type in subqueries 36 * [Ecto.Query] Don't select struct fields overridden with `nil` 37 * [Ecto.Query] Fix `select_merge` not tracking `load_in_query: false` field 38 * [Ecto.Query] Fix field source when used in `json_extract_path` 39 * [Ecto.Query] Properly build CTEs at compile time 40 * [Ecto.Query] Properly order subqueries in `dynamic` 41 * [Ecto.Repo] Fix `insert_all` query parameter count when using value queries alongside `placeholder` 42 * [Ecto.Repo] Raise if combination query is used in a `many` preload 43 * [Ecto.Schema] Ignore associations that aren't loaded on insert 44 45 ## v3.8.4 (2022-06-04) 46 47 ### Enhancements 48 49 * [Ecto.Multi] Add `one/2` and `all/2` functions 50 * [Ecto.Query] Support `literal(...)` in `fragment` 51 52 ### Bug fix 53 54 * [Ecto.Schema] Make sure fields are inspected in the correct order in Elixir v1.14+ 55 56 ## v3.8.3 (2022-05-11) 57 58 ### Bug fix 59 60 * [Ecto.Query] Allow source aliases to be used in `type/2` 61 * [Ecto.Schema] Avoid "undefined behaviour/struct" warnings and errors during compilation 62 63 ## v3.8.2 (2022-05-05) 64 65 ### Bug fix 66 67 * [Ecto.Adapter] Do not require adapter metadata to be raw maps 68 * [Ecto.Association] Respect `join_where` in many to many `on_replace` deletes 69 * [Ecto.Changeset] Check if list is in `empty_values` before nested validations 70 71 ## v3.8.1 (2022-04-27) 72 73 ### Bug fix 74 75 * [Ecto.Query] Fix regression where a join's on parameter on `update_all` was out of order 76 77 ## v3.8.0 (2022-04-26) 78 79 Ecto v3.8 requires Elixir v1.10+. 80 81 ### Enhancements 82 83 * [Ecto] Add new Embedded chapter to Introductory guides 84 * [Ecto.Changeset] Allow custom `:error_key` in unique_constraint 85 * [Ecto.Changeset] Add `:match` option to all constraint functions 86 * [Ecto.Query] Support dynamic aliases 87 * [Ecto.Query] Allow using `type/2` with virtual fields 88 * [Ecto.Query] Suggest alternatives to inexistent fields in queries 89 * [Ecto.Query] Support passing queries using subqueries to `insert_all` 90 * [Ecto.Repo] Allow `stacktrace: true` so stacktraces are included in telemetry events and logs 91 * [Ecto.Schema] Validate options given to schema fields 92 93 ### Bug fixes 94 95 * [Ecto.Changeset] Address regression on `validate_subset` no longer working with custom array types 96 * [Ecto.Changeset] **Potentially breaking change**: Detect `empty_values` inside lists when casting. This may cause issues if you were relying on the casting of empty values (by default, only `""`). 97 * [Ecto.Query] Handle atom list sigils in `select` 98 * [Ecto.Query] Improve tracking of `select_merge` inside subqueries 99 * [Ecto.Repo] Properly handle literals in queries given to `insert_all` 100 * [Ecto.Repo] Don't surface persisted data as changes on embed updates 101 * [Ecto.Schema] Preserve parent prefix on join tables 102 103 ## v3.7.2 (2022-03-13) 104 105 ### Enhancements 106 107 * [Ecto.Schema] Add option to skip validations for default values 108 * [Ecto.Query] Allow coalesce in `type/2` 109 * [Ecto.Query] Support parameterized types in type/2 110 * [Ecto.Query] Allow arbitrary parentheses in query expressions 111 112 ## v3.7.1 (2021-08-27) 113 114 ### Enhancements 115 116 * [Ecto.Embedded] Make `Ecto.Embedded` public and describe struct fields 117 118 ### Bug fixes 119 120 * [Ecto.Repo] Make sure parent changeset is included in changes for `insert`/`update`/`delete` when there are errors processing the parent itself 121 122 ## v3.7.0 (2021-08-19) 123 124 ### Enhancements 125 126 * [Ecto.Changeset] Add `Ecto.Changeset.traverse_validations/2` 127 * [Ecto.Enum] Add `Ecto.Enum.mappings/2` and `Ecto.Enum.dump_values/2` 128 * [Ecto.Query] Add support for dynamic `as(^as)` and `parent_as(^as)` 129 * [Ecto.Repo] Add stale changeset to `Ecto.StaleEntryError` fields 130 * [Ecto.Schema] Add support for `@schema_context` to set context metadata on schema definition 131 132 ### Bug fixes 133 134 * [Ecto.Changeset] Fix changeset inspection not redacting when embedded 135 * [Ecto.Changeset] Use semantic comparison on `validate_inclusion`, `validate_exclusion`, and `validate_subset` 136 * [Ecto.Enum] Raise on duplicate values in `Ecto.Enum` 137 * [Ecto.Query] Make sure `hints` are included in the query cache 138 * [Ecto.Repo] Support placeholders in `insert_all` without schemas 139 * [Ecto.Repo] Wrap in a subquery when query given to `Repo.aggregate` has combination 140 * [Ecto.Repo] Fix CTE subqueries not finding parent bindings 141 * [Ecto.Repo] Return changeset with assocs if any of the assocs are invalid 142 143 ## v3.6.2 (2021-05-28) 144 145 ### Enhancements 146 147 * [Ecto.Query] Support macros in `with_cte` 148 * [Ecto.Repo] Add `Ecto.Repo.all_running/0` to list all running repos 149 150 ### Bug fixes 151 152 * [Ecto.Query] Do not omit nil fields in a subquery select 153 * [Ecto.Query] Allow `parent_as` to look for an alias all the way up across subqueries 154 * [Ecto.Query] Raise if a nil value is given to a query from a nested map parameter 155 * [Ecto.Query] Fix `insert_all` when using both `:on_conflict` and `:placeholders` 156 * [mix ecto.load] Do not pass `--force` to underlying compile task 157 158 ## v3.6.1 (2021-04-12) 159 160 ### Enhancements 161 162 * [Ecto.Changeset] Allow the `:query` option in `unsafe_validate_unique` 163 164 ### Bug fixes 165 166 * [Ecto.Changeset] Add the relation id in `apply_changes` if the relation key exists (instead of hardcoding it to `id`) 167 168 ## v3.6.0 (2021-04-03) 169 170 ### Enhancements 171 172 * [Ecto.Changeset] Support `:repo_opts` in `unsafe_validate_unique` 173 * [Ecto.Changeset] Add a validation error if trying to cast a cardinality one embed/assoc with anything other than a map or keyword list 174 * [Ecto.Enum] Allow enums to map to custom values 175 * [Ecto.Multi] Add `Ecto.Multi.put/3` for directly storing values 176 * [Ecto.Query] **Potentially breaking change**: optimize `many_to_many` queries so it no longer load intermediary tables in more occasions. This may cause issues if you are using `Ecto.assoc/2` to load `many_to_many` associations and then trying to access intermediate bindings (which is discouraged but it was possible) 177 * [Ecto.Repo] Allow `insert_all` to be called with a query instead of rows 178 * [Ecto.Repo] Add `:placeholders` support to `insert_all` to avoid sending the same value multiple times 179 * [Ecto.Schema] Support `:preload_order` on `has_many` and `many_to_many` associations 180 * [Ecto.UUID] Add bang UUID conversion methods 181 * [Ecto.Query] The `:hints` option now accepts dynamic values when supplied as tuples 182 * [Ecto.Query] Support `select: map(source, fields)` where `source` is a fragment 183 * [Ecto.Query] Allow referring to the parent query in a join's subquery select via `parent_as` 184 * [mix ecto] Support file and line interpolation on `ECTO_EDITOR` 185 186 ### Bug fixes 187 188 * [Ecto.Changeset] Change `apply_changes/1` to add the relation to the `struct.relation_id` if relation struct is persisted 189 * [Ecto.Query] Remove unnecessary INNER JOIN in many to many association query 190 * [Ecto.Query] Allow parametric types to be interpolated in queries 191 * [Ecto.Schema] Raise `ArgumentError` when default has invalid type 192 193 ## v3.5.8 (2021-02-21) 194 195 ### Enhancements 196 197 * [Ecto.Query] Support map/2 on fragments and subqueries 198 199 ## v3.5.7 (2021-02-07) 200 201 ### Bug fixes 202 203 * [Ecto.Query] Fixes param ordering issue on dynamic queries with subqueries 204 205 ## v3.5.6 (2021-01-20) 206 207 ### Enhancements 208 209 * [Ecto.Schema] Support `on_replace: :delete_if_exists` on associations 210 211 ### Bug fixes 212 213 * [Ecto.Query] Allow unary minus operator in query expressions 214 * [Ecto.Schema] Allow nil values on typed maps 215 216 ## v3.5.5 (2020-11-12) 217 218 ### Enhancements 219 220 * [Ecto.Query] Add support for subqueries operators: `all`, `any`, and `exists` 221 222 ### Bug fixes 223 224 * [Ecto.Changeset] Use association source on `put_assoc` with maps/keywords 225 * [Ecto.Enum] Add `cast` clause for nil values on `Ecto.Enum` 226 * [Ecto.Schema] Allow nested type `:any` for non-virtual fields 227 228 ## v3.5.4 (2020-10-28) 229 230 ### Enhancements 231 232 * [mix ecto.drop] Provide `--force-drop` for databases that may support it 233 * [guides] Add new "Multi tenancy with foreign keys" guide 234 235 ### Bug fixes 236 237 * [Ecto.Changeset] Make keys optional in specs 238 * [Ecto.Enum] Make sure `values/2` works for virtual fields 239 * [Ecto.Query] Fix missing type on CTE queries that select a single field 240 241 ## v3.5.3 (2020-10-21) 242 243 ### Bug fixes 244 245 * [Ecto.Query] Do not reset parameter counter for nested CTEs 246 * [Ecto.Type] Fix regression where array type with nils could no longer be cast/load/dump 247 * [Ecto.Type] Fix CaseClauseError when casting a decimal with a binary remainder 248 249 ## v3.5.2 (2020-10-12) 250 251 ### Enhancements 252 253 * [Ecto.Repo] Add Repo.reload/2 and Repo.reload!/2 254 255 ### Bug fixes 256 257 * [Ecto.Changeset] Fix "__schema__/1 is undefined or private" error while inspecting a schemaless changeset 258 * [Ecto.Repo] Invoke `c:Ecto.Repo.default_options/1` per entry-point operation 259 260 ## v3.5.1 (2020-10-08) 261 262 ### Enhancements 263 264 * [Ecto.Changeset] Warn if there are duplicate IDs in the parent schema for `cast_assoc/3`/`cast_embed/3` 265 * [Ecto.Schema] Allow `belongs_to` to accept options for parameterized types 266 267 ### Bug fixes 268 269 * [Ecto.Query] Keep field types when using a subquery with source 270 271 ## v3.5.0 (2020-10-03) 272 273 v3.5 requires Elixir v1.8+. 274 275 ### Bug fixes 276 277 * [Ecto.Changeset] Ensure `:empty_values` in `cast/4` does not automatically propagate to following cast calls. If you want a given set of `:empty_values` to apply to all `cast/4` calls, change the value stored in `changeset.empty_values` instead 278 * [Ecto.Changeset] **Potentially breaking change**: Do not force repository updates to happen when using `optimistic_lock`. The lock field will only be incremented if the record has other changes. If no changes, nothing happens. 279 * [Ecto.Changeset] Do not automatically share empty values across `cast/3` calls 280 * [Ecto.Query] Consider query prefix in cte/combination query cache 281 * [Ecto.Query] Allow the entry to be marked as nil when using left join with subqueries 282 * [Ecto.Query] Support subqueries inside dynamic expressions 283 * [Ecto.Repo] Fix preloading when using dynamic repos and the sandbox in automatic mode 284 * [Ecto.Repo] Do not duplicate collections when associations are preloaded for repeated elements 285 286 ### Enhancements 287 288 * [Ecto.Enum] Add `Ecto.Enum` as a custom parameterized type 289 * [Ecto.Query] Allow `:prefix` in `from` to be set to nil 290 * [Ecto.Query] Do not restrict subqueries in `where` to map/struct types 291 * [Ecto.Query] Allow atoms in query without interpolation in order to support Ecto.Enum 292 * [Ecto.Schema] Do not validate uniqueness if there is a prior error on the field 293 * [Ecto.Schema] Allow `redact: true` in `field` 294 * [Ecto.Schema] Support parameterized types via `Ecto.ParameterizedType` 295 * [Ecto.Schema] Rewrite embeds and assocs as parameterized types. This means `__schema__(:type, assoc_or_embed)` now returns a parameterized type. To check if something is an association, use `__schema__(:assocs)` or `__schema__(:embeds)` instead 296 297 ## v3.4.6 (2020-08-07) 298 299 ### Enhancements 300 301 * [Ecto.Query] Allow `count/0` on `type/2` 302 * [Ecto.Multi] Support anonymous functions in multiple functions 303 304 ### Bug fixes 305 306 * [Ecto.Query] Consider booleans as literals in unions, subqueries, ctes, etc 307 * [Ecto.Schema] Generate IDs for nested embeds 308 309 ## v3.4.5 (2020-06-14) 310 311 ### Enhancements 312 313 * [Ecto.Changeset] Allow custom error key in `unsafe_validate_unique` 314 * [Ecto.Changeset] Improve performance when casting large params maps 315 316 ### Bug fixes 317 318 * [Ecto.Changeset] Improve error message for invalid `cast_assoc` 319 * [Ecto.Query] Fix inspecting query with fragment CTE 320 * [Ecto.Query] Fix inspecting dynamics with aliased bindings 321 * [Ecto.Query] Improve error message when selecting a single atom 322 * [Ecto.Repo] Reduce data-copying when preloading multiple associations 323 * [Ecto.Schema] Do not define a compile-time dependency for schema in `:join_through` 324 325 ## v3.4.4 (2020-05-11) 326 327 ### Enhancements 328 329 * [Ecto.Schema] Add `join_where` support to `many_to_many` 330 331 ## v3.4.3 (2020-04-27) 332 333 ### Enhancements 334 335 * [Ecto.Query] Support `as/1` and `parent_as/1` for lazy named bindings and to allow parent references from subqueries 336 * [Ecto.Query] Support `x in subquery(query)` 337 338 ### Bug fixes 339 340 * [Ecto.Query] Do not raise for missing assocs if :force is given to preload 341 * [Ecto.Repo] Return error from `Repo.delete` on invalid changeset from `prepare_changeset` 342 343 ## v3.4.2 (2020-04-10) 344 345 ### Enhancements 346 347 * [Ecto.Changeset] Support multiple fields in `unique_constraint/3` 348 349 ## v3.4.1 (2020-04-08) 350 351 ### Enhancements 352 353 * [Ecto] Add `Ecto.embedded_load/3` and `Ecto.embedded_dump/2` 354 * [Ecto.Query] Improve error message on invalid JSON expressions 355 * [Ecto.Repo] Emit `[:ecto, :repo, :init]` telemetry event upon Repo init 356 357 ### Bug fixes 358 359 * [Ecto.Query] Do not support JSON selectors on `type/2` 360 361 ### Deprecations 362 363 * [Ecto.Repo] Deprecate `conflict_target: {:constraint, _}`. It is a discouraged approach and `{:unsafe_fragment, _}` is still available if someone definitely needs it 364 365 ## v3.4.0 (2020-03-24) 366 367 v3.4 requires Elixir v1.7+. 368 369 ### Enhancements 370 371 * [Ecto.Query] Allow dynamic queries in CTE and improve error message 372 * [Ecto.Query] Add `Ecto.Query.API.json_extract_path/2` and JSON path support to query syntax. For example, `posts.metadata["tags"][0]["name"]` will return the name of the first tag stored in the `:map` metadata field 373 * [Ecto.Repo] Add new `default_options/1` callback to repository 374 * [Ecto.Repo] Support passing `:telemetry_options` to repository operations 375 376 ### Bug fixes 377 378 * [Ecto.Changeset] Properly add validation annotation to `validate_acceptance` 379 * [Ecto.Query] Raise if there is loaded non-empty association data without related key when preloading. This typically means not all fields have been loaded in a query 380 * [Ecto.Schema] Show meaningful error in case `schema` is invoked twice in an `Ecto.Schema` 381 382 ## v3.3.4 (2020-02-27) 383 384 ### Bug fixes 385 386 * [mix ecto] Do not rely on map ordering when parsing repos 387 * [mix ecto.gen.repo] Improve error message when a repo is not given 388 389 ## v3.3.3 (2020-02-14) 390 391 ### Enhancements 392 393 * [Ecto.Query] Support fragments in `lock` 394 * [Ecto.Query] Handle `nil` in `select_merge` with similar semantics to SQL databases (i.e. it simply returns `nil` itself) 395 396 ## v3.3.2 (2020-01-28) 397 398 ### Enhancements 399 400 * [Ecto.Changeset] Only bump optimistic lock in case of success 401 * [Ecto.Query] Allow macros in Ecto window expressions 402 * [Ecto.Schema] Support `:join_defaults` on `many_to_many` associations 403 * [Ecto.Schema] Allow MFargs to be given to association `:defaults` 404 * [Ecto.Type] Add `Ecto.Type.embedded_load` and `Ecto.Type.embedded_dump` 405 406 ### Bug fixes 407 408 * [Ecto.Repo] Ignore empty hostname when parsing database url (Elixir v1.10 support) 409 * [Ecto.Repo] Rewrite combinations on Repo.exists? queries 410 * [Ecto.Schema] Respect child `@schema_prefix` in `cast_assoc` 411 * [mix ecto.gen.repo] Use `config_path` when writing new config in `mix ecto.gen.repo` 412 413 ## v3.3.1 (2019-12-27) 414 415 ### Enhancements 416 417 * [Ecto.Query.WindowAPI] Support `filter/2` 418 419 ### Bug fixes 420 421 * [Ecto.Query.API] Fix `coalesce/2` usage with mixed types 422 423 ## v3.3.0 (2019-12-11) 424 425 ### Enhancements 426 427 * [Ecto.Adapter] Add `storage_status/1` callback to `Ecto.Adapters.Storage` behaviour 428 * [Ecto.Changeset] Add `Ecto.Changeset.apply_action!/2` 429 * [Ecto.Changeset] Remove actions restriction in `Ecto.Changeset.apply_action/2` 430 * [Ecto.Repo] Introduce `c:Ecto.Repo.aggregate/2` 431 * [Ecto.Repo] Support `{:replace_all_except, fields}` in `:on_conflict` 432 433 ### Bug fixes 434 435 * [Ecto.Query] Make sure the `:prefix` option in `:from`/`:join` also cascades to subqueries 436 * [Ecto.Query] Make sure the `:prefix` option in `:join` also cascades to queries 437 * [Ecto.Query] Use database returned values for literals. Previous Ecto versions knew literals from queries should not be discarded for combinations but, even if they were not discarded, we would ignore the values returned by the database 438 * [Ecto.Repo] Do not wrap schema operations in a transaction if already inside a transaction. We have also removed the **private** option called `:skip_transaction` 439 440 ### Deprecations 441 442 * [Ecto.Repo] `:replace_all_except_primary_keys` is deprecated in favor of `{:replace_all_except, fields}` in `:on_conflict` 443 444 ## v3.2.5 (2019-11-03) 445 446 ### Bug fixes 447 448 * [Ecto.Query] Fix a bug where executing some queries would leak the `{:maybe, ...}` type 449 450 ## v3.2.4 (2019-11-02) 451 452 ### Bug fixes 453 454 * [Ecto.Query] Improve error message on invalid join binding 455 * [Ecto.Query] Make sure the `:prefix` option in `:join` also applies to through associations 456 * [Ecto.Query] Invoke custom type when loading aggregations from the database (but fallback to database value if it can't be cast) 457 * [mix ecto.gen.repo] Support Elixir v1.9 style configs 458 459 ## v3.2.3 (2019-10-17) 460 461 ### Bug fixes 462 463 * [Ecto.Changeset] Do not convert enums given to `validate_inclusion` to a list 464 465 ### Enhancements 466 467 * [Ecto.Changeset] Improve error message on non-atom keys to change/put_change 468 * [Ecto.Changeset] Allow :with to be given as a `{module, function, args}` tuple on `cast_association/cast_embed` 469 * [Ecto.Changeset] Add `fetch_change!/2` and `fetch_field!/2` 470 471 ## v3.2.2 (2019-10-01) 472 473 ### Bug fixes 474 475 * [Ecto.Query] Fix keyword arguments given to `:on` when a bind is not given to join 476 * [Ecto.Repo] Make sure a preload given to an already preloaded has_many :through is loaded 477 478 ## v3.2.1 (2019-09-17) 479 480 ### Enhancements 481 482 * [Ecto.Changeset] Add rollover logic for default incrementer in `optimistic_lock` 483 * [Ecto.Query] Also expand macros when used inside `type/2` 484 485 ### Bug fixes 486 487 * [Ecto.Query] Ensure queries with non-cacheable queries in CTEs/combinations are also not-cacheable 488 489 ## v3.2.0 (2019-09-07) 490 491 v3.2 requires Elixir v1.6+. 492 493 ### Enhancements 494 495 * [Ecto.Query] Add common table expressions support `with_cte/3` and `recursive_ctes/2` 496 * [Ecto.Query] Allow `dynamic/3` to be used in `order_by`, `distinct`, `group_by`, as well as in `partition_by`, `order_by`, and `frame` inside `windows` 497 * [Ecto.Query] Allow filters in `type/2` expressions 498 * [Ecto.Repo] Merge options given to the repository into the changeset `repo_opts` and assign it back to make it available down the chain 499 * [Ecto.Repo] Add `prepare_query/3` callback that is invoked before query operations 500 * [Ecto.Repo] Support `:returning` option in `Ecto.Repo.update/2` 501 * [Ecto.Repo] Support passing a one arity function to `Ecto.Repo.transaction/2`, where the argument is the current repo 502 * [Ecto.Type] Add a new `embed_as/1` callback to `Ecto.Type` that allows adapters to control embedding behaviour 503 * [Ecto.Type] Add `use Ecto.Type` for convenience that implements the new required callbacks 504 505 ### Bug fixes 506 507 * [Ecto.Association] Ensure we delete an association before inserting when replacing on `has_one` 508 * [Ecto.Query] Do not allow interpolated `nil` in literal keyword list when building query 509 * [Ecto.Query] Do not remove literals from combinations, otherwise UNION/INTERSECTION queries may not match the number of values in `select` 510 * [Ecto.Query] Do not attempt to merge at compile-time non-keyword lists given to `select_merge` 511 * [Ecto.Repo] Do not override `:through` associations on preload unless forcing 512 * [Ecto.Repo] Make sure prefix option cascades to combinations and recursive queries 513 * [Ecto.Schema] Use OS time without drift when generating timestamps 514 * [Ecto.Type] Allow any datetime in `datetime_add` 515 516 ## v3.1.7 (2019-06-27) 517 518 ### Bug fixes 519 520 * [Ecto.Changeset] Make sure `put_assoc` with empty changeset propagates on insert 521 522 ## v3.1.6 (2019-06-19) 523 524 ### Enhancements 525 526 * [Ecto.Repo] Add `:read_only` repositories 527 * [Ecto.Schema] Also validate options given to `:through` associations 528 529 ### Bug fixes 530 531 * [Ecto.Changeset] Do not mark `put_assoc` from `[]` to `[]` or from `nil` to `nil` as change 532 * [Ecto.Query] Remove named binding when excluding joins 533 * [mix ecto.gen.repo] Use `:config_path` instead of hardcoding to `config/config.exs` 534 535 ## v3.1.5 (2019-06-06) 536 537 ### Enhancements 538 539 * [Ecto.Repo] Allow `:default_dynamic_repo` option on `use Ecto.Repo` 540 * [Ecto.Schema] Support `{:fragment, ...}` in the `:where` option for associations 541 542 ### Bug fixes 543 544 * [Ecto.Query] Fix handling of literals in combinators (union, except, intersection) 545 546 ## v3.1.4 (2019-05-07) 547 548 ### Bug fixes 549 550 * [Ecto.Changeset] Convert validation enums to lists before adding them as validation metadata 551 * [Ecto.Schema] Properly propagate prefix to join_through source in many_to_many associations 552 553 ## v3.1.3 (2019-04-30) 554 555 ### Enhancements 556 557 * [Ecto.Changeset] Expose the enum that was validated against in errors from enum-based validations 558 559 ## v3.1.2 (2019-04-24) 560 561 ### Enhancements 562 563 * [Ecto.Query] Add support for `type+over` 564 * [Ecto.Schema] Allow schema fields to be excluded from queries 565 566 ### Bug fixes 567 568 * [Ecto.Changeset] Do not list a field as changed if it is updated to its original value 569 * [Ecto.Query] Keep literal numbers and bitstring in subqueries and unions 570 * [Ecto.Query] Improve error message for invalid `type/2` expression 571 * [Ecto.Query] Properly count interpolations in `select_merge/2` 572 573 ## v3.1.1 (2019-04-04) 574 575 ### Bug fixes 576 577 * [Ecto] Do not require Jason (i.e. it should continue to be an optional dependency) 578 * [Ecto.Repo] Make sure `many_to_many` and `Ecto.Multi` work with dynamic repos 579 580 ## v3.1.0 (2019-04-02) 581 582 v3.1 requires Elixir v1.5+. 583 584 ### Enhancements 585 586 * [Ecto.Changeset] Add `not_equal_to` option for `validate_number` 587 * [Ecto.Query] Improve error message for missing `fragment` arguments 588 * [Ecto.Query] Improve error message on missing struct key for structs built in `select` 589 * [Ecto.Query] Allow dynamic named bindings 590 * [Ecto.Repo] Add dynamic repository support with `Ecto.Repo.put_dynamic_repo/1` and `Ecto.Repo.get_dynamic_repo/0` (experimental) 591 * [Ecto.Type] Cast naive_datetime/utc_datetime strings without seconds 592 593 ### Bug fixes 594 595 * [Ecto.Changeset] Do not run `unsafe_validate_unique` query unless relevant fields were changed 596 * [Ecto.Changeset] Raise if an unknown field is given on `Ecto.Changeset.change/2` 597 * [Ecto.Changeset] Expose the type that was validated in errors generated by `validate_length/3` 598 * [Ecto.Query] Add support for `field/2` as first element of `type/2` and alias as second element of `type/2` 599 * [Ecto.Query] Do not attempt to assert types of named bindings that are not known at compile time 600 * [Ecto.Query] Properly cast boolean expressions in select 601 * [Mix.Ecto] Load applications during repo lookup so their app environment is available 602 603 ### Deprecations 604 605 * [Ecto.LogEntry] Fully deprecate previously soft deprecated API 606 607 ## v3.0.7 (2019-02-06) 608 609 ### Bug fixes 610 611 * [Ecto.Query] `reverse_order` reverses by primary key if no order is given 612 613 ## v3.0.6 (2018-12-31) 614 615 ### Enhancements 616 617 * [Ecto.Query] Add `reverse_order/1` 618 619 ### Bug fixes 620 621 * [Ecto.Multi] Raise better error message on accidental rollback inside `Ecto.Multi` 622 * [Ecto.Query] Properly merge deeply nested preloaded joins 623 * [Ecto.Query] Raise better error message on missing select on schemaless queries 624 * [Ecto.Schema] Fix parameter ordering in assoc `:where` 625 626 ## v3.0.5 (2018-12-08) 627 628 ### Backwards incompatible changes 629 630 * [Ecto.Schema] The `:where` option added in Ecto 3.0.0 had a major flaw and it has been reworked in this version. This means a tuple of three elements can no longer be passed to `:where`, instead a keyword list must be given. Check the "Filtering associations" section in `has_many/3` docs for more information 631 632 ### Bug fixes 633 634 * [Ecto.Query] Do not raise on lists of tuples that are not keywords. Instead, let custom Ecto.Type handle them 635 * [Ecto.Query] Allow `prefix: nil` to be given to subqueries 636 * [Ecto.Query] Use different cache keys for unions/intersections/excepts 637 * [Ecto.Repo] Fix support for upserts with `:replace` without a schema 638 * [Ecto.Type] Do not lose precision when casting `utc_datetime_usec` with a time zone different than Etc/UTC 639 640 ## v3.0.4 (2018-11-29) 641 642 ### Enhancements 643 644 * [Decimal] Bump decimal dependency 645 * [Ecto.Repo] Remove unused `:pool_timeout` 646 647 ## v3.0.3 (2018-11-20) 648 649 ### Enhancements 650 651 * [Ecto.Changeset] Add `count: :bytes` option in `validate_length/3` 652 * [Ecto.Query] Support passing `Ecto.Query` in `Ecto.Repo.insert_all` 653 654 ### Bug fixes 655 656 * [Ecto.Type] Respect adapter types when loading/dumping arrays and maps 657 * [Ecto.Query] Ensure no bindings in order_by when using combinations in `Ecto.Query` 658 * [Ecto.Repo] Ensure adapter is compiled (instead of only loaded) before invoking it 659 * [Ecto.Repo] Support new style child spec from adapters 660 661 ## v3.0.2 (2018-11-17) 662 663 ### Bug fixes 664 665 * [Ecto.LogEntry] Bring old Ecto.LogEntry APIs back for compatibility 666 * [Ecto.Repo] Consider non-joined fields when merging preloaded assocs only at root 667 * [Ecto.Repo] Take field sources into account in :replace_all_fields upsert option 668 * [Ecto.Type] Convert `:utc_datetime` to `DateTime` when sending it to adapters 669 670 ## v3.0.1 (2018-11-03) 671 672 ### Bug fixes 673 674 * [Ecto.Query] Ensure parameter order is preserved when using more than 32 parameters 675 * [Ecto.Query] Consider query prefix when planning association joins 676 * [Ecto.Repo] Consider non-joined fields as unique parameters when merging preloaded query assocs 677 678 ## v3.0.0 (2018-10-29) 679 680 Note this version includes changes from `ecto` and `ecto_sql` but in future releases all `ecto_sql` entries will be listed in their own CHANGELOG. 681 682 ### Enhancements 683 684 * [Ecto.Adapters.MySQL] Add ability to specify cli_protocol for `ecto.create` and `ecto.drop` commands 685 * [Ecto.Adapters.PostgreSQL] Add ability to specify maintenance database name for PostgreSQL adapter for `ecto.create` and `ecto.drop` commands 686 * [Ecto.Changeset] Store constraint name in error metadata for constraints 687 * [Ecto.Changeset] Add `validations/1` and `constraints/1` instead of allowing direct access on the struct fields 688 * [Ecto.Changeset] Add `:force_update` option when casting relations, to force an update even if there are no changes 689 * [Ecto.Migration] Migrations now lock the migrations table in order to avoid concurrent migrations in a cluster. The type of lock can be configured via the `:migration_lock` repository configuration and defaults to "FOR UPDATE" or disabled if set to nil 690 * [Ecto.Migration] Add `:migration_default_prefix` repository configuration 691 * [Ecto.Migration] Add reversible version of `remove/2` subcommand 692 * [Ecto.Migration] Add support for non-empty arrays as defaults in migrations 693 * [Ecto.Migration] Add support for logging notices/alerts/warnings when running migrations (only supported by Postgres currently) 694 * [Ecto.Migrator] Warn when migrating and there is a higher version already migrated in the database 695 * [Ecto.Multi] Add support for anonymous functions in `insert/4`, `update/4`, `insert_or_update/4`, and `delete/4` 696 * [Ecto.Query] Support tuples in `where` and `having`, allowing queries such as `where: {p.foo, p.bar} > {^foo, ^bar}` 697 * [Ecto.Query] Support arithmetic operators in queries as a thin layer around the DB functionality 698 * [Ecto.Query] Allow joins in queries to be named via `:as` and allow named bindings 699 * [Ecto.Query] Support excluding specific join types in `exclude/2` 700 * [Ecto.Query] Allow virtual field update in subqueries 701 * [Ecto.Query] Support `coalesce/2` in queries, such as `select: coalesce(p.title, p.old_title)` 702 * [Ecto.Query] Support `filter/2` in queries, such as `select: filter(count(p.id), p.public == true)` 703 * [Ecto.Query] The `:prefix` and `:hints` options are now supported on both `from` and `join` expressions 704 * [Ecto.Query] Support `:asc_nulls_last`, `:asc_nulls_first`, `:desc_nulls_last`, and `:desc_nulls_first` in `order_by` 705 * [Ecto.Query] Allow variables (sources) to be given in queries, for example, useful for invoking functions, such as `fragment("some_function(?)", p)` 706 * [Ecto.Query] Add support for `union`, `union_all`, `intersection`, `intersection_all`, `except` and `except_all` 707 * [Ecto.Query] Add support for `windows` and `over` 708 * [Ecto.Query] Raise when comparing a string with a charlist during planning 709 * [Ecto.Repo] Only start transactions if an association or embed has changed, this reduces the overhead during repository operations 710 * [Ecto.Repo] Support `:replace_all_except_primary_key` as `:on_conflict` strategy 711 * [Ecto.Repo] Support `{:replace, fields}` as `:on_conflict` strategy 712 * [Ecto.Repo] Support `:unsafe_fragment` as `:conflict_target` 713 * [Ecto.Repo] Support `select` in queries given to `update_all` and `delete_all` 714 * [Ecto.Repo] Add `Repo.exists?/2` 715 * [Ecto.Repo] Add `Repo.checkout/2` - useful when performing multiple operations in short-time to interval, allowing the pool to be bypassed 716 * [Ecto.Repo] Add `:stale_error_field` to `Repo.insert/update/delete` that converts `Ecto.StaleEntryError` into a changeset error. The message can also be set with `:stale_error_message` 717 * [Ecto.Repo] Preloading now only sorts results by the relationship key instead of sorting by the whole struct 718 * [Ecto.Schema] Allow `:where` option to be given to `has_many`/`has_one`/`belongs_to`/`many_to_many` 719 720 ### Bug fixes 721 722 * [Ecto.Inspect] Do not fail when inspecting query expressions which have a number of bindings more than bindings available 723 * [Ecto.Migration] Keep double underscores on autogenerated index names to be consistent with changesets 724 * [Ecto.Query] Fix `Ecto.Query.API.map/2` for single nil column with join 725 * [Ecto.Migration] Ensure `create_if_not_exists` is properly reversible 726 * [Ecto.Repo] Allow many_to_many associations to be preloaded via a function (before the behaviour was erratic) 727 * [Ecto.Schema] Make autogen ID loading work with custom type 728 * [Ecto.Schema] Make `updated_at` have the same value as `inserted_at` 729 * [Ecto.Schema] Ensure all fields are replaced with `on_conflict: :replace_all/:replace_all_except_primary_key` and not only the fields sent as changes 730 * [Ecto.Type] Return `:error` when casting NaN or infinite decimals 731 * [mix ecto.migrate] Properly run migrations after ECTO_EDITOR changes 732 * [mix ecto.migrations] List migrated versions even if the migration file is deleted 733 * [mix ecto.load] The task now fails on SQL errors on Postgres 734 735 ### Deprecations 736 737 Although Ecto 3.0 is a major bump version, the functionality below emits deprecation warnings to ease the migration process. The functionality below will be removed in future Ecto 3.1+ releases. 738 739 * [Ecto.Changeset] Passing a list of binaries to `cast/3` is deprecated, please pass a list of atoms instead 740 * [Ecto.Multi] `Ecto.Multi.run/3` now receives the repo in which the transaction is executing as the first argument to functions, and the changes so far as the second argument 741 * [Ecto.Query] `join/5` now expects `on: expr` as last argument instead of simply `expr`. This was done in order to properly support the `:as`, `:hints` and `:prefix` options 742 * [Ecto.Repo] The `:returning` option for `update_all` and `delete_all` has been deprecated as those statements now support `select` clauses 743 * [Ecto.Repo] Passing `:adapter` via config is deprecated in favor of passing it on `use Ecto.Repo` 744 * [Ecto.Repo] The `:loggers` configuration is deprecated in favor of "Telemetry Events" 745 746 ### Backwards incompatible changes 747 748 * [Ecto.DateTime] `Ecto.Date`, `Ecto.Time` and `Ecto.DateTime` were previously deprecated and have now been removed 749 * [Ecto.DataType] `Ecto.DataType` protocol has been removed 750 * [Ecto.Migration] Automatically inferred index names may differ in Ecto v3.0 for indexes on complex column names 751 * [Ecto.Multi] `Ecto.Multi.run/5` now receives the repo in which the transaction is executing as the first argument to functions, and the changes so far as the second argument 752 * [Ecto.Query] A `join` no longer wraps `fragment` in parentheses. In some cases, such as common table expressions, you will have to explicitly wrap the fragment in parens. 753 * [Ecto.Repo] The `on_conflict: :replace_all` option now will also send fields with default values to the database. If you prefer the old behaviour that only sends the changes in the changeset, you can set it to `on_conflict: {:replace, Map.keys(changeset.changes)}` (this change is also listed as a bug fix) 754 * [Ecto.Repo] The repository operations are no longer called from association callbacks - this behaviour was not guaranteed in previous versions but we are listing as backwards incompatible changes to help with users relying on this behaviour 755 * [Ecto.Repo] `:pool_timeout` is no longer supported in favor of a new queue system described in `DBConnection.start_link/2` under "Queue config". For most users, configuring `:timeout` is enough, as it now includes both queue and query time 756 * [Ecto.Schema] `:time`, `:naive_datetime` and `:utc_datetime` no longer keep microseconds information. If you want to keep microseconds, use `:time_usec`, `:naive_datetime_usec`, `:utc_datetime_usec` 757 * [Ecto.Schema] The `@schema_prefix` option now only affects the `from`/`join` of where the schema is used and no longer the whole query 758 * [Ecto.Schema.Metadata] The `source` key no longer returns a tuple of the schema_prefix and the table/collection name. It now returns just the table/collection string. You can now access the schema_prefix via the `prefix` key. 759 * [Mix.Ecto] `Mix.Ecto.ensure_started/2` has been removed. However, in Ecto 2.2 the `Mix.Ecto` module was not considered part of the public API and should not have been used but we are listing this for guidance. 760 761 ### Adapter changes 762 763 * [Ecto.Adapter] Split `Ecto.Adapter` into `Ecto.Adapter.Queryable` and `Ecto.Adapter.Schema` to provide more granular repository APIs 764 * [Ecto.Adapter] The `:sources` field in `query_meta` now contains three elements tuples with `{source, schema, prefix}` in order to support `from`/`join` prefixes (#2572) 765 * [Ecto.Adapter] The database types `time`, `utc_datetime` and `naive_datetime` should translate to types with seconds precision while the database types `time_usec`, `utc_datetime_usec` and `naive_datetime_usec` should have microseconds precision (#2291) 766 * [Ecto.Adapter] The `on_conflict` argument for `insert` and `insert_all` no longer receives a `{:replace_all, list(), atom()}` tuple. Instead, it receives a `{fields :: [atom()], list(), atom()}` where `fields` is a list of atoms of the fields to be replaced (#2181) 767 * [Ecto.Adapter] `insert`/`update`/`delete` now receive both `:source` and `:prefix` fields instead of a single `:source` field with both `source` and `prefix` in it (#2490) 768 * [Ecto.Adapter.Migration] A new `lock_for_migration/4` callback has been added. It is implemented by default by `Ecto.Adapters.SQL` (#2215) 769 * [Ecto.Adapter.Migration] The `execute_ddl` should now return `{:ok, []}` to make space for returning notices/hints/warnings in the future (adapters leveraging `Ecto.Adapters.SQL` do not have to perform any change) 770 * [Ecto.Query] The `from` field in `Ecto.Query` now returns a `Ecto.Query.FromExpr` with the `:source` field, unifying the behaviour in `from` and `join` expressions (#2497) 771 * [Ecto.Query] Tuple expressions are now supported in queries. For example, `where: {p.foo, p.bar} > {p.bar, p.baz}` should translate to `WHERE (p.foo, p.bar) > (p.bar, p.baz)` in SQL databases. Adapters should be changed to handle `{:{}, meta, exprs}` in the query AST (#2344) 772 * [Ecto.Query] Adapters should support the following arithmetic operators in queries `+`, `-`, `*` and `/` (#2400) 773 * [Ecto.Query] Adapters should support `filter/2` in queries, as in `select: filter(count(p.id), p.public == true)` (#2487) 774 775 ## Previous versions 776 777 * See the CHANGELOG.md [in the v2.2 branch](https://github.com/elixir-ecto/ecto/blob/v2.2/CHANGELOG.md)