activerecord 7.2.3 → 8.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (124) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +391 -958
  3. data/README.rdoc +1 -1
  4. data/lib/active_record/association_relation.rb +1 -0
  5. data/lib/active_record/associations/association.rb +34 -10
  6. data/lib/active_record/associations/builder/association.rb +7 -6
  7. data/lib/active_record/associations/collection_association.rb +1 -1
  8. data/lib/active_record/associations/disable_joins_association_scope.rb +1 -1
  9. data/lib/active_record/associations/has_many_through_association.rb +3 -2
  10. data/lib/active_record/associations/preloader/association.rb +2 -2
  11. data/lib/active_record/associations/singular_association.rb +8 -3
  12. data/lib/active_record/associations.rb +34 -4
  13. data/lib/active_record/asynchronous_queries_tracker.rb +28 -24
  14. data/lib/active_record/attribute_methods/primary_key.rb +4 -8
  15. data/lib/active_record/attribute_methods/query.rb +34 -0
  16. data/lib/active_record/attribute_methods/time_zone_conversion.rb +2 -12
  17. data/lib/active_record/autosave_association.rb +69 -27
  18. data/lib/active_record/connection_adapters/abstract/connection_handler.rb +34 -25
  19. data/lib/active_record/connection_adapters/abstract/connection_pool/queue.rb +0 -1
  20. data/lib/active_record/connection_adapters/abstract/connection_pool/reaper.rb +0 -1
  21. data/lib/active_record/connection_adapters/abstract/connection_pool.rb +6 -15
  22. data/lib/active_record/connection_adapters/abstract/database_statements.rb +90 -43
  23. data/lib/active_record/connection_adapters/abstract/query_cache.rb +8 -2
  24. data/lib/active_record/connection_adapters/abstract/quoting.rb +1 -1
  25. data/lib/active_record/connection_adapters/abstract/schema_creation.rb +4 -5
  26. data/lib/active_record/connection_adapters/abstract/schema_definitions.rb +7 -2
  27. data/lib/active_record/connection_adapters/abstract/schema_statements.rb +34 -7
  28. data/lib/active_record/connection_adapters/abstract/transaction.rb +15 -5
  29. data/lib/active_record/connection_adapters/abstract_adapter.rb +31 -43
  30. data/lib/active_record/connection_adapters/abstract_mysql_adapter.rb +21 -40
  31. data/lib/active_record/connection_adapters/mysql/quoting.rb +0 -8
  32. data/lib/active_record/connection_adapters/mysql/schema_definitions.rb +2 -8
  33. data/lib/active_record/connection_adapters/mysql/schema_statements.rb +50 -45
  34. data/lib/active_record/connection_adapters/mysql2/database_statements.rb +84 -94
  35. data/lib/active_record/connection_adapters/mysql2_adapter.rb +1 -8
  36. data/lib/active_record/connection_adapters/pool_config.rb +7 -7
  37. data/lib/active_record/connection_adapters/postgresql/database_statements.rb +72 -43
  38. data/lib/active_record/connection_adapters/postgresql/oid/array.rb +1 -1
  39. data/lib/active_record/connection_adapters/postgresql/oid/point.rb +10 -0
  40. data/lib/active_record/connection_adapters/postgresql/referential_integrity.rb +2 -4
  41. data/lib/active_record/connection_adapters/postgresql/schema_creation.rb +1 -11
  42. data/lib/active_record/connection_adapters/postgresql/schema_definitions.rb +6 -12
  43. data/lib/active_record/connection_adapters/postgresql/schema_dumper.rb +2 -1
  44. data/lib/active_record/connection_adapters/postgresql/schema_statements.rb +59 -16
  45. data/lib/active_record/connection_adapters/postgresql_adapter.rb +46 -96
  46. data/lib/active_record/connection_adapters/schema_cache.rb +1 -3
  47. data/lib/active_record/connection_adapters/sqlite3/database_statements.rb +80 -100
  48. data/lib/active_record/connection_adapters/sqlite3/schema_creation.rb +0 -6
  49. data/lib/active_record/connection_adapters/sqlite3/schema_dumper.rb +13 -0
  50. data/lib/active_record/connection_adapters/sqlite3/schema_statements.rb +9 -1
  51. data/lib/active_record/connection_adapters/sqlite3_adapter.rb +53 -12
  52. data/lib/active_record/connection_adapters/statement_pool.rb +4 -2
  53. data/lib/active_record/connection_adapters/trilogy/database_statements.rb +37 -67
  54. data/lib/active_record/connection_adapters/trilogy_adapter.rb +0 -17
  55. data/lib/active_record/connection_adapters.rb +0 -56
  56. data/lib/active_record/connection_handling.rb +23 -1
  57. data/lib/active_record/core.rb +29 -14
  58. data/lib/active_record/database_configurations/database_config.rb +4 -0
  59. data/lib/active_record/database_configurations/hash_config.rb +16 -2
  60. data/lib/active_record/encryption/config.rb +3 -1
  61. data/lib/active_record/encryption/encryptable_record.rb +4 -4
  62. data/lib/active_record/encryption/encrypted_attribute_type.rb +10 -1
  63. data/lib/active_record/encryption/encryptor.rb +16 -8
  64. data/lib/active_record/encryption/extended_deterministic_queries.rb +4 -2
  65. data/lib/active_record/encryption/scheme.rb +8 -1
  66. data/lib/active_record/enum.rb +9 -22
  67. data/lib/active_record/errors.rb +13 -5
  68. data/lib/active_record/fixtures.rb +0 -2
  69. data/lib/active_record/future_result.rb +13 -9
  70. data/lib/active_record/gem_version.rb +3 -3
  71. data/lib/active_record/insert_all.rb +1 -1
  72. data/lib/active_record/locking/optimistic.rb +1 -1
  73. data/lib/active_record/log_subscriber.rb +5 -11
  74. data/lib/active_record/migration/command_recorder.rb +31 -11
  75. data/lib/active_record/migration/compatibility.rb +5 -2
  76. data/lib/active_record/migration.rb +38 -42
  77. data/lib/active_record/model_schema.rb +3 -4
  78. data/lib/active_record/nested_attributes.rb +4 -6
  79. data/lib/active_record/persistence.rb +128 -130
  80. data/lib/active_record/query_logs.rb +102 -50
  81. data/lib/active_record/query_logs_formatter.rb +17 -28
  82. data/lib/active_record/querying.rb +8 -8
  83. data/lib/active_record/railtie.rb +2 -26
  84. data/lib/active_record/railties/databases.rake +11 -35
  85. data/lib/active_record/reflection.rb +18 -21
  86. data/lib/active_record/relation/batches/batch_enumerator.rb +4 -3
  87. data/lib/active_record/relation/batches.rb +132 -72
  88. data/lib/active_record/relation/calculations.rb +40 -39
  89. data/lib/active_record/relation/delegation.rb +25 -14
  90. data/lib/active_record/relation/finder_methods.rb +18 -18
  91. data/lib/active_record/relation/merger.rb +8 -8
  92. data/lib/active_record/relation/predicate_builder/polymorphic_array_value.rb +1 -1
  93. data/lib/active_record/relation/predicate_builder/relation_handler.rb +4 -3
  94. data/lib/active_record/relation/predicate_builder.rb +13 -0
  95. data/lib/active_record/relation/query_methods.rb +105 -61
  96. data/lib/active_record/relation/spawn_methods.rb +7 -7
  97. data/lib/active_record/relation.rb +79 -61
  98. data/lib/active_record/result.rb +66 -4
  99. data/lib/active_record/sanitization.rb +7 -6
  100. data/lib/active_record/schema_dumper.rb +5 -0
  101. data/lib/active_record/schema_migration.rb +2 -1
  102. data/lib/active_record/scoping/named.rb +5 -2
  103. data/lib/active_record/statement_cache.rb +14 -14
  104. data/lib/active_record/store.rb +7 -3
  105. data/lib/active_record/table_metadata.rb +1 -3
  106. data/lib/active_record/tasks/database_tasks.rb +69 -60
  107. data/lib/active_record/tasks/mysql_database_tasks.rb +0 -2
  108. data/lib/active_record/tasks/postgresql_database_tasks.rb +2 -1
  109. data/lib/active_record/tasks/sqlite_database_tasks.rb +2 -2
  110. data/lib/active_record/test_databases.rb +1 -1
  111. data/lib/active_record/test_fixtures.rb +12 -0
  112. data/lib/active_record/token_for.rb +1 -1
  113. data/lib/active_record/transactions.rb +5 -6
  114. data/lib/active_record/validations/uniqueness.rb +8 -8
  115. data/lib/active_record.rb +21 -48
  116. data/lib/arel/collectors/bind.rb +2 -2
  117. data/lib/arel/collectors/sql_string.rb +1 -1
  118. data/lib/arel/collectors/substitute_binds.rb +2 -2
  119. data/lib/arel/nodes/binary.rb +1 -1
  120. data/lib/arel/nodes/node.rb +1 -1
  121. data/lib/arel/nodes/sql_literal.rb +1 -1
  122. data/lib/arel/table.rb +3 -7
  123. metadata +9 -10
  124. data/lib/active_record/relation/record_fetch_warning.rb +0 -52
data/CHANGELOG.md CHANGED
@@ -1,4 +1,4 @@
1
- ## Rails 7.2.3 (October 28, 2025) ##
1
+ ## Rails 8.0.4 (October 28, 2025) ##
2
2
 
