CHANGELOG.md 16.7 KB
Newer Older
1 2 3 4
*   Deprecate `ColumnDumper#migration_keys`.

    *Ryuta Kamizono*

D
Daniel Colson 已提交
5 6 7 8 9 10
*   Fix `association_primary_key_type` for reflections with symbol primary key

    Fixes #27864

    *Daniel Colson*

11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
*   Virtual/generated column support for MySQL 5.7.5+ and MariaDB 5.2.0+.

    MySQL generated columns: https://dev.mysql.com/doc/refman/5.7/en/create-table-generated-columns.html
    MariaDB virtual columns: https://mariadb.com/kb/en/mariadb/virtual-computed-columns/

    Declare virtual columns with `t.virtual name, type: …, as: "expression"`.
    Pass `stored: true` to persist the generated value (false by default).

    Example:

        create_table :generated_columns do |t|
          t.string  :name
          t.virtual :upper_name,  type: :string,  as: "UPPER(name)"
          t.virtual :name_length, type: :integer, as: "LENGTH(name)", stored: true
          t.index :name_length  # May be indexed, too!
        end

    *Ryuta Kamizono*

30 31 32 33
*   Deprecate `initialize_schema_migrations_table` and `initialize_internal_metadata_table`.

    *Ryuta Kamizono*

R
Ryuta Kamizono 已提交
34 35 36 37
*   Support foreign key creation for SQLite3.

    *Ryuta Kamizono*

38
*   Place generated migrations into the path set by `config.paths["db/migrate"]`.
39 40

    *Kevin Glowacz*
41

R
Ryuta Kamizono 已提交
42
*   Raise `ActiveRecord::InvalidForeignKey` when a foreign key constraint fails on SQLite3.
A
Andrew White 已提交
43 44 45

    *Ryuta Kamizono*

46
*   Add the touch option to ActiveRecord#increment! and decrement!.
47 48 49

    *Hiroaki Izu*

50 51 52 53 54
*   Deprecate passing a class to the `class_name` because it eagerloads more classes than
    necessary and potentially creates circular dependencies.

    *Kir Shatrov*

55
*   Raise error when has_many through is defined before through association.
56

57
    Fixes #26834.
58 59 60

    *Chris Holmes*

61 62 63 64
*   Deprecate passing `name` to `indexes`.

    *Ryuta Kamizono*

65 66 67 68
*   Remove deprecated tasks: `db:test:clone`, `db:test:clone_schema`, `db:test:clone_structure`.

    *Rafel Mendonça França*

69
*   Compare deserialized values for `PostgreSQL::OID::Hstore` types when
70
    calling `ActiveRecord::Dirty#changed_in_place?`.
71 72 73 74 75

    Fixes #27502.

    *Jon Moss*

76 77
*   Raise `ArgumentError` when passing an `ActiveRecord::Base` instance to `.find`,
    `.exists?` and `.update`.
78 79 80

    *Rafael Mendonça França*

81 82 83 84 85 86
*   Respect precision option for arrays of timestamps.

    Fixes #27514.

    *Sean Griffin*

87 88 89 90
*   Optimize slow model instantiation when using STI and `store_full_sti_class = false` option.

    *Konstantin Lazarev*

91 92 93 94 95 96 97 98 99 100 101 102 103
*   Add `touch` option to counter cache modifying methods.

    Works when updating, resetting, incrementing and decrementing counters:

        # Touches `updated_at`/`updated_on`.
        Topic.increment_counter(:messages_count, 1, touch: true)
        Topic.decrement_counter(:messages_count, 1, touch: true)

        # Touches `last_discussed_at`.
        Topic.reset_counters(18, :messages, touch: :last_discussed_at)

        # Touches `updated_at` and `last_discussed_at`.
        Topic.update_counters(18, messages_count: 5, touch: %i( updated_at last_discussed_at ))
104 105 106 107 108

    Fixes #26724.

    *Jarred Trost*

109 110 111 112
*   Remove deprecated `#uniq`, `#uniq!`, and `#uniq_value`.

    *Ryuta Kamizono*

113 114 115 116
*   Remove deprecated `#insert_sql`, `#update_sql`, and `#delete_sql`.

    *Ryuta Kamizono*