3
3
  * Fix SQLite3 data loss during table alterations with CASCADE foreign keys.
4
4
 
@@ -22,6 +22,10 @@
22
22
 
23
23
  *Ruy Rocha*
24
24
 
25
+ * Add support for bound SQL literals in CTEs.
26
+
27
+ *Nicolas Bachschmidt*
28
+
25
29
  * Fix `belongs_to` associations not to clear the entire composite primary key.
26
30
 
27
31
  When clearing a `belongs_to` association that references a model with composite primary key,
@@ -33,23 +37,10 @@
33
37
 
34
38
  *Ian Terrell*, *axlekb AB*
35
39
 
36
- * Prevent persisting invalid record.
37
-
38
- *Edouard Chin*
39
-
40
- * Fix count with group by qualified name on loaded relation.
41
-
42
- *Ryuta Kamizono*
43
-
44
- * Fix `sum` with qualified name on loaded relation.
45
-
46
- *Chris Gunther*
47
-
48
- * Fix prepared statements on mysql2 adapter.
49
40
 
50
- *Jean Boussier*
41
+ ## Rails 8.0.3 (September 22, 2025) ##
51
42
 
52
- * Fix query cache for pinned connections in multi threaded transactional tests.
43
+ * Fix query cache for pinned connections in multi threaded transactional tests
53
44
 
54
45
  When a pinned connection is used across separate threads, they now use a separate cache store
55
46
  for each thread.
@@ -62,21 +53,42 @@
62
53
 
63
54
  *Rob Lewis*
64
55
 
65
- * Fix false positive change detection involving STI and polymorhic has one relationships.
56
+ * Fix false positive change detection involving STI and polymorphic has one relationships.
66
57
 
67
58
  Polymorphic `has_one` relationships would always be considered changed when defined in a STI child
68
59
  class, causing nedless extra autosaves.
69
60
 
70
61
  *David Fritsch*
71
62
 
72
- * Fix stale associaton detection for polymophic `belong_to`.
63
+ * Skip calling `PG::Connection#cancel` in `cancel_any_running_query`
64
+ when using libpq >= 18 with pg < 1.6.0, due to incompatibility.
65
+ Rollback still runs, but may take longer.
66
+
67
+ *Yasuo Honda*, *Lars Kanis*
68
+
69
+ * Fix stale association detection for polymorphic `belongs_to`.
73
70
 
74
71
  *Florent Beaurain*, *Thomas Crambert*
75
72
 
76
- * Fix removal of PostgreSQL version comments in `structure.sql` for latest PostgreSQL versions which include `\restrict`.
73
+ * Fix removal of PostgreSQL version comments in `structure.sql` for latest PostgreSQL versions which include `\restrict`
77
74
 
78
75
  *Brendan Weibrecht*
79
76
 
77
+ * Allow setting `schema_format` in database configuration.
78
+
79
+ ```
80
+ primary:
81
+ schema_format: ruby
82
+ ```
83
+
84
+ Useful in multi-database setups to have different formats per-database.
85
+
86
+ *T S Vallender*
87
+
88
+ * Use ntuples to populate row_count instead of count for Postgres
89
+
90
+ *Jonathan Calvert*
91
+
80
92
  * Fix `#merge` with `#or` or `#and` and a mixture of attributes and SQL strings resulting in an incorrect query.
81
93
 
82
94
  ```ruby
@@ -119,6 +131,18 @@
119
131
 
120
132
  *fatkodima*
121
133
 
134
+ * Fix migration log message for down operations.
135
+
136
+ *Bernardo Barreto*
137
+
138
+ * Prepend `extra_flags` in postgres' `structure_load`
139
+
140
+ When specifying `structure_load_flags` with a postgres adapter, the flags
141
+ were appended to the default flags, instead of prepended.
142
+ This caused issues with flags not being taken into account by postgres.
143
+
144
+ *Alice Loeser*
145
+
122
146
  * Fix `annotate` comments to propagate to `update_all`/`delete_all`.
123
147
 
124
148
  *fatkodima*
@@ -128,10 +152,6 @@
128
152
 
129
153
  *Hartley McGuire*
130
154
 
131
- * Fix inline has_and_belongs_to_many fixtures for tables with composite primary keys.
132
-
133
- *fatkodima*
134
-
135
155
  * `create_or_find_by` will now correctly rollback a transaction.
136
156
 
137
157
  When using `create_or_find_by`, raising a ActiveRecord::Rollback error
@@ -150,6 +170,42 @@
150
170
 
151
171
  *Jean Boussier*
152
172
 
173
+ * Fix stale state for composite foreign keys in belongs_to associations.
174
+
175
+ *Varun Sharma*
176
+
177
+
178
+ ## Rails 8.0.2.1 (August 13, 2025) ##
179
+
180
+ * Call inspect on ids in RecordNotFound error
181
+
182
+ [CVE-2025-55193]
183
+
184
+ *Gannon McGibbon*, *John Hawthorn*
185
+
186
+
187
+ ## Rails 8.0.2 (March 12, 2025) ##
188
+
189
+ * Fix inverting `rename_enum_value` when `:from`/`:to` are provided.
190
+
191
+ *fatkodima*
192
+
193
+ * Prevent persisting invalid record.
194
+
195
+ *Edouard Chin*
196
+
197
+ * Fix inverting `drop_table` without options.
198
+
199
+ *fatkodima*
200
+
201
+ * Fix count with group by qualified name on loaded relation.
202
+
203
+ *Ryuta Kamizono*
204
+
205
+ * Fix `sum` with qualified name on loaded relation.
206
+
207
+ *Chris Gunther*
208
+
153
209
  * The SQLite3 adapter quotes non-finite Numeric values like "Infinity" and "NaN".
154
210
 
155
211
  *Mike Dalessio*
@@ -182,7 +238,25 @@
182
238
 
183
239
  *zzak*
184
240
 
185
- * Prevent persisting invalid record.
241
+ * PoolConfig no longer keeps a reference to the connection class.
242
+
243
+ Keeping a reference to the class caused subtle issues when combined with reloading in
244
+ development. Fixes #54343.
245
+
246
+ *Mike Dalessio*
247
+
248
+ * Fix SQL notifications sometimes not sent when using async queries.
249
+
250
+ ```ruby
251
+ Post.async_count
252
+ ActiveSupport::Notifications.subscribed(->(*) { "Will never reach here" }) do
253
+ Post.count
254
+ end
255
+ ```
256
+
257
+ In rare circumstances and under the right race condition, Active Support notifications
258
+ would no longer be dispatched after using an asynchronous query.
259
+ This is now fixed.
186
260
 
187
261
  *Edouard Chin*
188
262
 
@@ -220,14 +294,6 @@
220
294
 
221
295
  *Sjoerd Lagarde*
222
296
 
223
- * Fix count with group by qualified name on loaded relation.
224
-
225
- *Ryuta Kamizono*
226
-
227
- * Fix sum with qualified name on loaded relation.
228
-
229
- *Chris Gunther*
230
-
231
297
  * Fix autosave associations to no longer validated unmodified associated records.
232
298
 
233
299
  Active Record was incorrectly performing validation on associated record that
@@ -249,9 +315,12 @@
249
315
 
250
316
  *Matthew Draper*
251
317
 
252
- * Fix prepared statements on mysql2 adapter.
253
318
 
254
- *Jean Boussier*
319
+ ## Rails 8.0.1 (December 13, 2024) ##
320
+
321
+ * Fix removing foreign keys with :restrict action for MySQL.
322
+
323
+ *fatkodima*
255
324
 
256
325
  * Fix a race condition in `ActiveRecord::Base#method_missing` when lazily defining attributes.
257
326
 
@@ -264,8 +333,7 @@
264
333
 
265
334
  *Bastian Bartmann*
266
335
 
267
- * Fix `add_unique_constraint`/`add_check_constraint`/`/`add_foreign_key` to be revertible when
268
- given invalid options.
336
+ * Fix `add_unique_constraint`/`add_check_constraint`/`add_foreign_key` to be revertible when given invalid options.
269
337
 
270
338
  *fatkodima*
271
339
 
@@ -273,7 +341,11 @@
273
341
 
274
342
  *fatkodima*
275
343
 
276
- * NOT VALID constraints should not dump in `create_table`.
344
+ * Fix `insert_all` to not update existing records.
345
+
346
+ *fatkodima*
347
+
348
+ * `NOT VALID` constraints should not dump in `create_table`.
277
349
 
278
350
  *Ryuta Kamizono*
279
351
 
@@ -281,6 +353,16 @@
281
353
 
282
354
  *fatkodima*
283
355
 
356
+ * Properly reset composite primary key configuration when setting a primary key.
357
+
358
+ *fatkodima*
359
+
360
+ * Fix Mysql2Adapter support for prepared statements
361
+
362
+ Using prepared statements with MySQL could result in a `NoMethodError` exception.
363
+
364
+ *Jean Boussier*, *Leo Arnold*, *zzak*
365
+
284
366
  * Fix parsing of SQLite foreign key names when they contain non-ASCII characters
285
367
 
286
368
  *Zacharias Knudsen*
@@ -293,63 +375,101 @@
293
375
 
294
376
  *Joshua Young*
295
377
 
296
- * Restore back the ability to pass only database name for `DATABASE_URL`.
378
+ * Fix `sum` when performing a grouped calculation.
379
+
380
+ `User.group(:friendly).sum` no longer worked. This is fixed.
381
+
382
+ *Edouard Chin*
383
+
384
+ * Restore back the ability to pass only database name to `DATABASE_URL`.
297
385
 
298
386
  *fatkodima*
299
387
 
300
- * Fix `order` with using association name as an alias.
301
388
 
302
- *Ryuta Kamizono*
389
+ ## Rails 8.0.0.1 (December 10, 2024) ##
390
+
391
+ * No changes.
392
+
393
+
394
+ ## Rails 8.0.0 (November 07, 2024) ##
395
+
396
+ * Fix support for `query_cache: false` in `database.yml`.
397
+
398
+ `query_cache: false` would no longer entirely disable the Active Record query cache.
399
+
400
+ *zzak*
303
401
 
304
- * Improve invalid argument error for with.
402
+
403
+ ## Rails 8.0.0.rc2 (October 30, 2024) ##
404
+
405
+ * NULLS NOT DISTINCT works with UNIQUE CONSTRAINT as well as UNIQUE INDEX.
305
406
 
306
407
  *Ryuta Kamizono*
307
408
 
308
- * Deduplicate `with` CTE expressions.
409
+ * The `db:prepare` task no longer loads seeds when a non-primary database is created.
309
410
 
310
- *fatkodima*
411
+ Previously, the `db:prepare` task would load seeds whenever a new database
412
+ is created, leading to potential loss of data if a database is added to an
413
+ existing environment.
311
414
 
415
+ Introduces a new database config property `seeds` to control whether seeds
416
+ are loaded during `db:prepare` which defaults to `true` for primary database
417
+ configs and `false` otherwise.
312
418
 
313
- ## Rails 7.2.2.2 (August 13, 2025) ##
419
+ Fixes #53348.
314
420
 
315
- * Call inspect on ids in RecordNotFound error
421
+ *Mike Dalessio*
316
422
 
317
- [CVE-2025-55193]
423
+ * `PG::UnableToSend: no connection to the server` is now retryable as a connection-related exception
318
424
 
319
- *Gannon McGibbon*, *John Hawthorn*
425
+ *Kazuma Watanabe*
320
426
 
427
+ * Fix strict loading propagation even if statement cache is not used.
321
428
 
322
- ## Rails 7.2.2.1 (December 10, 2024) ##
429
+ *Ryuta Kamizono*
323
430
 
324
- * No changes.
431
+ * Allow `rename_enum` accepts two from/to name arguments as `rename_table` does so.
325
432
 
433
+ *Ryuta Kamizono*
326
434
 
327
- ## Rails 7.2.2 (October 30, 2024) ##
328
435
 
329
- * Fix support for `query_cache: false` in `database.yml`.
436
+ ## Rails 8.0.0.rc1 (October 19, 2024) ##
330
437
 
331
- `query_cache: false` would no longer entirely disable the Active Record query cache.
438
+ * Remove deprecated support to setting `ENV["SCHEMA_CACHE"]`.
332
439
 
333
- *zzak*
440
+ *Rafael Mendonça França*
334
441
 
335
- * Set `.attributes_for_inspect` to `:all` by default.
442
+ * Remove deprecated support to passing a database name to `cache_dump_filename`.
336
443
 
337
- For new applications it is set to `[:id]` in config/environment/production.rb.
444
+ *Rafael Mendonça França*
338
445
 
339
- In the console all the attributes are always shown.
446
+ * Remove deprecated `ActiveRecord::ConnectionAdapters::ConnectionPool#connection`.
340
447
 
341
- *Andrew Novoselac*
448
+ *Rafael Mendonça França*
342
449
 
343
- * `PG::UnableToSend: no connection to the server` is now retryable as a connection-related exception
450
+ * Remove deprecated `config.active_record.sqlite3_deprecated_warning`.
344
451
 
345
- *Kazuma Watanabe*
452
+ *Rafael Mendonça França*
453
+
454
+ * Remove deprecated `config.active_record.warn_on_records_fetched_greater_than`.
346
455
 
347
- * Fix marshalling of unsaved associated records in 7.1 format.
456
+ *Rafael Mendonça França*
348
457
 
349
- The 7.1 format would only marshal associated records if the association was loaded.
350
- But associations that would only contain unsaved records would be skipped.
458
+ * Remove deprecated support for defining `enum` with keyword arguments.
351
459
 
352
- *Jean Boussier*
460
+ *Rafael Mendonça França*
461
+
462
+ * Remove deprecated support to finding database adapters that aren't registered to Active Record.
463
+
464
+ *Rafael Mendonça França*
465
+
466
+ * Remove deprecated `config.active_record.allow_deprecated_singular_associations_name`.
467
+
468
+ *Rafael Mendonça França*
469
+
470
+ * Remove deprecated `config.active_record.commit_transaction_on_non_local_return`.
471
+
472
+ *Rafael Mendonça França*
353
473
 
354
474
  * Fix incorrect SQL query when passing an empty hash to `ActiveRecord::Base.insert`.
355
475
 
@@ -364,70 +484,42 @@
364
484
 
365
485
  *Joshua Young*
366
486
 
367
- * Fix `dependent: :destroy` for bi-directional has one through association.
368
-
369
- Fixes #50948.
487
+ * Allow `ActiveRecord::Base#pluck` to accept hash arguments with symbol and string values.
370
488
 
371
489
  ```ruby
372
- class Left < ActiveRecord::Base
373
- has_one :middle, dependent: :destroy
374
- has_one :right, through: :middle
375
- end
376
-
377
- class Middle < ActiveRecord::Base
378
- belongs_to :left, dependent: :destroy
379
- belongs_to :right, dependent: :destroy
380
- end
381
-
382
- class Right < ActiveRecord::Base
383
- has_one :middle, dependent: :destroy
384
- has_one :left, through: :middle
385
- end
490
+ Post.joins(:comments).pluck(:id, comments: :id)
491
+ Post.joins(:comments).pluck("id", "comments" => "id")
386
492
  ```
387
- In the above example `left.destroy` wouldn't destroy its associated `Right`
388
- record.
389
493
 
390
- *Andy Stewart*
494
+ *Joshua Young*
495
+
496
+ * Make Float distinguish between `float4` and `float8` in PostgreSQL.
391
497
 
392
- * Properly handle lazily pinned connection pools.
498
+ Fixes #52742
393
499
 
394
- Fixes #53147.
500
+ *Ryota Kitazawa*, *Takayuki Nagatomi*
395
501
 
396
- When using transactional fixtures with system tests to similar tools
397
- such as capybara, it could happen that a connection end up pinned by the
398
- server thread rather than the test thread, causing
399
- `"Cannot expire connection, it is owned by a different thread"` errors.
400
502
 
401
- *Jean Boussier*
503
+ ## Rails 8.0.0.beta1 (September 26, 2024) ##
402
504
 
403
- * Fix `ActiveRecord::Base.with` to accept more than two sub queries.
505
+ * Allow `drop_table` to accept an array of table names.
404
506
 
405
- Fixes #53110.
507
+ This will let you to drop multiple tables in a single call.
406
508
 