117 118 119 120
*   Remove deprecated `#use_transactional_fixtures` configuration.

    *Rafael Mendonça França*

121 122 123 124
*   Remove deprecated `#raise_in_transactional_callbacks` configuration.

    *Rafael Mendonça França*

125 126 127 128
*   Remove deprecated `#load_schema_for`.

    *Rafael Mendonça França*

129
*   Remove deprecated conditions parameter from `#destroy_all` and `#delete_all`.
130 131 132

    *Rafael Mendonça França*

133 134 135 136
*   Remove deprecated support to passing arguments to `#select` when a block is provided.

    *Rafael Mendonça França*

137 138 139 140
*   Remove deprecated support to query using commas on LIMIT.

    *Rafael Mendonça França*

141 142 143 144
*   Remove deprecated support to passing a class as a value in a query.

    *Rafael Mendonça França*

145
*   Raise `ActiveRecord::IrreversibleOrderError` when using `last` with an irreversible
146 147 148 149
    order.

    *Rafael Mendonça França*

150
*   Raise when a `has_many :through` association has an ambiguous reflection name.
151 152 153

    *Rafael Mendonça França*

154
*   Raise when `ActiveRecord::Migration` is inherited from directly.
155 156 157

    *Rafael Mendonça França*

158 159 160 161 162
*   Remove deprecated `original_exception` argument in `ActiveRecord::StatementInvalid#initialize`
    and `ActiveRecord::StatementInvalid#original_exception`.

    *Rafael Mendonça França*

K
kenta-s 已提交
163
*   `#tables` and `#table_exists?` return only tables and not views.
164 165 166 167 168

    All the deprecations on those methods were removed.

    *Rafael Mendonça França*

169 170 171 172
*   Remove deprecated `name` argument from `#tables`.

    *Rafael Mendonça França*

173 174 175 176
*   Remove deprecated support to passing a column to `#quote`.

    *Rafael Mendonça França*

177
*   Set `:time` as a timezone aware type and remove deprecation when
B
Benjamin Fleischer 已提交
178
    `config.active_record.time_zone_aware_types` is not explicitly set.
179 180 181

    *Rafael Mendonça França*

182 183 184 185
*   Remove deprecated force reload argument in singular and collection association readers.

    *Rafael Mendonça França*

186 187 188 189 190
*   Remove deprecated `activerecord.errors.messages.restrict_dependent_destroy.one` and
    `activerecord.errors.messages.restrict_dependent_destroy.many` i18n scopes.

    *Rafael Mendonça França*

191 192 193 194 195 196 197
*   Allow passing extra flags to `db:structure:load` and `db:structure:dump`

    Introduces `ActiveRecord::Tasks::DatabaseTasks.structure_(load|dump)_flags` to customize the
    eventual commands run against the database, e.g. mysqldump/pg_dump.

    *Kir Shatrov*

R
Richard Monette 已提交
198 199
*   Notifications see frozen SQL string.

200
    Fixes #23774.
R
Richard Monette 已提交
201 202 203

    *Richard Monette*

204
*   RuntimeErrors are no longer translated to `ActiveRecord::StatementInvalid`.
R
Richard Monette 已提交
205 206 207

    *Richard Monette*

208 209 210 211
*   Change the schema cache format to use YAML instead of Marshal.

    *Kir Shatrov*

212 213 214 215 216 217 218
*   Support index length and order options using both string and symbol
    column names.

    Fixes #27243.

    *Ryuta Kamizono*

219 220 221 222
*   Raise `ActiveRecord::RangeError` when values that executed are out of range.

    *Ryuta Kamizono*

223 224 225 226 227 228
*   Raise `ActiveRecord::NotNullViolation` when a record cannot be inserted
    or updated because it would violate a not null constraint.

    *Ryuta Kamizono*

*   Emulate db trigger behaviour for after_commit :destroy, :update.
229 230 231 232 233 234 235

    Race conditions can occur when an ActiveRecord is destroyed
    twice or destroyed and updated. The callbacks should only be
    triggered once, similar to a SQL database trigger.

    *Stefan Budeanu*