407
509
  ```ruby
408
- User.with(foo: [User.select(:id), User.select(:id), User.select(:id)]).to_sql
409
- undefined method `union' for an instance of Arel::Nodes::UnionAll (NoMethodError)
510
+ ActiveRecord::Base.lease_connection.drop_table(:users, :posts)
410
511
  ```
411
512
 
412
- The above now works as expected.
413
-
414
- *fatkodima*
415
-
416
- * Properly release pinned connections with non joinable connections.
417
-
418
- Fixes #52973
513
+ *Gabriel Sobrinho*
419
514
 
420
- When running system tests with transactional fixtures on, it could happen that
421
- the connection leased by the Puma thread wouldn't be properly released back to the pool,
422
- causing "Cannot expire connection, it is owned by a different thread" errors in later tests.
423
-
424
- *Jean Boussier*
515
+ * Add support for PostgreSQL `IF NOT EXISTS` via the `:if_not_exists` option
516
+ on the `add_enum_value` method.
425
517
 
426
- * Make Float distinguish between `float4` and `float8` in PostgreSQL.
518
+ *Ariel Rzezak*
427
519
 
428
- Fixes #52742
520
+ * When running `db:migrate` on a fresh database, load the databases schemas before running migrations.
429
521
 
430
- *Ryota Kitazawa*, *Takayuki Nagatomi*
522
+ *Andrew Novoselac*, *Marek Kasztelnik*
431
523
 
432
524
  * Fix an issue where `.left_outer_joins` used with multiple associations that have
433
525
  the same child association but different parents does not join all parents.
@@ -440,6 +532,39 @@
440
532
 
441
533
  *Garrett Blehm*
442
534
 
535
+ * Deprecate `unsigned_float` and `unsigned_decimal` short-hand column methods.
536
+
537
+ As of MySQL 8.0.17, the UNSIGNED attribute is deprecated for columns of type FLOAT, DOUBLE,
538
+ and DECIMAL. Consider using a simple CHECK constraint instead for such columns.
539
+
540
+ https://dev.mysql.com/doc/refman/8.0/en/numeric-type-syntax.html
541
+
542
+ *Ryuta Kamizono*
543
+
544
+ * Drop MySQL 5.5 support.
545
+
546
+ MySQL 5.5 is the only version that does not support datetime with precision,
547
+ which we have supported in the core. Now we support MySQL 5.6.4 or later, which
548
+ is the first version to support datetime with precision.
549
+
550
+ *Ryuta Kamizono*
551
+
552
+ * Make Active Record asynchronous queries compatible with transactional fixtures.
553
+
554
+ Previously transactional fixtures would disable asynchronous queries, because transactional
555
+ fixtures impose all queries use the same connection.
556
+
557
+ Now asynchronous queries will use the connection pinned by transactional fixtures, and behave
558
+ much closer to production.
559
+
560
+ *Jean Boussier*
561
+
562
+ * Deserialize binary data before decrypting
563
+
564
+ This ensures that we call `PG::Connection.unescape_bytea` on PostgreSQL before decryption.
565
+
566
+ *Donal McBreen*
567
+
443
568
  * Ensure `ActiveRecord::Encryption.config` is always ready before access.
444
569
 
445
570
  Previously, `ActiveRecord::Encryption` configuration was deferred until `ActiveRecord::Base`
@@ -462,954 +587,262 @@
462
587
 
463
588
  *Ruy Rocha*
464
589
 
590
+ * Add support for SQLite3 full-text-search and other virtual tables.
465
591
 
466
- ## Rails 7.2.1.2 (October 23, 2024) ##
592
+ Previously, adding sqlite3 virtual tables messed up `schema.rb`.
467
593
 
468
- * No changes.
594
+ Now, virtual tables can safely be added using `create_virtual_table`.
469
595
 
596
+ *Zacharias Knudsen*
470
597
 
471
- ## Rails 7.2.1.1 (October 15, 2024) ##
598
+ * Support use of alternative database interfaces via the `database_cli` ActiveRecord configuration option.
472
599
 
473
- * No changes.
600
+ ```ruby
601
+ Rails.application.configure do
602
+ config.active_record.database_cli = { postgresql: "pgcli" }
603
+ end
604
+ ```
474
605
 
606
+ *T S Vallender*
475
607
 
476
- ## Rails 7.2.1 (August 22, 2024) ##
608
+ * Add support for dumping table inheritance and native partitioning table definitions for PostgeSQL adapter
477
609
 
478
- * Fix detection for `enum` columns with parallelized tests and PostgreSQL.
610
+ *Justin Talbott*
479
611
 
480
- *Rafael Mendonça França*
612
+ * Add support for `ActiveRecord::Point` type casts using `Hash` values
481
613
 
482
- * Allow to eager load nested nil associations.
614
+ This allows `ActiveRecord::Point` to be cast or serialized from a hash
615
+ with `:x` and `:y` keys of numeric values, mirroring the functionality of
616
+ existing casts for string and array values. Both string and symbol keys are
617
+ supported.
483
618
 
484
- *fatkodima*
619
+ ```ruby
620
+ class PostgresqlPoint < ActiveRecord::Base
621
+ attribute :x, :point
622
+ attribute :y, :point
623
+ attribute :z, :point
624
+ end
625
+
626
+ val = PostgresqlPoint.new({
627
+ x: '(12.34, -43.21)',
628
+ y: [12.34, '-43.21'],
629
+ z: {x: '12.34', y: -43.21}
630
+ })
631
+ ActiveRecord::Point.new(12.32, -43.21) == val.x == val.y == val.z
632
+ ```
485
633
 
486
- * Fix swallowing ignore order warning when batching using `BatchEnumerator`.
634
+ *Stephen Drew*
487
635
 
488
- *fatkodima*
636
+ * Replace `SQLite3::Database#busy_timeout` with `#busy_handler_timeout=`.
489
637
 
490
- * Fix memory bloat on the connection pool when using the Fiber `IsolatedExecutionState`.
638
+ Provides a non-GVL-blocking, fair retry interval busy handler implementation.
491
639
 
492
- *Jean Boussier*
640
+ *Stephen Margheim*
493
641
 
494
- * Restore inferred association class with the same modularized name.
642
+ * SQLite3Adapter: Translate `SQLite3::BusyException` into `ActiveRecord::StatementTimeout`.
495
643
 
496
- *Justin Ko*
644
+ *Matthew Nguyen*
497
645
 
498
- * Fix `ActiveRecord::Base.inspect` to properly explain how to load schema information.
646
+ * Include schema name in `enable_extension` statements in `db/schema.rb`.
499
647
 
500
- *Jean Boussier*
648
+ The schema dumper will now include the schema name in generated
649
+ `enable_extension` statements if they differ from the current schema.
501
650
 
502
- * Check invalid `enum` options for the new syntax.
651
+ For example, if you have a migration:
503
652
 
504
- The options using `_` prefix in the old syntax are invalid in the new syntax.
653
+ ```ruby
654
+ enable_extension "heroku_ext.pgcrypto"
655
+ enable_extension "pg_stat_statements"
656
+ ```
505
657
 
506
- *Rafael Mendonça França*
658
+ then the generated schema dump will also contain:
659
+
660
+ ```ruby
661
+ enable_extension "heroku_ext.pgcrypto"
662
+ enable_extension "pg_stat_statements"
663
+ ```
664
+
665
+ *Tony Novak*
507
666
 
508
667
  * Fix `ActiveRecord::Encryption::EncryptedAttributeType#type` to return
509
668
  actual cast type.
510
669
 
511
670
  *Vasiliy Ermolovich*
512
671
 
513
- * Fix `create_table` with `:auto_increment` option for MySQL adapter.
672
+ * SQLite3Adapter: Bulk insert fixtures.
514
673
 
515
- *fatkodima*
674
+ Previously one insert command was executed for each fixture, now they are
675
+ aggregated in a single bulk insert command.
516
676
 
677
+ *Lázaro Nixon*
517
678
 
518
- ## Rails 7.2.0 (August 09, 2024) ##
679
+ * PostgreSQLAdapter: Allow `disable_extension` to be called with schema-qualified name.
519
680
 
520
- * Handle commas in Sqlite3 default function definitions.
681
+ For parity with `enable_extension`, the `disable_extension` method can be called with a schema-qualified
682
+ name (e.g. `disable_extension "myschema.pgcrypto"`). Note that PostgreSQL's `DROP EXTENSION` does not
683
+ actually take a schema name (unlike `CREATE EXTENSION`), so the resulting SQL statement will only name
684
+ the extension, e.g. `DROP EXTENSION IF EXISTS "pgcrypto"`.
521
685
 
522
- *Stephen Margheim*
686
+ *Tony Novak*
523
687
 
524
- * Fixes `validates_associated` raising an exception when configured with a
525
- singular association and having `index_nested_attribute_errors` enabled.
688
+ * Make `create_schema` / `drop_schema` reversible in migrations.
526
689
 
527
- *Martin Spickermann*
690
+ Previously, `create_schema` and `drop_schema` were irreversible migration operations.
528
691
 
529
- * The constant `ActiveRecord::ImmutableRelation` has been deprecated because
530
- we want to reserve that name for a stronger sense of "immutable relation".
531
- Please use `ActiveRecord::UnmodifiableRelation` instead.
692
+ *Tony Novak*
532
693
 
533
- *Xavier Noria*
694
+ * Support batching using custom columns.
534
695
 
535
- * Add condensed `#inspect` for `ConnectionPool`, `AbstractAdapter`, and
536
- `DatabaseConfig`.
696
+ ```ruby
697
+ Product.in_batches(cursor: [:shop_id, :id]) do |relation|
698
+ # do something with relation
699
+ end
700
+ ```
537
701
 
538
- *Hartley McGuire*
702
+ *fatkodima*
539
703
 
540
- * Fixed a memory performance issue in Active Record attribute methods definition.
704
+ * Use SQLite `IMMEDIATE` transactions when possible.
541
705
 
542
- *Jean Boussier*
706
+ Transactions run against the SQLite3 adapter default to IMMEDIATE mode to improve concurrency support and avoid busy exceptions.
543
707
 
544
- * Define the new Active Support notification event `start_transaction.active_record`.
708
+ *Stephen Margheim*
545
709
 
546
- This event is fired when database transactions or savepoints start, and
547
- complements `transaction.active_record`, which is emitted when they finish.
710
+ * Raise specific exception when a connection is not defined.
548
711
 
549
- The payload has the transaction (`:transaction`) and the connection (`:connection`).
712
+ The new `ConnectionNotDefined` exception provides connection name, shard and role accessors indicating the details of the connection that was requested.
550
713
 
551
- *Xavier Noria*
714
+ *Hana Harencarova*, *Matthew Draper*
552
715
 
553
- * Fix an issue where the IDs reader method did not return expected results
554
- for preloaded associations in models using composite primary keys.
716
+ * Delete the deprecated constant `ActiveRecord::ImmutableRelation`.
555
717
 
556
- *Jay Ang*
718
+ *Xavier Noria*
557
719
 
558
- * The payload of `sql.active_record` Active Support notifications now has the current transaction in the `:transaction` key.
720
+ * Fix duplicate callback execution when child autosaves parent with `has_one` and `belongs_to`.
559
721
 
560
- *Xavier Noria*
722
+ Before, persisting a new child record with a new associated parent record would run `before_validation`,
723
+ `after_validation`, `before_save` and `after_save` callbacks twice.
561
724
 
562
- * The payload of `transaction.active_record` Active Support notifications now has the transaction the event is related to in the `:transaction` key.
725
+ Now, these callbacks are only executed once as expected.
563
726
 
564
- *Xavier Noria*
727
+ *Joshua Young*
565
728
 
566
- * Define `ActiveRecord::Transaction#uuid`, which returns a UUID for the database transaction. This may be helpful when tracing database activity. These UUIDs are generated only on demand.
729
+ * `ActiveRecord::Encryption::Encryptor` now supports a `:compressor` option to customize the compression algorithm used.
567
730
 
568
- *Xavier Noria*
731
+ ```ruby
732
+ module ZstdCompressor
733
+ def self.deflate(data)
734
+ Zstd.compress(data)
735
+ end
569
736
 
570
- * Fix inference of association model on nested models with the same demodularized name.
737
+ def self.inflate(data)
738
+ Zstd.decompress(data)
739
+ end
740
+ end
571
741
 
572
- E.g. with the following setup:
742
+ class User
743
+ encrypts :name, compressor: ZstdCompressor
744
+ end
745
+ ```
746
+
747
+ You disable compression by passing `compress: false`.
573
748
 
574
749
  ```ruby
575
- class Nested::Post < ApplicationRecord
576
- has_one :post, through: :other
750
+ class User
751
+ encrypts :name, compress: false
577
752
  end
578
753
  ```
579
754
 
580
- Before, `#post` would infer the model as `Nested::Post`, but now it correctly infers `Post`.
581
-
582
- *Joshua Young*
755
+ *heka1024*
583
756
 
584
- * PostgreSQL `Cidr#change?` detects the address prefix change.
757
+ * Add condensed `#inspect` for `ConnectionPool`, `AbstractAdapter`, and
758
+ `DatabaseConfig`.
585
759
 
586
- *Taketo Takashima*
760
+ *Hartley McGuire*
587
761
 
588
- * Change `BatchEnumerator#destroy_all` to return the total number of affected rows.
762
+ * Add `.shard_keys`, `.sharded?`, & `.connected_to_all_shards` methods.
589
763
 
590
- Previously, it always returned `nil`.
764
+ ```ruby
765
+ class ShardedBase < ActiveRecord::Base
766
+ self.abstract_class = true
591
767
 
592
- *fatkodima*
768
+ connects_to shards: {
769
+ shard_one: { writing: :shard_one },
770
+ shard_two: { writing: :shard_two }
771
+ }
772
+ end
593
773
 
594
- * Support `touch_all` in batches.
774
+ class ShardedModel < ShardedBase
775
+ end
595
776
 
596
- ```ruby
597
- Post.in_batches.touch_all
777
+ ShardedModel.shard_keys => [:shard_one, :shard_two]
778
+ ShardedModel.sharded? => true
779
+ ShardedBase.connected_to_all_shards { ShardedModel.current_shard } => [:shard_one, :shard_two]
598
780
  ```
599
781
 
600
- *fatkodima*
782
+ *Nony Dutton*
601
783
 
602
- * Add support for `:if_not_exists` and `:force` options to `create_schema`.
784
+ * Add a `filter` option to `in_order_of` to prioritize certain values in the sorting without filtering the results
785
+ by these values.
603
786
 
604
- *fatkodima*
787
+ *Igor Depolli*
605
788
 
606
- * Fix `index_errors` having incorrect index in association validation errors.
789
+ * Fix an issue where the IDs reader method did not return expected results
790
+ for preloaded associations in models using composite primary keys.
607
791
 
608
- *lulalala*
792
+ *Jay Ang*
609
793
 
610
- * Add `index_errors: :nested_attributes_order` mode.
794
+ * Allow to configure `strict_loading_mode` globally or within a model.
611
795
 
612
- This indexes the association validation errors based on the order received by nested attributes setter, and respects the `reject_if` configuration. This enables API to provide enough information to the frontend to map the validation errors back to their respective form fields.
796
+ Defaults to `:all`, can be changed to `:n_plus_one_only`.
613
797
 
614
- *lulalala*
798
+ *Garen Torikian*
615
799
 
616
- * Add `Rails.application.config.active_record.postgresql_adapter_decode_dates` to opt out of decoding dates automatically with the postgresql adapter. Defaults to true.
800
+ * Add `ActiveRecord::Relation#readonly?`.
617
801
 
618
- *Joé Dupuis*
802
+ Reflects if the relation has been marked as readonly.
619
803
 
620
- * Association option `query_constraints` is deprecated in favor of `foreign_key`.
804
+ *Theodor Tonum*
621
805
 
622
- *Nikita Vasilevsky*
806
+ * Improve `ActiveRecord::Store` to raise a descriptive exception if the column is not either
807
+ structured (e.g., PostgreSQL +hstore+/+json+, or MySQL +json+) or declared serializable via
808
+ `ActiveRecord.store`.
623
809
 
624
- * Add `ENV["SKIP_TEST_DATABASE_TRUNCATE"]` flag to speed up multi-process test runs on large DBs when all tests run within default transaction.
810
+ Previously, a `NoMethodError` would be raised when the accessor was read or written:
625
811
 