236
*   Moved `DecimalWithoutScale`, `Text`, and `UnsignedInteger` from Active Model to Active Record.
237 238 239

    *Iain Beeston*

240 241 242 243 244
*   Fix `write_attribute` method to check whether an attribute is aliased or not, and
    use the aliased attribute name if needed.

    *Prathamesh Sonpatki*

245 246 247 248 249 250 251
*   Fix `read_attribute` method to check whether an attribute is aliased or not, and
    use the aliased attribute name if needed.

    Fixes #26417.

    *Prathamesh Sonpatki*

252
*   PostgreSQL & MySQL: Use big integer as primary key type for new tables.
253 254 255

    *Jon McCartie*, *Pavel Pravosud*

256 257 258 259 260 261
*   Change the type argument of `ActiveRecord::Base#attribute` to be optional.
    The default is now `ActiveRecord::Type::Value.new`, which provides no type
    casting behavior.

    *Sean Griffin*

J
Jon Moss 已提交
262
*   Don't treat unsigned integers with zerofill as signed.
263 264 265 266 267

    Fixes #27125.

    *Ryuta Kamizono*

268 269 270 271
*   Fix the uniqueness validation scope with a polymorphic association.

    *Sergey Alekseev*

272
*   Raise `ActiveRecord::RecordNotFound` from collection `*_ids` setters
273 274
    for unknown IDs with a better error message.

275 276 277 278
    Changes the collection `*_ids` setters to cast provided IDs the data
    type of the primary key set in the association, not the model
    primary key.

279 280
    *Dominic Cleal*

281 282 283 284 285
*   For PostgreSQL >= 9.4 use `pgcrypto`'s `gen_random_uuid()` instead of
    `uuid-ossp`'s UUID generation function.

    *Yuji Yaginuma*, *Yaw Boakye*

286 287 288 289
*   Introduce `Model#reload_<association>` to bring back the behavior
    of `Article.category(true)` where `category` is a singular
    association.

290 291
    The force reloading of the association reader was deprecated
    in #20888. Unfortunately the suggested alternative of
292 293 294 295 296 297 298 299
    `article.reload.category` does not expose the same behavior.

    This patch adds a reader method with the prefix `reload_` for
    singular associations. This method has the same semantics as
    passing true to the association reader used to have.

    *Yves Senn*

Y
Yves Senn 已提交
300 301 302 303 304
*   Make sure eager loading `ActiveRecord::Associations` also loads
    constants defined in `ActiveRecord::Associations::Preloader`.

    *Yves Senn*

J
Jon Moss 已提交
305 306 307 308 309 310 311
*   Allow `ActionController::Parameters`-like objects to be passed as
    values for Postgres HStore columns.

    Fixes #26904.

    *Jon Moss*

312
*   Added `stat` method to `ActiveRecord::ConnectionAdapters::ConnectionPool`.
313 314 315 316 317 318 319 320

    Example:

        ActiveRecord::Base.connection_pool.stat # =>
        { size: 15, connections: 1, busy: 1, dead: 0, idle: 0, waiting: 0, checkout_timeout: 5 }

    *Pavel Evstigneev*

321 322
*   Avoid `unscope(:order)` when `limit_value` is presented for `count`
    and `exists?`.
323 324

    If `limit_value` is presented, records fetching order is very important
V
Vipul A M 已提交
325
    for performance. We should not unscope the order in the case.
326 327 328

    *Ryuta Kamizono*

V
Vipul A M 已提交
329
*   Fix an Active Record `DateTime` field `NoMethodError` caused by incomplete
330 331 332
    datetime.

    Fixes #24195.
S
Sen-Zhang 已提交
333 334 335

    *Sen Zhang*

V
Vipul A M 已提交
336
*   Allow `slice` to take an array of methods(without the need for splatting).
337 338 339

    *Cohen Carlisle*

340 341 342 343 344 345 346
*   Improved partial writes with HABTM and has many through associations
    to fire database query only if relation has been changed.

    Fixes #19663.

    *Mehmet Emin İNAÇ*

347 348 349 350 351
*   Deprecate passing arguments and block at the same time to
    `ActiveRecord::QueryMethods#select`.

    *Prathamesh Sonpatki*