626
- This cuts ~10s from the test run of HEY when run by 24 processes against the 178 tables, since ~4,000 table truncates can then be skipped.
812
+ NoMethodError: undefined method `accessor' for an instance of ActiveRecord::Type::Text
627
813
 
628
- *DHH*
814
+ Now, a descriptive `ConfigurationError` is raised:
629
815
 
630
- * Added support for recursive common table expressions.
631
-
632
- ```ruby
633
- Post.with_recursive(
634
- post_and_replies: [
635
- Post.where(id: 42),
636
- Post.joins('JOIN post_and_replies ON posts.in_reply_to_id = post_and_replies.id'),
637
- ]
638
- )
639
- ```
640
-
641
- Generates the following SQL:
642
-
643
- ```sql
644
- WITH RECURSIVE "post_and_replies" AS (
645
- (SELECT "posts".* FROM "posts" WHERE "posts"."id" = 42)
646
- UNION ALL
647
- (SELECT "posts".* FROM "posts" JOIN post_and_replies ON posts.in_reply_to_id = post_and_replies.id)
648
- )
649
- SELECT "posts".* FROM "posts"
650
- ```
651
-
652
- *ClearlyClaire*
653
-
654
- * `validate_constraint` can be called in a `change_table` block.
655
-
656
- ex:
657
- ```ruby
658
- change_table :products do |t|
659
- t.check_constraint "price > discounted_price", name: "price_check", validate: false
660
- t.validate_check_constraint "price_check"
661
- end
662
- ```
663
-
664
- *Cody Cutrer*
665
-
666
- * `PostgreSQLAdapter` now decodes columns of type date to `Date` instead of string.
667
-
668
- Ex:
669
- ```ruby
670
- ActiveRecord::Base.connection
671
- .select_value("select '2024-01-01'::date").class #=> Date
672
- ```
673
-
674
- *Joé Dupuis*
675
-
676
- * Strict loading using `:n_plus_one_only` does not eagerly load child associations.
677
-
678
- With this change, child associations are no longer eagerly loaded, to
679
- match intended behavior and to prevent non-deterministic order issues caused
680
- by calling methods like `first` or `last`. As `first` and `last` don't cause
681
- an N+1 by themselves, calling child associations will no longer raise.
682
- Fixes #49473.
683
-
684
- Before:
685
-
686
- ```ruby
687
- person = Person.find(1)
688
- person.strict_loading!(mode: :n_plus_one_only)
689
- person.posts.first
690
- # SELECT * FROM posts WHERE person_id = 1; -- non-deterministic order
691
- person.posts.first.firm # raises ActiveRecord::StrictLoadingViolationError
692
- ```
693
-
694
- After:
695
-
696
- ```ruby
697
- person = Person.find(1)
698
- person.strict_loading!(mode: :n_plus_one_only)
699
- person.posts.first # this is 1+1, not N+1
700
- # SELECT * FROM posts WHERE person_id = 1 ORDER BY id LIMIT 1;
701
- person.posts.first.firm # no longer raises
702
- ```
703
-
704
- *Reid Lynch*
705
-
706
- * Allow `Sqlite3Adapter` to use `sqlite3` gem version `2.x`.
816
+ ActiveRecord::ConfigurationError: the column 'metadata' has not been configured as a store.
817
+ Please make sure the column is declared serializable via 'ActiveRecord.store' or, if your
818
+ database supports it, use a structured column type like hstore or json.
707
819
 
708
820
  *Mike Dalessio*
709
821
 
710
- * Allow `ActiveRecord::Base#pluck` to accept hash values.
711
-
712
- ```ruby
713
- # Before
714
- Post.joins(:comments).pluck("posts.id", "comments.id", "comments.body")
715
-
716
- # After
717
- Post.joins(:comments).pluck(posts: [:id], comments: [:id, :body])
718
- ```
719
-
720
- *fatkodima*
721
-
722
- * Raise an `ActiveRecord::ActiveRecordError` error when the MySQL database returns an invalid version string.
723
-
724
- *Kevin McPhillips*
725
-
726
- * `ActiveRecord::Base.transaction` now yields an `ActiveRecord::Transaction` object.
727
-
728
- This allows to register callbacks on it.
729
-
730
- ```ruby
731
- Article.transaction do |transaction|
732
- article.update(published: true)
733
- transaction.after_commit do
734
- PublishNotificationMailer.with(article: article).deliver_later
735
- end
736
- end
737
- ```
738
-
739
- *Jean Boussier*
740
-
741
- * Add `ActiveRecord::Base.current_transaction`.
742
-
743
- Returns the current transaction, to allow registering callbacks on it.
744
-
745
- ```ruby
746
- Article.current_transaction.after_commit do
747
- PublishNotificationMailer.with(article: article).deliver_later
748
- end
749
- ```
750
-
751
- *Jean Boussier*
752
-
753
- * Add `ActiveRecord.after_all_transactions_commit` callback.
754
-
755
- Useful for code that may run either inside or outside a transaction and needs
756
- to perform work after the state changes have been properly persisted.
757
-
758
- ```ruby
759
- def publish_article(article)
760
- article.update(published: true)
761
- ActiveRecord.after_all_transactions_commit do
762
- PublishNotificationMailer.with(article: article).deliver_later
763
- end
764
- end
765
- ```
766
-
767
- In the above example, the block is either executed immediately if called outside
768
- of a transaction, or called after the open transaction is committed.
769
-
770
- If the transaction is rolled back, the block isn't called.
771
-
772
- *Jean Boussier*
773
-
774
- * Add the ability to ignore counter cache columns until they are backfilled.
775
-
776
- Starting to use counter caches on existing large tables can be troublesome, because the column
777
- values must be backfilled separately of the column addition (to not lock the table for too long)
778
- and before the use of `:counter_cache` (otherwise methods like `size`/`any?`/etc, which use
779
- counter caches internally, can produce incorrect results). People usually use database triggers
780
- or callbacks on child associations while backfilling before introducing a counter cache
781
- configuration to the association.
782
-
783
- Now, to safely backfill the column, while keeping the column updated with child records added/removed, use:
784
-
785
- ```ruby
786
- class Comment < ApplicationRecord
787
- belongs_to :post, counter_cache: { active: false }
788
- end
789
- ```
790
-
791
- While the counter cache is not "active", the methods like `size`/`any?`/etc will not use it,
792
- but get the results directly from the database. After the counter cache column is backfilled, simply
793
- remove the `{ active: false }` part from the counter cache definition, and it will now be used by the
794
- mentioned methods.
795
-
796
- *fatkodima*
797
-
798
- * Retry known idempotent SELECT queries on connection-related exceptions.
799
-
800
- SELECT queries we construct by walking the Arel tree and / or with known model attributes
801
- are idempotent and can safely be retried in the case of a connection error. Previously,
802
- adapters such as `TrilogyAdapter` would raise `ActiveRecord::ConnectionFailed: Trilogy::EOFError`
803
- when encountering a connection error mid-request.
804
-
805
- *Adrianna Chang*
806
-
807
- * Allow association's `foreign_key` to be composite.
808
-
809
- `query_constraints` option was the only way to configure a composite foreign key by passing an `Array`.
810
- Now it's possible to pass an Array value as `foreign_key` to achieve the same behavior of an association.
811
-
812
- *Nikita Vasilevsky*
813
-
814
- * Allow association's `primary_key` to be composite.
815
-
816
- Association's `primary_key` can be composite when derived from associated model `primary_key` or `query_constraints`.
817
- Now it's possible to explicitly set it as composite on the association.
818
-
819
- *Nikita Vasilevsky*
820
-
821
- * Add `config.active_record.permanent_connection_checkout` setting.
822
-
823
- Controls whether `ActiveRecord::Base.connection` raises an error, emits a deprecation warning, or neither.
824
-
825
- `ActiveRecord::Base.connection` checkouts a database connection from the pool and keeps it leased until the end of
826
- the request or job. This behavior can be undesirable in environments that use many more threads or fibers than there
827
- is available connections.
828
-
829
- This configuration can be used to track down and eliminate code that calls `ActiveRecord::Base.connection` and
830
- migrate it to use `ActiveRecord::Base.with_connection` instead.
831
-
832
- The default behavior remains unchanged, and there is currently no plans to change the default.
833
-
834
- *Jean Boussier*
835
-
836
- * Add dirties option to uncached.
837
-
838
- This adds a `dirties` option to `ActiveRecord::Base.uncached` and
839
- `ActiveRecord::ConnectionAdapters::ConnectionPool#uncached`.
840
-
841
- When set to `true` (the default), writes will clear all query caches belonging to the current thread.
842
- When set to `false`, writes to the affected connection pool will not clear any query cache.
843
-
844
- This is needed by Solid Cache so that cache writes do not clear query caches.
845
-
846
- *Donal McBreen*
847
-
848
- * Deprecate `ActiveRecord::Base.connection` in favor of `.lease_connection`.
849
-
850
- The method has been renamed as `lease_connection` to better reflect that the returned
851
- connection will be held for the duration of the request or job.
852
-
853
- This deprecation is a soft deprecation, no warnings will be issued and there is no
854
- current plan to remove the method.
855
-
856
- *Jean Boussier*
857
-
858
- * Deprecate `ActiveRecord::ConnectionAdapters::ConnectionPool#connection`.
859
-
860
- The method has been renamed as `lease_connection` to better reflect that the returned
861
- connection will be held for the duration of the request or job.
862
-
863
- *Jean Boussier*
864
-
865
- * Expose a generic fixture accessor for fixture names that may conflict with Minitest.
866
-
867
- ```ruby
868
- assert_equal "Ruby on Rails", web_sites(:rubyonrails).name
869
- assert_equal "Ruby on Rails", fixture(:web_sites, :rubyonrails).name
870
- ```
871
-
872
- *Jean Boussier*
873
-
874
- * Using `Model.query_constraints` with a single non-primary-key column used to raise as expected, but with an
875
- incorrect error message.
876
-
877
- This has been fixed to raise with a more appropriate error message.
878
-
879
- *Joshua Young*
880
-
881
- * Fix `has_one` association autosave setting the foreign key attribute when it is unchanged.
882
-
883
- This behavior is also inconsistent with autosaving `belongs_to` and can have unintended side effects like raising
884
- an `ActiveRecord::ReadonlyAttributeError` when the foreign key attribute is marked as read-only.
885
-
886
- *Joshua Young*
887
-
888
- * Remove deprecated behavior that would rollback a transaction block when exited using `return`, `break` or `throw`.
889
-
890
- *Rafael Mendonça França*
891
-
892
- * Deprecate `Rails.application.config.active_record.commit_transaction_on_non_local_return`.
893
-
894
- *Rafael Mendonça França*
895
-
896
- * Remove deprecated support to pass `rewhere` to `ActiveRecord::Relation#merge`.
897
-
898
- *Rafael Mendonça França*
899
-
900
- * Remove deprecated support to pass `deferrable: true` to `add_foreign_key`.
901
-
902
- *Rafael Mendonça França*
903
-
904
- * Remove deprecated support to quote `ActiveSupport::Duration`.
905
-
906
- *Rafael Mendonça França*
907
-
908
- * Remove deprecated `#quote_bound_value`.
909
-
910
- *Rafael Mendonça França*
911
-
912
- * Remove deprecated `ActiveRecord::ConnectionAdapters::ConnectionPool#connection_klass`.
913
-
914
- *Rafael Mendonça França*
915
-
916
- * Remove deprecated support to apply `#connection_pool_list`, `#active_connections?`, `#clear_active_connections!`,
917
- `#clear_reloadable_connections!`, `#clear_all_connections!` and `#flush_idle_connections!` to the connections pools
918
- for the current role when the `role` argument isn't provided.
919
-
920
- *Rafael Mendonça França*
921
-
922
- * Remove deprecated `#all_connection_pools`.
923
-
924
- *Rafael Mendonça França*
925
-
926
- * Remove deprecated `ActiveRecord::ConnectionAdapters::SchemaCache#data_sources`.
927
-
928
- *Rafael Mendonça França*
929
-
930
- * Remove deprecated `ActiveRecord::ConnectionAdapters::SchemaCache.load_from`.
931
-
932
- *Rafael Mendonça França*
933
-
934
- * Remove deprecated `#all_foreign_keys_valid?` from database adapters.
935
-
936
- *Rafael Mendonça França*
937
-
938
- * Remove deprecated support to passing coder and class as second argument to `serialize`.
939
-
940
- *Rafael Mendonça França*
941
-
942
- * Remove deprecated support to `ActiveRecord::Base#read_attribute(:id)` to return the custom primary key value.
943
-
944
- *Rafael Mendonça França*
945
-
946
- * Remove deprecated `TestFixtures.fixture_path`.
947
-
948
- *Rafael Mendonça França*
949
-
950
- * Remove deprecated behavior to support referring to a singular association by its plural name.
951
-
952
- *Rafael Mendonça França*
953
-
954
- * Deprecate `Rails.application.config.active_record.allow_deprecated_singular_associations_name`.
955
-
956
- *Rafael Mendonça França*
957
-
958
- * Remove deprecated support to passing `SchemaMigration` and `InternalMetadata` classes as arguments to
959
- `ActiveRecord::MigrationContext`.
960
-
961
- *Rafael Mendonça França*
962
-
963
- * Remove deprecated `ActiveRecord::Migration.check_pending!` method.
964
-
965
- *Rafael Mendonça França*
966
-
967
- * Remove deprecated `ActiveRecord::LogSubscriber.runtime` method.
968
-
969
- *Rafael Mendonça França*
970
-
971
- * Remove deprecated `ActiveRecord::LogSubscriber.runtime=` method.
972
-
973
- *Rafael Mendonça França*
974
-
975
- * Remove deprecated `ActiveRecord::LogSubscriber.reset_runtime` method.
976
-
977
- *Rafael Mendonça França*
978
-
979
- * Remove deprecated support to define `explain` in the connection adapter with 2 arguments.
980
-
981
- *Rafael Mendonça França*
982
-
983
- * Remove deprecated `ActiveRecord::ActiveJobRequiredError`.
984
-
985
- *Rafael Mendonça França*
986
-
987
- * Remove deprecated `ActiveRecord::Base.clear_active_connections!`.
988
-
989
- *Rafael Mendonça França*
990
-
991
- * Remove deprecated `ActiveRecord::Base.clear_reloadable_connections!`.
992
-
993
- *Rafael Mendonça França*
994
-
995
- * Remove deprecated `ActiveRecord::Base.clear_all_connections!`.
996
-
997
- *Rafael Mendonça França*
998
-
999
- * Remove deprecated `ActiveRecord::Base.flush_idle_connections!`.
1000
-
1001
- *Rafael Mendonça França*
1002
-
1003
- * Remove deprecated `name` argument from `ActiveRecord::Base.remove_connection`.
1004
-
1005
- *Rafael Mendonça França*
1006
-
1007
- * Remove deprecated support to call `alias_attribute` with non-existent attribute names.
1008
-
1009
- *Rafael Mendonça França*
1010
-
1011
- * Remove deprecated `Rails.application.config.active_record.suppress_multiple_database_warning`.
1012
-
1013
- *Rafael Mendonça França*
1014
-
1015
- * Add `ActiveRecord::Encryption::MessagePackMessageSerializer`.
1016
-
1017
- Serialize data to the MessagePack format, for efficient storage in binary columns.
1018
-
1019
- The binary encoding requires around 30% less space than the base64 encoding
1020
- used by the default serializer.
1021
-
1022
- *Donal McBreen*
1023
-
1024
- * Add support for encrypting binary columns.
1025
-
1026
- Ensure encryption and decryption pass `Type::Binary::Data` around for binary data.
1027
-
1028
- Previously encrypting binary columns with the `ActiveRecord::Encryption::MessageSerializer`
1029
- incidentally worked for MySQL and SQLite, but not PostgreSQL.
1030
-
1031
- *Donal McBreen*
1032
-
1033
- * Deprecated `ENV["SCHEMA_CACHE"]` in favor of `schema_cache_path` in the database configuration.
1034
-
1035
- *Rafael Mendonça França*
1036
-
1037
- * Add `ActiveRecord::Base.with_connection` as a shortcut for leasing a connection for a short duration.
1038
-
1039
- The leased connection is yielded, and for the duration of the block, any call to `ActiveRecord::Base.connection`
1040
- will yield that same connection.
1041
-
1042
- This is useful to perform a few database operations without causing a connection to be leased for the
1043
- entire duration of the request or job.
1044
-
1045
- *Jean Boussier*
1046
-
1047
- * Deprecate `config.active_record.warn_on_records_fetched_greater_than` now that `sql.active_record`
1048
- notification includes `:row_count` field.
1049
-
1050
- *Jason Nochlin*
1051
-
1052
- * Fix an issue with `where.associated` losing the current join type scope.
1053
-
1054
- Example:
1055
-
1056
- ```ruby
1057
- Post.left_joins(:author).where.associated(:author)
1058
- ```
1059
-
1060
- Previously, the `LEFT OUTER JOIN` would be lost and converted to an `INNER JOIN`.
1061
-
1062
- *Saleh Alhaddad*
1063
-
1064
- * Fix an issue where `ActiveRecord::Encryption` configurations are not ready before the loading
1065
- of Active Record models, when an application is eager loaded. As a result, encrypted attributes
1066
- could be misconfigured in some cases.
1067
-
1068
- *Maxime Réty*
822
+ * Fix inference of association model on nested models with the same demodularized name.
1069
823
 
1070
- * Deprecate defining an `enum` with keyword arguments.
824
+ E.g. with the following setup:
1071
825
 
1072
826
  ```ruby
1073
- class Function > ApplicationRecord
1074
- # BAD
1075
- enum color: [:red, :blue],
1076
- type: [:instance, :class]
1077
-
1078
- # GOOD
1079
- enum :color, [:red, :blue]
1080
- enum :type, [:instance, :class]
827
+ class Nested::Post < ApplicationRecord
828
+ has_one :post, through: :other
1081
829
  end
1082
830
  ```
1083
831
 
1084
- *Hartley McGuire*
1085
-
1086
- * Add `config.active_record.validate_migration_timestamps` option for validating migration timestamps.
1087
-
1088
- When set, validates that the timestamp prefix for a migration is no more than a day ahead of
1089
- the timestamp associated with the current time. This is designed to prevent migrations prefixes
1090
- from being hand-edited to future timestamps, which impacts migration generation and other
1091
- migration commands.
1092
-
1093
- *Adrianna Chang*
1094
-
1095
- * Properly synchronize `Mysql2Adapter#active?` and `TrilogyAdapter#active?`.
1096
-
1097
- As well as `disconnect!` and `verify!`.
1098
-
1099
- This generally isn't a big problem as connections must not be shared between
1100
- threads, but is required when running transactional tests or system tests
1101
- and could lead to a SEGV.
1102
-
1103
- *Jean Boussier*
1104
-
1105
- * Support `:source_location` tag option for query log tags.
1106
-
1107
- ```ruby
1108
- config.active_record.query_log_tags << :source_location
1109
- ```
1110
-
1111
- Calculating the caller location is a costly operation and should be used primarily in development
1112
- (note, there is also a `config.active_record.verbose_query_logs` that serves the same purpose)
1113
- or occasionally on production for debugging purposes.
1114
-
1115
- *fatkodima*
1116
-
1117
- * Add an option to `ActiveRecord::Encryption::Encryptor` to disable compression.
1118
-
1119
- Allow compression to be disabled by setting `compress: false`
1120
-
1121
- ```ruby
1122
- class User
1123
- encrypts :name, encryptor: ActiveRecord::Encryption::Encryptor.new(compress: false)
1124
- end
1125
- ```
1126
-
1127
- *Donal McBreen*
1128
-
1129
- * Deprecate passing strings to `ActiveRecord::Tasks::DatabaseTasks.cache_dump_filename`.
1130
-
1131
- A `ActiveRecord::DatabaseConfigurations::DatabaseConfig` object should be passed instead.
1132
-
1133
- *Rafael Mendonça França*
1134
-
1135
- * Add `row_count` field to `sql.active_record` notification.
1136
-
1137
- This field returns the amount of rows returned by the query that emitted the notification.
1138
-
1139
- This metric is useful in cases where one wants to detect queries with big result sets.
1140
-
1141
- *Marvin Bitterlich*
1142
-
1143
- * Consistently raise an `ArgumentError` when passing an invalid argument to a nested attributes association writer.
1144
-
1145
- Previously, this would only raise on collection associations and produce a generic error on singular associations.
1146
-
1147
- Now, it will raise on both collection and singular associations.
1148
-
1149
- *Joshua Young*
1150
-
1151
- * Fix single quote escapes on default generated MySQL columns.
1152
-
1153
- MySQL 5.7.5+ supports generated columns, which can be used to create a column that is computed from an expression.
1154
-
1155
- Previously, the schema dump would output a string with double escapes for generated columns with single quotes in the default expression.
1156
-
1157
- This would result in issues when importing the schema on a fresh instance of a MySQL database.
1158
-
1159
- Now, the string will not be escaped and will be valid Ruby upon importing of the schema.
1160
-
1161
- *Yash Kapadia*
1162
-
1163
- * Fix Migrations with versions older than 7.1 validating options given to
1164
- `add_reference` and `t.references`.
1165
-
1166
- *Hartley McGuire*
1167
-
1168
- * Add `<role>_types` class method to `ActiveRecord::DelegatedType` so that the delegated types can be introspected.
1169
-
1170
- *JP Rosevear*
1171
-
1172
- * Make `schema_dump`, `query_cache`, `replica` and `database_tasks` configurable via `DATABASE_URL`.
1173
-
1174
- This wouldn't always work previously because boolean values would be interpreted as strings.
1175
-
1176
- e.g. `DATABASE_URL=postgres://localhost/foo?schema_dump=false` now properly disable dumping the schema
1177
- cache.
1178
-
1179
- *Mike Coutermarsh*, *Jean Boussier*
1180
-
1181
- * Introduce `ActiveRecord::Transactions::ClassMethods#set_callback`.
1182
-
1183
- It is identical to `ActiveSupport::Callbacks::ClassMethods#set_callback`
1184
- but with support for `after_commit` and `after_rollback` callback options.
832
+ Before, `#post` would infer the model as `Nested::Post`, but now it correctly infers `Post`.
1185
833
 
1186
834
  *Joshua Young*
1187
835
 