V
Vipul A M 已提交
352 353
*   Optimistic locking: Added ability to update `locking_column` value.
    Ignore optimistic locking if trying to update with new `locking_column` value.
354 355 356

    *bogdanvlviv*

V
Vipul A M 已提交
357
*   Fixed: Optimistic locking does not work well with `null` in the database.
358

359
    Fixes #26024.
360 361 362

    *bogdanvlviv*

363 364 365 366 367
*   Fixed support for case insensitive comparisons of `text` columns in
    PostgreSQL.

    *Edho Arief*

368
*   Serialize JSON attribute value `nil` as SQL `NULL`, not JSON `null`.
369 370 371

    *Trung Duc Tran*

372 373 374 375 376 377 378
*   Return `true` from `update_attribute` when the value of the attribute
    to be updated is unchanged.

    Fixes #26593.

    *Prathamesh Sonpatki*

379 380 381 382 383 384 385 386 387 388 389 390 391 392 393
*   Always store errors details information with symbols.

    When the association is autosaved we were storing the details with
    string keys. This was creating inconsistency with other details that are
    added using the `Errors#add` method. It was also inconsistent with the
    `Errors#messages` storage.

    To fix this inconsistency we are always storing with symbols. This will
    cause a small breaking change because in those cases the details could
    be accessed as strings keys but now it can not.

    Fix #26499.

    *Rafael Mendonça França*, *Marcus Vieira*

394 395 396 397 398 399 400
*   Calling `touch` on a model using optimistic locking will now leave the model
    in a non-dirty state with no attribute changes.

    Fixes #26496.

    *Jakob Skjerning*

401 402 403 404 405
*   Using a mysql2 connection after it fails to reconnect will now have an error message
    saying the connection is closed rather than an undefined method error message.

    *Dylan Thacker-Smith*

406 407 408 409 410 411 412
*   PostgreSQL array columns will now respect the encoding of strings contained
    in the array.

    Fixes #26326.

    *Sean Griffin*

413 414 415 416 417 418 419
*   Inverse association instances will now be set before `after_find` or
    `after_initialize` callbacks are run.

    Fixes #26320.

    *Sean Griffin*

420 421 422 423 424
*   Remove unnecessarily association load when a `belongs_to` association has already been
    loaded then the foreign key is changed directly and the record saved.

    *James Coleman*

425
*   Remove standardized column types/arguments spaces in schema dump.
426 427 428

    *Tim Petricola*

429 430 431 432 433 434 435
*   Avoid loading records from database when they are already loaded using
    the `pluck` method on a collection.

    Fixes #25921.

    *Ryuta Kamizono*

436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467
*   Remove text default treated as an empty string in non-strict mode for
    consistency with other types.

    Strict mode controls how MySQL handles invalid or missing values in
    data-change statements such as INSERT or UPDATE. If strict mode is not
    in effect, MySQL inserts adjusted values for invalid or missing values
    and produces warnings.

        def test_mysql_not_null_defaults_non_strict
          using_strict(false) do
            with_mysql_not_null_table do |klass|
              record = klass.new
              assert_nil record.non_null_integer
              assert_nil record.non_null_string
              assert_nil record.non_null_text
              assert_nil record.non_null_blob

              record.save!
              record.reload

              assert_equal 0,  record.non_null_integer
              assert_equal "", record.non_null_string
              assert_equal "", record.non_null_text
              assert_equal "", record.non_null_blob
            end
          end
        end

    https://dev.mysql.com/doc/refman/5.7/en/sql-mode.html#sql-mode-strict

    *Ryuta Kamizono*

R
Ryuta Kamizono 已提交
468
*   SQLite3 migrations to add a column to an existing table can now be
469 470 471
    successfully rolled back when the column was given and invalid column
    type.

472
    Fixes #26087.
473 474 475

    *Travis O'Neill*

476 477 478 479
*   Deprecate `sanitize_conditions`. Use `sanitize_sql` instead.

    *Ryuta Kamizono*