1188
- * Make `ActiveRecord::Encryption::Encryptor` agnostic of the serialization format used for encrypted data.
1189
-
1190
- Previously, the encryptor instance only allowed an encrypted value serialized as a `String` to be passed to the message serializer.
1191
-
1192
- Now, the encryptor lets the configured `message_serializer` decide which types of serialized encrypted values are supported. A custom serialiser is therefore allowed to serialize `ActiveRecord::Encryption::Message` objects using a type other than `String`.
1193
-
1194
- The default `ActiveRecord::Encryption::MessageSerializer` already ensures that only `String` objects are passed for deserialization.
1195
-
1196
- *Maxime Réty*
1197
-
1198
- * Fix `encrypted_attribute?` to take into account context properties passed to `encrypts`.
1199
-
1200
- *Maxime Réty*
1201
-
1202
- * The object returned by `explain` now responds to `pluck`, `first`,
1203
- `last`, `average`, `count`, `maximum`, `minimum`, and `sum`. Those
1204
- new methods run `EXPLAIN` on the corresponding queries:
1205
-
1206
- ```ruby
1207
- User.all.explain.count
1208
- # EXPLAIN SELECT COUNT(*) FROM `users`
1209
- # ...
1210
-
1211
- User.all.explain.maximum(:id)
1212
- # EXPLAIN SELECT MAX(`users`.`id`) FROM `users`
1213
- # ...
1214
- ```
1215
-
1216
- *Petrik de Heus*
1217
-
1218
- * Fixes an issue where `validates_associated` `:on` option wasn't respected
1219
- when validating associated records.
1220
-
1221
- *Austen Madden*, *Alex Ghiculescu*, *Rafał Brize*
1222
-
1223
- * Allow overriding SQLite defaults from `database.yml`.
1224
-
1225
- Any PRAGMA configuration set under the `pragmas` key in the configuration
1226
- file takes precedence over Rails' defaults, and additional PRAGMAs can be
1227
- set as well.
1228
-
1229
- ```yaml
1230
- database: storage/development.sqlite3
1231
- timeout: 5000
1232
- pragmas:
1233
- journal_mode: off
1234
- temp_store: memory
1235
- ```
1236
-
1237
- *Stephen Margheim*
1238
-
1239
- * Remove warning message when running SQLite in production, but leave it unconfigured.
1240
-
1241
- There are valid use cases for running SQLite in production. However, it must be done
1242
- with care, so instead of a warning most users won't see anyway, it's preferable to
1243
- leave the configuration commented out to force them to think about having the database
1244
- on a persistent volume etc.
1245
-
1246
- *Jacopo Beschi*, *Jean Boussier*
1247
-
1248
- * Add support for generated columns to the SQLite3 adapter.
1249
-
1250
- Generated columns (both stored and dynamic) are supported since version 3.31.0 of SQLite.
1251
- This adds support for those to the SQLite3 adapter.
1252
-
1253
- ```ruby
1254
- create_table :users do |t|
1255
- t.string :name
1256
- t.virtual :name_upper, type: :string, as: 'UPPER(name)'
1257
- t.virtual :name_lower, type: :string, as: 'LOWER(name)', stored: true
1258
- end
1259
- ```
1260
-
1261
- *Stephen Margheim*
1262
-
1263
- * TrilogyAdapter: ignore `host` if `socket` parameter is set.
1264
-
1265
- This allows to configure a connection on a UNIX socket via `DATABASE_URL`:
1266
-
1267
- ```
1268
- DATABASE_URL=trilogy://does-not-matter/my_db_production?socket=/var/run/mysql.sock
1269
- ```
1270
-
1271
- *Jean Boussier*
1272
-
1273
- * Make `assert_queries_count`, `assert_no_queries`, `assert_queries_match`, and
1274
- `assert_no_queries_match` assertions public.
1275
-
1276
- To assert the expected number of queries are made, Rails internally uses `assert_queries_count` and
1277
- `assert_no_queries`. To assert that specific SQL queries are made, `assert_queries_match` and
1278
- `assert_no_queries_match` are used. These assertions can now be used in applications as well.
1279
-
1280
- ```ruby
1281
- class ArticleTest < ActiveSupport::TestCase
1282
- test "queries are made" do
1283
- assert_queries_count(1) { Article.first }
1284
- end
1285
-
1286
- test "creates a foreign key" do
1287
- assert_queries_match(/ADD FOREIGN KEY/i, include_schema: true) do
1288
- @connection.add_foreign_key(:comments, :posts)
1289
- end
1290
- end
1291
- end
1292
- ```
1293
-
1294
- *Petrik de Heus*, *fatkodima*
1295
-
1296
- * Fix `has_secure_token` calls the setter method on initialize.
1297
-
1298
- *Abeid Ahmed*
1299
-
1300
- * When using a `DATABASE_URL`, allow for a configuration to map the protocol in the URL to a specific database
1301
- adapter. This allows decoupling the adapter the application chooses to use from the database connection details
1302
- set in the deployment environment.
1303
-
1304
- ```ruby
1305
- # ENV['DATABASE_URL'] = "mysql://localhost/example_database"
1306
- config.active_record.protocol_adapters.mysql = "trilogy"
1307
- # will connect to MySQL using the trilogy adapter
1308
- ```
1309
-
1310
- *Jean Boussier*, *Kevin McPhillips*
1311
-
1312
- * In cases where MySQL returns `warning_count` greater than zero, but returns no warnings when
1313
- the `SHOW WARNINGS` query is executed, `ActiveRecord.db_warnings_action` proc will still be
1314
- called with a generic warning message rather than silently ignoring the warning(s).
1315
-
1316
- *Kevin McPhillips*
1317
-
1318
- * `DatabaseConfigurations#configs_for` accepts a symbol in the `name` parameter.
1319
-
1320
- *Andrew Novoselac*
1321
-
1322
- * Fix `where(field: values)` queries when `field` is a serialized attribute
1323
- (for example, when `field` uses `ActiveRecord::Base.serialize` or is a JSON
1324
- column).
1325
-
1326
- *João Alves*
1327
-
1328
- * Make the output of `ActiveRecord::Core#inspect` configurable.
1329
-
1330
- By default, calling `inspect` on a record will yield a formatted string including just the `id`.
1331
-
1332
- ```ruby
1333
- Post.first.inspect #=> "#<Post id: 1>"
1334
- ```
1335
-
1336
- The attributes to be included in the output of `inspect` can be configured with
1337
- `ActiveRecord::Core#attributes_for_inspect`.
1338
-
1339
- ```ruby
1340
- Post.attributes_for_inspect = [:id, :title]
1341
- Post.first.inspect #=> "#<Post id: 1, title: "Hello, World!">"
1342
- ```
1343
-
1344
- With `attributes_for_inspect` set to `:all`, `inspect` will list all the record's attributes.
1345
-
1346
- ```ruby
1347
- Post.attributes_for_inspect = :all
1348
- Post.first.inspect #=> "#<Post id: 1, title: "Hello, World!", published_at: "2023-10-23 14:28:11 +0000">"
1349
- ```
1350
-
1351
- In `development` and `test` mode, `attributes_for_inspect` will be set to `:all` by default.
1352
-
1353
- You can also call `full_inspect` to get an inspection with all the attributes.
1354
-
1355
- The attributes in `attribute_for_inspect` will also be used for `pretty_print`.
1356
-
1357
- *Andrew Novoselac*
1358
-
1359
- * Don't mark attributes as changed when reassigned to `Float::INFINITY` or
1360
- `-Float::INFINITY`.
1361
-
1362
- *Maicol Bentancor*
1363
-
1364
- * Support the `RETURNING` clause for MariaDB.
1365
-
1366
- *fatkodima*, *Nikolay Kondratyev*
1367
-
1368
- * The SQLite3 adapter now implements the `supports_deferrable_constraints?` contract.
1369
-
1370
- Allows foreign keys to be deferred by adding the `:deferrable` key to the `foreign_key` options.
1371
-
1372
- ```ruby
1373
- add_reference :person, :alias, foreign_key: { deferrable: :deferred }
1374
- add_reference :alias, :person, foreign_key: { deferrable: :deferred }
1375
- ```
1376
-
1377
- *Stephen Margheim*
1378
-
1379
- * Add the `set_constraints` helper to PostgreSQL connections.
1380
-
1381
- ```ruby
1382
- Post.create!(user_id: -1) # => ActiveRecord::InvalidForeignKey
1383
-
1384
- Post.transaction do
1385
- Post.connection.set_constraints(:deferred)
1386
- p = Post.create!(user_id: -1)
1387
- u = User.create!
1388
- p.user = u
1389
- p.save!
1390
- end
1391
- ```
1392
-
1393
- *Cody Cutrer*
1394
-
1395
- * Include `ActiveModel::API` in `ActiveRecord::Base`.
1396
-
1397
- *Sean Doyle*
1398
-
1399
- * Ensure `#signed_id` outputs `url_safe` strings.
1400
-
1401
- *Jason Meller*
1402
-
1403
- * Add `nulls_last` and working `desc.nulls_first` for MySQL.
1404
-
1405
- *Tristan Fellows*
836
+ * Add public method for checking if a table is ignored by the schema cache.
1406
837
 
1407
- * Allow for more complex hash arguments for `order` which mimics `where` in `ActiveRecord::Relation`.
838
+ Previously, an application would need to reimplement `ignored_table?` from the schema cache class to check if a table was set to be ignored. This adds a public method to support this and updates the schema cache to use that directly.
1408
839
 
1409
840
  ```ruby
1410
- Topic.includes(:posts).order(posts: { created_at: :desc })
841
+ ActiveRecord.schema_cache_ignored_tables = ["developers"]
842
+ ActiveRecord.schema_cache_ignored_table?("developers")
843
+ => true
1411
844
  ```
1412
845
 
1413
- *Myles Boone*
846
+ *Eileen M. Uchitelle*
1414
847
 
1415
- Please check [7-1-stable](https://github.com/rails/rails/blob/7-1-stable/activerecord/CHANGELOG.md) for previous changes.
848
+ Please check [7-2-stable](https://github.com/rails/rails/blob/7-2-stable/activerecord/CHANGELOG.md) for previous changes.