480 481 482 483 484
*   Doing count on relations that contain LEFT OUTER JOIN Arel node no longer
    force a DISTINCT. This solves issues when using count after a left_joins.

    *Maxime Handfield Lapointe*

485 486 487 488 489
*   RecordNotFound raised by association.find exposes `id`, `primary_key` and
    `model` methods to be consistent with RecordNotFound raised by Record.find.

    *Michel Pigassou*

490 491 492 493 494 495 496
*   Hashes can once again be passed to setters of `composed_of`, if all of the
    mapping methods are methods implemented on `Hash`.

    Fixes #25978.

    *Sean Griffin*

497 498 499 500
*   Fix the SELECT statement in `#table_comment` for MySQL.

    *Takeshi Akima*

501
*   Virtual attributes will no longer raise when read on models loaded from the
502
    database.
503 504 505

    *Sean Griffin*

506 507 508 509
*   Support calling the method `merge` in `scope`'s lambda.

    *Yasuhiro Sugino*

510 511 512 513
*   Fixes multi-parameter attributes conversion with invalid params.

    *Hiroyuki Ishii*

514
*   Add newline between each migration in `structure.sql`.
515 516

    Keeps schema migration inserts as a single commit, but allows for easier
517 518 519
    git diffing.

    Fixes #25504.
520 521 522

    *Grey Baker*, *Norberto Lopes*

523 524 525 526 527 528 529 530 531 532 533 534 535 536 537
*   The flag `error_on_ignored_order_or_limit` has been deprecated in favor of
    the current `error_on_ignored_order`.

    *Xavier Noria*

*   Batch processing methods support `limit`:

        Post.limit(10_000).find_each do |post|
          # ...
        end

    It also works in `find_in_batches` and `in_batches`.

    *Xavier Noria*

538
*   Using `group` with an attribute that has a custom type will properly cast
539 540
    the hash keys after calling a calculation method like `count`.

V
Vipul A M 已提交
541
    Fixes #25595.
542 543 544

    *Sean Griffin*

545
*   Fix the generated `#to_param` method to use `omission: ''` so that
546 547 548 549 550 551
    the resulting output is actually up to 20 characters, not
    effectively 17 to leave room for the default "...".
    Also call `#parameterize` before `#truncate` and make the
    `separator: /-/` to maximize the information included in the
    output.

552
    Fixes #23635.
553 554 555

    *Rob Biedenharn*

556 557 558 559 560 561 562
*   Ensure concurrent invocations of the connection reaper cannot allocate the
    same connection to two threads.

    Fixes #25585.

    *Matthew Draper*

563 564 565 566 567 568
*   Inspecting an object with an associated array of over 10 elements no longer
    truncates the array, preventing `inspect` from looping infinitely in some
    cases.

    *Kevin McPhillips*

569
*   Removed the unused methods `ActiveRecord::Base.connection_id` and
570
    `ActiveRecord::Base.connection_id=`.
571 572 573

    *Sean Griffin*

574
*   Ensure hashes can be assigned to attributes created using `composed_of`.
575

576 577 578 579
    Fixes #25210.

    *Sean Griffin*

580 581
*   Fix logging edge case where if an attribute was of the binary type and
    was provided as a Hash.
R
Rafael Mendonça França 已提交
582

583 584
    *Jon Moss*

585 586 587 588
*   Handle JSON deserialization correctly if the column default from database
    adapter returns `''` instead of `nil`.

    *Johannes Opper*
589

590
*   Introduce `ActiveRecord::TransactionSerializationError` for catching
591 592 593 594
    transaction serialization failures or deadlocks.

    *Erol Fornoles*

V
Vipul A M 已提交
595
*   PostgreSQL: Fix `db:structure:load` silent failure on SQL error.
596

597 598
    The command line flag `-v ON_ERROR_STOP=1` should be used
    when invoking `psql` to make sure errors are not suppressed.
599 600 601 602 603 604 605 606 607 608

    Example:

        psql -v ON_ERROR_STOP=1 -q -f awesome-file.sql my-app-db

    Fixes #23818.

    *Ralin Chimev*


609
Please check [5-0-stable](https://github.com/rails/rails/blob/5-0-stable/activerecord/CHANGELOG.md) for previous changes.