activerecord 7.2.3 → 8.0.0.beta1

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.

Potentially problematic release.


This version of activerecord might be problematic. Click here for more details.

Files changed (132) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +192 -1261
  3. data/README.rdoc +2 -2
  4. data/lib/active_record/associations/alias_tracker.rb +4 -6
  5. data/lib/active_record/associations/association.rb +25 -5
  6. data/lib/active_record/associations/belongs_to_association.rb +2 -18
  7. data/lib/active_record/associations/builder/association.rb +7 -6
  8. data/lib/active_record/associations/collection_association.rb +4 -4
  9. data/lib/active_record/associations/disable_joins_association_scope.rb +1 -1
  10. data/lib/active_record/associations/has_many_through_association.rb +4 -9
  11. data/lib/active_record/associations/join_dependency/join_association.rb +27 -25
  12. data/lib/active_record/associations/preloader/association.rb +2 -2
  13. data/lib/active_record/associations/singular_association.rb +8 -3
  14. data/lib/active_record/associations.rb +50 -32
  15. data/lib/active_record/asynchronous_queries_tracker.rb +28 -24
  16. data/lib/active_record/attribute_methods/serialization.rb +1 -1
  17. data/lib/active_record/attribute_methods.rb +19 -24
  18. data/lib/active_record/attributes.rb +26 -37
  19. data/lib/active_record/autosave_association.rb +81 -49
  20. data/lib/active_record/base.rb +2 -2
  21. data/lib/active_record/callbacks.rb +1 -1
  22. data/lib/active_record/connection_adapters/abstract/connection_handler.rb +16 -10
  23. data/lib/active_record/connection_adapters/abstract/connection_pool/queue.rb +0 -1
  24. data/lib/active_record/connection_adapters/abstract/connection_pool/reaper.rb +0 -1
  25. data/lib/active_record/connection_adapters/abstract/connection_pool.rb +31 -75
  26. data/lib/active_record/connection_adapters/abstract/database_statements.rb +90 -43
  27. data/lib/active_record/connection_adapters/abstract/query_cache.rb +14 -19
  28. data/lib/active_record/connection_adapters/abstract/quoting.rb +1 -1
  29. data/lib/active_record/connection_adapters/abstract/schema_definitions.rb +2 -6
  30. data/lib/active_record/connection_adapters/abstract/schema_statements.rb +27 -9
  31. data/lib/active_record/connection_adapters/abstract/transaction.rb +15 -5
  32. data/lib/active_record/connection_adapters/abstract_adapter.rb +27 -57
  33. data/lib/active_record/connection_adapters/abstract_mysql_adapter.rb +28 -58
  34. data/lib/active_record/connection_adapters/mysql/quoting.rb +1 -15
  35. data/lib/active_record/connection_adapters/mysql/schema_definitions.rb +2 -8
  36. data/lib/active_record/connection_adapters/mysql/schema_statements.rb +43 -45
  37. data/lib/active_record/connection_adapters/mysql2/database_statements.rb +42 -98
  38. data/lib/active_record/connection_adapters/mysql2_adapter.rb +2 -16
  39. data/lib/active_record/connection_adapters/postgresql/database_statements.rb +64 -42
  40. data/lib/active_record/connection_adapters/postgresql/oid/point.rb +10 -0
  41. data/lib/active_record/connection_adapters/postgresql/schema_creation.rb +0 -1
  42. data/lib/active_record/connection_adapters/postgresql/schema_definitions.rb +12 -14
  43. data/lib/active_record/connection_adapters/postgresql/schema_dumper.rb +1 -1
  44. data/lib/active_record/connection_adapters/postgresql/schema_statements.rb +51 -9
  45. data/lib/active_record/connection_adapters/postgresql_adapter.rb +44 -101
  46. data/lib/active_record/connection_adapters/schema_cache.rb +1 -3
  47. data/lib/active_record/connection_adapters/sqlite3/database_statements.rb +76 -100
  48. data/lib/active_record/connection_adapters/sqlite3/quoting.rb +0 -13
  49. data/lib/active_record/connection_adapters/sqlite3/schema_creation.rb +0 -6
  50. data/lib/active_record/connection_adapters/sqlite3/schema_dumper.rb +13 -0
  51. data/lib/active_record/connection_adapters/sqlite3/schema_statements.rb +8 -2
  52. data/lib/active_record/connection_adapters/sqlite3_adapter.rb +60 -22
  53. data/lib/active_record/connection_adapters/trilogy/database_statements.rb +37 -67
  54. data/lib/active_record/connection_adapters/trilogy_adapter.rb +1 -18
  55. data/lib/active_record/connection_handling.rb +29 -11
  56. data/lib/active_record/core.rb +15 -60
  57. data/lib/active_record/counter_cache.rb +1 -1
  58. data/lib/active_record/database_configurations/connection_url_resolver.rb +1 -3
  59. data/lib/active_record/delegated_type.rb +18 -18
  60. data/lib/active_record/encryption/config.rb +3 -1
  61. data/lib/active_record/encryption/encryptable_record.rb +5 -5
  62. data/lib/active_record/encryption/encrypted_attribute_type.rb +11 -2
  63. data/lib/active_record/encryption/encryptor.rb +35 -29
  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 +12 -13
  67. data/lib/active_record/errors.rb +16 -8
  68. data/lib/active_record/fixture_set/table_row.rb +2 -19
  69. data/lib/active_record/fixtures.rb +0 -1
  70. data/lib/active_record/future_result.rb +14 -10
  71. data/lib/active_record/gem_version.rb +4 -4
  72. data/lib/active_record/insert_all.rb +1 -1
  73. data/lib/active_record/marshalling.rb +1 -4
  74. data/lib/active_record/migration/command_recorder.rb +22 -5
  75. data/lib/active_record/migration/compatibility.rb +5 -2
  76. data/lib/active_record/migration.rb +36 -35
  77. data/lib/active_record/model_schema.rb +1 -1
  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_cache.rb +5 -4
  81. data/lib/active_record/query_logs.rb +98 -44
  82. data/lib/active_record/query_logs_formatter.rb +17 -28
  83. data/lib/active_record/querying.rb +10 -10
  84. data/lib/active_record/railtie.rb +5 -6
  85. data/lib/active_record/railties/databases.rake +1 -2
  86. data/lib/active_record/reflection.rb +9 -7
  87. data/lib/active_record/relation/batches/batch_enumerator.rb +4 -3
  88. data/lib/active_record/relation/batches.rb +132 -72
  89. data/lib/active_record/relation/calculations.rb +55 -55
  90. data/lib/active_record/relation/delegation.rb +25 -14
  91. data/lib/active_record/relation/finder_methods.rb +31 -32
  92. data/lib/active_record/relation/merger.rb +8 -8
  93. data/lib/active_record/relation/predicate_builder/association_query_value.rb +0 -2
  94. data/lib/active_record/relation/predicate_builder/polymorphic_array_value.rb +1 -1
  95. data/lib/active_record/relation/predicate_builder/relation_handler.rb +4 -3
  96. data/lib/active_record/relation/predicate_builder.rb +5 -0
  97. data/lib/active_record/relation/query_attribute.rb +1 -1
  98. data/lib/active_record/relation/query_methods.rb +90 -91
  99. data/lib/active_record/relation/record_fetch_warning.rb +2 -2
  100. data/lib/active_record/relation/spawn_methods.rb +1 -1
  101. data/lib/active_record/relation/where_clause.rb +2 -8
  102. data/lib/active_record/relation.rb +77 -76
  103. data/lib/active_record/result.rb +68 -7
  104. data/lib/active_record/sanitization.rb +7 -6
  105. data/lib/active_record/schema_dumper.rb +16 -29
  106. data/lib/active_record/schema_migration.rb +2 -1
  107. data/lib/active_record/scoping/named.rb +5 -2
  108. data/lib/active_record/secure_token.rb +3 -3
  109. data/lib/active_record/signed_id.rb +6 -7
  110. data/lib/active_record/statement_cache.rb +12 -12
  111. data/lib/active_record/store.rb +7 -3
  112. data/lib/active_record/tasks/database_tasks.rb +24 -15
  113. data/lib/active_record/tasks/mysql_database_tasks.rb +0 -2
  114. data/lib/active_record/tasks/postgresql_database_tasks.rb +0 -7
  115. data/lib/active_record/tasks/sqlite_database_tasks.rb +2 -2
  116. data/lib/active_record/test_fixtures.rb +12 -0
  117. data/lib/active_record/testing/query_assertions.rb +2 -2
  118. data/lib/active_record/token_for.rb +1 -1
  119. data/lib/active_record/transactions.rb +1 -3
  120. data/lib/active_record/validations/uniqueness.rb +8 -8
  121. data/lib/active_record.rb +16 -1
  122. data/lib/arel/collectors/bind.rb +1 -1
  123. data/lib/arel/crud.rb +0 -2
  124. data/lib/arel/delete_manager.rb +0 -5
  125. data/lib/arel/nodes/delete_statement.rb +2 -4
  126. data/lib/arel/nodes/update_statement.rb +2 -4
  127. data/lib/arel/select_manager.rb +2 -6
  128. data/lib/arel/update_manager.rb +0 -5
  129. data/lib/arel/visitors/dot.rb +0 -2
  130. data/lib/arel/visitors/sqlite.rb +0 -25
  131. data/lib/arel/visitors/to_sql.rb +1 -3
  132. metadata +14 -11
data/CHANGELOG.md CHANGED
@@ -1,1415 +1,346 @@
1
- ## Rails 7.2.3 (October 28, 2025) ##
1
+ ## Rails 8.0.0.beta1 (September 26, 2024) ##
2
2
 
3
- * Fix SQLite3 data loss during table alterations with CASCADE foreign keys.
3
+ * Allow `drop_table` to accept an array of table names.
4
4
 
5
- When altering a table in SQLite3 that is referenced by child tables with
6
- `ON DELETE CASCADE` foreign keys, ActiveRecord would silently delete all
7
- data from the child tables. This occurred because SQLite requires table
8
- recreation for schema changes, and during this process the original table
9
- is temporarily dropped, triggering CASCADE deletes on child tables.
10
-
11
- The root cause was incorrect ordering of operations. The original code
12
- wrapped `disable_referential_integrity` inside a transaction, but
13
- `PRAGMA foreign_keys` cannot be modified inside a transaction in SQLite -
14
- attempting to do so simply has no effect. This meant foreign keys remained
15
- enabled during table recreation, causing CASCADE deletes to fire.
16
-
17
- The fix reverses the order to follow the official SQLite 12-step ALTER TABLE
18
- procedure: `disable_referential_integrity` now wraps the transaction instead
19
- of being wrapped by it. This ensures foreign keys are properly disabled
20
- before the transaction starts and re-enabled after it commits, preventing
21
- CASCADE deletes while maintaining data integrity through atomic transactions.
22
-
23
- *Ruy Rocha*
24
-
25
- * Fix `belongs_to` associations not to clear the entire composite primary key.
26
-
27
- When clearing a `belongs_to` association that references a model with composite primary key,
28
- only the optional part of the key should be cleared.
29
-
30
- *zzak*
31
-
32
- * Fix invalid records being autosaved when distantly associated records are marked for deletion.
33
-
34
- *Ian Terrell*, *axlekb AB*
35
-
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
-
50
- *Jean Boussier*
51
-
52
- * Fix query cache for pinned connections in multi threaded transactional tests.
53
-
54
- When a pinned connection is used across separate threads, they now use a separate cache store
55
- for each thread.
56
-
57
- This improve accuracy of system tests, and any test using multiple threads.
58
-
59
- *Heinrich Lee Yu*, *Jean Boussier*
60
-
61
- * Don't add `id_value` attribute alias when attribute/column with that name already exists.
62
-
63
- *Rob Lewis*
64
-
65
- * Fix false positive change detection involving STI and polymorhic has one relationships.
66
-
67
- Polymorphic `has_one` relationships would always be considered changed when defined in a STI child
68
- class, causing nedless extra autosaves.
69
-
70
- *David Fritsch*
71
-
72
- * Fix stale associaton detection for polymophic `belong_to`.
73
-
74
- *Florent Beaurain*, *Thomas Crambert*
75
-
76
- * Fix removal of PostgreSQL version comments in `structure.sql` for latest PostgreSQL versions which include `\restrict`.
77
-
78
- *Brendan Weibrecht*
79
-
80
- * Fix `#merge` with `#or` or `#and` and a mixture of attributes and SQL strings resulting in an incorrect query.
81
-
82
- ```ruby
83
- base = Comment.joins(:post).where(user_id: 1).where("recent = 1")
84
- puts base.merge(base.where(draft: true).or(Post.where(archived: true))).to_sql
85
- ```
86
-
87
- Before:
88
-
89
- ```SQL
90
- SELECT "comments".* FROM "comments"
91
- INNER JOIN "posts" ON "posts"."id" = "comments"."post_id"
92
- WHERE (recent = 1)
93
- AND (
94
- "comments"."user_id" = 1
95
- AND (recent = 1)
96
- AND "comments"."draft" = 1
97
- OR "posts"."archived" = 1
98
- )
99
- ```
100
-
101
- After:
102
-
103
- ```SQL
104
- SELECT "comments".* FROM "comments"
105
- INNER JOIN "posts" ON "posts"."id" = "comments"."post_id"
106
- WHERE "comments"."user_id" = 1
107
- AND (recent = 1)
108
- AND (
109
- "comments"."user_id" = 1
110
- AND (recent = 1)
111
- AND "comments"."draft" = 1
112
- OR "posts"."archived" = 1
113
- )
114
- ```
115
-
116
- *Joshua Young*
117
-
118
- * Fix inline `has_and_belongs_to_many` fixtures for tables with composite primary keys.
119
-
120
- *fatkodima*
121
-
122
- * Fix `annotate` comments to propagate to `update_all`/`delete_all`.
123
-
124
- *fatkodima*
125
-
126
- * Fix checking whether an unpersisted record is `include?`d in a strictly
127
- loaded `has_and_belongs_to_many` association.
128
-
129
- *Hartley McGuire*
130
-
131
- * Fix inline has_and_belongs_to_many fixtures for tables with composite primary keys.
132
-
133
- *fatkodima*
134
-
135
- * `create_or_find_by` will now correctly rollback a transaction.
136
-
137
- When using `create_or_find_by`, raising a ActiveRecord::Rollback error
138
- in a `after_save` callback had no effect, the transaction was committed
139
- and a record created.
140
-
141
- *Edouard Chin*
142
-
143
- * Gracefully handle `Timeout.timeout` firing during connection configuration.
144
-
145
- Use of `Timeout.timeout` could result in improperly initialized database connection.
146
-
147
- This could lead to a partially configured connection being used, resulting in various exceptions,
148
- the most common being with the PostgreSQLAdapter raising `undefined method 'key?' for nil`
149
- or `TypeError: wrong argument type nil (expected PG::TypeMap)`.
150
-
151
- *Jean Boussier*
152
-
153
- * The SQLite3 adapter quotes non-finite Numeric values like "Infinity" and "NaN".
154
-
155
- *Mike Dalessio*
156
-
157
- * Handle libpq returning a database version of 0 on no/bad connection in `PostgreSQLAdapter`.
158
-
159
- Before, this version would be cached and an error would be raised during connection configuration when
160
- comparing it with the minimum required version for the adapter. This meant that the connection could
161
- never be successfully configured on subsequent reconnection attempts.
162
-
163
- Now, this is treated as a connection failure consistent with libpq, raising a `ActiveRecord::ConnectionFailed`
164
- and ensuring the version isn't cached, which allows the version to be retrieved on the next connection attempt.
165
-
166
- *Joshua Young*, *Rian McGuire*
167
-
168
- * Fix error handling during connection configuration.
169
-
170
- Active Record wasn't properly handling errors during the connection configuration phase.
171
- This could lead to a partially configured connection being used, resulting in various exceptions,
172
- the most common being with the PostgreSQLAdapter raising `undefined method `key?' for nil`
173
- or `TypeError: wrong argument type nil (expected PG::TypeMap)`.
174
-
175
- *Jean Boussier*
176
-
177
- * Fix a case where a non-retryable query could be marked retryable.
178
-
179
- *Hartley McGuire*
180
-
181
- * Handle circular references when autosaving associations.
182
-
183
- *zzak*
184
-
185
- * Prevent persisting invalid record.
186
-
187
- *Edouard Chin*
188
-
189
- * Fix support for PostgreSQL enum types with commas in their name.
190
-
191
- *Arthur Hess*
192
-
193
- * Fix inserts on MySQL with no RETURNING support for a table with multiple auto populated columns.
194
-
195
- *Nikita Vasilevsky*
196
-
197
- * Fix joining on a scoped association with string joins and bind parameters.
198
-
199
- ```ruby
200
- class Instructor < ActiveRecord::Base
201
- has_many :instructor_roles, -> { active }
202
- end
203
-
204
- class InstructorRole < ActiveRecord::Base
205
- scope :active, -> {
206
- joins("JOIN students ON instructor_roles.student_id = students.id")
207
- .where(students { status: 1 })
208
- }
209
- end
210
-
211
- Instructor.joins(:instructor_roles).first
212
- ```
213
-
214
- The above example would result in `ActiveRecord::StatementInvalid` because the
215
- `active` scope bind parameters would be lost.
216
-
217
- *Jean Boussier*
218
-
219
- * Fix a potential race condition with system tests and transactional fixtures.
220
-
221
- *Sjoerd Lagarde*
222
-
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
- * Fix autosave associations to no longer validated unmodified associated records.
232
-
233
- Active Record was incorrectly performing validation on associated record that
234
- weren't created nor modified as part of the transaction:
235
-
236
- ```ruby
237
- Post.create!(author: User.find(1)) # Fail if user is invalid
238
- ```
239
-
240
- *Jean Boussier*
241
-
242
- * Remember when a database connection has recently been verified (for
243
- two seconds, by default), to avoid repeated reverifications during a
244
- single request.
245
-
246
- This should recreate a similar rate of verification as in Rails 7.1,
247
- where connections are leased for the duration of a request, and thus
248
- only verified once.
249
-
250
- *Matthew Draper*
251
-
252
- * Fix prepared statements on mysql2 adapter.
253
-
254
- *Jean Boussier*
255
-
256
- * Fix a race condition in `ActiveRecord::Base#method_missing` when lazily defining attributes.
257
-
258
- If multiple thread were concurrently triggering attribute definition on the same model,
259
- it could result in a `NoMethodError` being raised.
260
-
261
- *Jean Boussier*
262
-
263
- * Fix MySQL default functions getting dropped when changing a column's nullability.
264
-
265
- *Bastian Bartmann*
266
-
267
- * Fix `add_unique_constraint`/`add_check_constraint`/`/`add_foreign_key` to be revertible when
268
- given invalid options.
269
-
270
- *fatkodima*
271
-
272
- * Fix asynchronous destroying of polymorphic `belongs_to` associations.
273
-
274
- *fatkodima*
275
-
276
- * NOT VALID constraints should not dump in `create_table`.
277
-
278
- *Ryuta Kamizono*
279
-
280
- * Fix finding by nil composite primary key association.
281
-
282
- *fatkodima*
283
-
284
- * Fix parsing of SQLite foreign key names when they contain non-ASCII characters
285
-
286
- *Zacharias Knudsen*
287
-
288
- * Fix parsing of MySQL 8.0.16+ CHECK constraints when they contain new lines.
289
-
290
- *Steve Hill*
291
-
292
- * Ensure normalized attribute queries use `IS NULL` consistently for `nil` and normalized `nil` values.
293
-
294
- *Joshua Young*
295
-
296
- * Restore back the ability to pass only database name for `DATABASE_URL`.
297
-
298
- *fatkodima*
299
-
300
- * Fix `order` with using association name as an alias.
301
-
302
- *Ryuta Kamizono*
303
-
304
- * Improve invalid argument error for with.
305
-
306
- *Ryuta Kamizono*
307
-
308
- * Deduplicate `with` CTE expressions.
309
-
310
- *fatkodima*
311
-
312
-
313
- ## Rails 7.2.2.2 (August 13, 2025) ##
314
-
315
- * Call inspect on ids in RecordNotFound error
316
-
317
- [CVE-2025-55193]
318
-
319
- *Gannon McGibbon*, *John Hawthorn*
320
-
321
-
322
- ## Rails 7.2.2.1 (December 10, 2024) ##
323
-
324
- * No changes.
325
-
326
-
327
- ## Rails 7.2.2 (October 30, 2024) ##
328
-
329
- * Fix support for `query_cache: false` in `database.yml`.
330
-
331
- `query_cache: false` would no longer entirely disable the Active Record query cache.
332
-
333
- *zzak*
334
-
335
- * Set `.attributes_for_inspect` to `:all` by default.
336
-
337
- For new applications it is set to `[:id]` in config/environment/production.rb.
338
-
339
- In the console all the attributes are always shown.
340
-
341
- *Andrew Novoselac*
342
-
343
- * `PG::UnableToSend: no connection to the server` is now retryable as a connection-related exception
344
-
345
- *Kazuma Watanabe*
346
-
347
- * Fix marshalling of unsaved associated records in 7.1 format.
348
-
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.
351
-
352
- *Jean Boussier*
353
-
354
- * Fix incorrect SQL query when passing an empty hash to `ActiveRecord::Base.insert`.
355
-
356
- *David Stosik*
357
-
358
- * Allow to save records with polymorphic join tables that have `inverse_of`
359
- specified.
360
-
361
- *Markus Doits*
362
-
363
- * Fix association scopes applying on the incorrect join when using a polymorphic `has_many through:`.
364
-
365
- *Joshua Young*
366
-
367
- * Fix `dependent: :destroy` for bi-directional has one through association.
368
-
369
- Fixes #50948.
370
-
371
- ```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
386
- ```
387
- In the above example `left.destroy` wouldn't destroy its associated `Right`
388
- record.
389
-
390
- *Andy Stewart*
391
-
392
- * Properly handle lazily pinned connection pools.
393
-
394
- Fixes #53147.
395
-
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
-
401
- *Jean Boussier*
402
-
403
- * Fix `ActiveRecord::Base.with` to accept more than two sub queries.
404
-
405
- Fixes #53110.
406
-
407
- ```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)
410
- ```
411
-
412
- The above now works as expected.
413
-
414
- *fatkodima*
415
-
416
- * Properly release pinned connections with non joinable connections.
417
-
418
- Fixes #52973
419
-
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*
425
-
426
- * Make Float distinguish between `float4` and `float8` in PostgreSQL.
427
-
428
- Fixes #52742
429
-
430
- *Ryota Kitazawa*, *Takayuki Nagatomi*
431
-
432
- * Fix an issue where `.left_outer_joins` used with multiple associations that have
433
- the same child association but different parents does not join all parents.
434
-
435
- Previously, using `.left_outer_joins` with the same child association would only join one of the parents.
436
-
437
- Now it will correctly join both parents.
438
-
439
- Fixes #41498.
440
-
441
- *Garrett Blehm*
442
-
443
- * Ensure `ActiveRecord::Encryption.config` is always ready before access.
444
-
445
- Previously, `ActiveRecord::Encryption` configuration was deferred until `ActiveRecord::Base`
446
- was loaded. Therefore, accessing `ActiveRecord::Encryption.config` properties before
447
- `ActiveRecord::Base` was loaded would give incorrect results.
448
-
449
- `ActiveRecord::Encryption` now has its own loading hook so that its configuration is set as
450
- soon as needed.
451
-
452
- When `ActiveRecord::Base` is loaded, even lazily, it in turn triggers the loading of
453
- `ActiveRecord::Encryption`, thus preserving the original behavior of having its config ready
454
- before any use of `ActiveRecord::Base`.
455
-
456
- *Maxime Réty*
457
-
458
- * Add `TimeZoneConverter#==` method, so objects will be properly compared by
459
- their type, scale, limit & precision.
460
-
461
- Address #52699.
462
-
463
- *Ruy Rocha*
464
-
465
-
466
- ## Rails 7.2.1.2 (October 23, 2024) ##
467
-
468
- * No changes.
469
-
470
-
471
- ## Rails 7.2.1.1 (October 15, 2024) ##
472
-
473
- * No changes.
474
-
475
-
476
- ## Rails 7.2.1 (August 22, 2024) ##
477
-
478
- * Fix detection for `enum` columns with parallelized tests and PostgreSQL.
479
-
480
- *Rafael Mendonça França*
481
-
482
- * Allow to eager load nested nil associations.
483
-
484
- *fatkodima*
485
-
486
- * Fix swallowing ignore order warning when batching using `BatchEnumerator`.
487
-
488
- *fatkodima*
489
-
490
- * Fix memory bloat on the connection pool when using the Fiber `IsolatedExecutionState`.
491
-
492
- *Jean Boussier*
493
-
494
- * Restore inferred association class with the same modularized name.
495
-
496
- *Justin Ko*
497
-
498
- * Fix `ActiveRecord::Base.inspect` to properly explain how to load schema information.
499
-
500
- *Jean Boussier*
501
-
502
- * Check invalid `enum` options for the new syntax.
503
-
504
- The options using `_` prefix in the old syntax are invalid in the new syntax.
505
-
506
- *Rafael Mendonça França*
507
-
508
- * Fix `ActiveRecord::Encryption::EncryptedAttributeType#type` to return
509
- actual cast type.
510
-
511
- *Vasiliy Ermolovich*
512
-
513
- * Fix `create_table` with `:auto_increment` option for MySQL adapter.
514
-
515
- *fatkodima*
516
-
517
-
518
- ## Rails 7.2.0 (August 09, 2024) ##
519
-
520
- * Handle commas in Sqlite3 default function definitions.
521
-
522
- *Stephen Margheim*
523
-
524
- * Fixes `validates_associated` raising an exception when configured with a
525
- singular association and having `index_nested_attribute_errors` enabled.
526
-
527
- *Martin Spickermann*
528
-
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.
532
-
533
- *Xavier Noria*
534
-
535
- * Add condensed `#inspect` for `ConnectionPool`, `AbstractAdapter`, and
536
- `DatabaseConfig`.
537
-
538
- *Hartley McGuire*
539
-
540
- * Fixed a memory performance issue in Active Record attribute methods definition.
541
-
542
- *Jean Boussier*
543
-
544
- * Define the new Active Support notification event `start_transaction.active_record`.
545
-
546
- This event is fired when database transactions or savepoints start, and
547
- complements `transaction.active_record`, which is emitted when they finish.
548
-
549
- The payload has the transaction (`:transaction`) and the connection (`:connection`).
550
-
551
- *Xavier Noria*
552
-
553
- * Fix an issue where the IDs reader method did not return expected results
554
- for preloaded associations in models using composite primary keys.
555
-
556
- *Jay Ang*
557
-
558
- * The payload of `sql.active_record` Active Support notifications now has the current transaction in the `:transaction` key.
559
-
560
- *Xavier Noria*
561
-
562
- * The payload of `transaction.active_record` Active Support notifications now has the transaction the event is related to in the `:transaction` key.
563
-
564
- *Xavier Noria*
565
-
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.
567
-
568
- *Xavier Noria*
569
-
570
- * Fix inference of association model on nested models with the same demodularized name.
571
-
572
- E.g. with the following setup:
573
-
574
- ```ruby
575
- class Nested::Post < ApplicationRecord
576
- has_one :post, through: :other
577
- end
578
- ```
579
-
580
- Before, `#post` would infer the model as `Nested::Post`, but now it correctly infers `Post`.
581
-
582
- *Joshua Young*
583
-
584
- * PostgreSQL `Cidr#change?` detects the address prefix change.
585
-
586
- *Taketo Takashima*
587
-
588
- * Change `BatchEnumerator#destroy_all` to return the total number of affected rows.
589
-
590
- Previously, it always returned `nil`.
591
-
592
- *fatkodima*
593
-
594
- * Support `touch_all` in batches.
595
-
596
- ```ruby
597
- Post.in_batches.touch_all
598
- ```
599
-
600
- *fatkodima*
601
-
602
- * Add support for `:if_not_exists` and `:force` options to `create_schema`.
603
-
604
- *fatkodima*
605
-
606
- * Fix `index_errors` having incorrect index in association validation errors.
607
-
608
- *lulalala*
609
-
610
- * Add `index_errors: :nested_attributes_order` mode.
611
-
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.
613
-
614
- *lulalala*
615
-
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.
617
-
618
- *Joé Dupuis*
619
-
620
- * Association option `query_constraints` is deprecated in favor of `foreign_key`.
621
-
622
- *Nikita Vasilevsky*
623
-
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.
625
-
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.
627
-
628
- *DHH*
629
-
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`.
707
-
708
- *Mike Dalessio*
709
-
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:
5
+ This will let you to drop multiple tables in a single call.
784
6
 
785
7
  ```ruby
786
- class Comment < ApplicationRecord
787
- belongs_to :post, counter_cache: { active: false }
788
- end
8
+ ActiveRecord::Base.lease_connection.drop_table(:users, :posts)
789
9
  ```
790
10
 
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.
11
+ *Gabriel Sobrinho*
815
12
 
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.
13
+ * Add support for PostgreSQL `IF NOT EXISTS` via the `:if_not_exists` option
14
+ on the `add_enum_value` method.
818
15
 
819
- *Nikita Vasilevsky*
16
+ *Ariel Rzezak*
820
17
 
821
- * Add `config.active_record.permanent_connection_checkout` setting.
18
+ * When running `db:migrate` on a fresh database, load the database schema before running migrations.
822
19
 
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.
20
+ *Andrew Novoselac*
833
21
 
834
- *Jean Boussier*
22
+ * Fix an issue where `.left_outer_joins` used with multiple associations that have
23
+ the same child association but different parents does not join all parents.
835
24
 
836
- * Add dirties option to uncached.
25
+ Previously, using `.left_outer_joins` with the same child association would only join one of the parents.
837
26
 
838
- This adds a `dirties` option to `ActiveRecord::Base.uncached` and
839
- `ActiveRecord::ConnectionAdapters::ConnectionPool#uncached`.
27
+ Now it will correctly join both parents.
840
28
 
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.
29
+ Fixes #41498.
843
30
 
844
- This is needed by Solid Cache so that cache writes do not clear query caches.
31
+ *Garrett Blehm*
845
32
 
846
- *Donal McBreen*
33
+ * Deprecate `unsigned_float` and `unsigned_decimal` short-hand column methods.
847
34
 
848
- * Deprecate `ActiveRecord::Base.connection` in favor of `.lease_connection`.
35
+ As of MySQL 8.0.17, the UNSIGNED attribute is deprecated for columns of type FLOAT, DOUBLE,
36
+ and DECIMAL. Consider using a simple CHECK constraint instead for such columns.
849
37
 
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.
38
+ https://dev.mysql.com/doc/refman/8.0/en/numeric-type-syntax.html
852
39
 
853
- This deprecation is a soft deprecation, no warnings will be issued and there is no
854
- current plan to remove the method.
40
+ *Ryuta Kamizono*
855
41
 
856
- *Jean Boussier*
42
+ * Drop MySQL 5.5 support.
857
43
 
858
- * Deprecate `ActiveRecord::ConnectionAdapters::ConnectionPool#connection`.
44
+ MySQL 5.5 is the only version that does not support datetime with precision,
45
+ which we have supported in the core. Now we support MySQL 5.6.4 or later, which
46
+ is the first version to support datetime with precision.
859
47
 
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.
48
+ *Ryuta Kamizono*
862
49
 
863
- *Jean Boussier*
50
+ * Make Active Record asynchronous queries compatible with transactional fixtures.
864
51
 
865
- * Expose a generic fixture accessor for fixture names that may conflict with Minitest.
52
+ Previously transactional fixtures would disable asynchronous queries, because transactional
53
+ fixtures impose all queries use the same connection.
866
54
 
867
- ```ruby
868
- assert_equal "Ruby on Rails", web_sites(:rubyonrails).name
869
- assert_equal "Ruby on Rails", fixture(:web_sites, :rubyonrails).name
870
- ```
55
+ Now asynchronous queries will use the connection pinned by transactional fixtures, and behave
56
+ much closer to production.
871
57
 
872
58
  *Jean Boussier*
873
59
 
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!`.
60
+ * Deserialize binary data before decrypting
1000
61
 
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.
62
+ This ensures that we call `PG::Connection.unescape_bytea` on PostgreSQL before decryption.
1021
63
 
1022
64
  *Donal McBreen*
1023
65
 
1024
- * Add support for encrypting binary columns.
1025
-
1026
- Ensure encryption and decryption pass `Type::Binary::Data` around for binary data.
66
+ * Ensure `ActiveRecord::Encryption.config` is always ready before access.
1027
67
 
1028
- Previously encrypting binary columns with the `ActiveRecord::Encryption::MessageSerializer`
1029
- incidentally worked for MySQL and SQLite, but not PostgreSQL.
68
+ Previously, `ActiveRecord::Encryption` configuration was deferred until `ActiveRecord::Base`
69
+ was loaded. Therefore, accessing `ActiveRecord::Encryption.config` properties before
70
+ `ActiveRecord::Base` was loaded would give incorrect results.
1030
71
 
1031
- *Donal McBreen*
72
+ `ActiveRecord::Encryption` now has its own loading hook so that its configuration is set as
73
+ soon as needed.
1032
74
 
1033
- * Deprecated `ENV["SCHEMA_CACHE"]` in favor of `schema_cache_path` in the database configuration.
75
+ When `ActiveRecord::Base` is loaded, even lazily, it in turn triggers the loading of
76
+ `ActiveRecord::Encryption`, thus preserving the original behavior of having its config ready
77
+ before any use of `ActiveRecord::Base`.
1034
78
 
1035
- *Rafael Mendonça França*
79
+ *Maxime Réty*
1036
80
 
1037
- * Add `ActiveRecord::Base.with_connection` as a shortcut for leasing a connection for a short duration.
81
+ * Add `TimeZoneConverter#==` method, so objects will be properly compared by
82
+ their type, scale, limit & precision.
1038
83
 
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.
84
+ Address #52699.
1041
85
 
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.
86
+ *Ruy Rocha*
1044
87
 
1045
- *Jean Boussier*
88
+ * Add support for SQLite3 full-text-search and other virtual tables.
1046
89
 
1047
- * Deprecate `config.active_record.warn_on_records_fetched_greater_than` now that `sql.active_record`
1048
- notification includes `:row_count` field.
90
+ Previously, adding sqlite3 virtual tables messed up `schema.rb`.
1049
91
 
1050
- *Jason Nochlin*
92
+ Now, virtual tables can safely be added using `create_virtual_table`.
1051
93
 
1052
- * Fix an issue with `where.associated` losing the current join type scope.
94
+ *Zacharias Knudsen*
1053
95
 
1054
- Example:
96
+ * Support use of alternative database interfaces via the `database_cli` ActiveRecord configuration option.
1055
97
 
1056
98
  ```ruby
1057
- Post.left_joins(:author).where.associated(:author)
99
+ Rails.application.configure do
100
+ config.active_record.database_cli = { postgresql: "pgcli" }
101
+ end
1058
102
  ```
1059
103
 
1060
- Previously, the `LEFT OUTER JOIN` would be lost and converted to an `INNER JOIN`.
104
+ *T S Vallender*
1061
105
 
1062
- *Saleh Alhaddad*
106
+ * Add support for dumping table inheritance and native partitioning table definitions for PostgeSQL adapter
1063
107
 
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.
108
+ *Justin Talbott*
1067
109
 
1068
- *Maxime Réty*
110
+ * Add support for `ActiveRecord::Point` type casts using `Hash` values
1069
111
 
1070
- * Deprecate defining an `enum` with keyword arguments.
112
+ This allows `ActiveRecord::Point` to be cast or serialized from a hash
113
+ with `:x` and `:y` keys of numeric values, mirroring the functionality of
114
+ existing casts for string and array values. Both string and symbol keys are
115
+ supported.
1071
116
 
1072
117
  ```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]
118
+ class PostgresqlPoint < ActiveRecord::Base
119
+ attribute :x, :point
120
+ attribute :y, :point
121
+ attribute :z, :point
1081
122
  end
123
+
124
+ val = PostgresqlPoint.new({
125
+ x: '(12.34, -43.21)',
126
+ y: [12.34, '-43.21'],
127
+ z: {x: '12.34', y: -43.21}
128
+ })
129
+ ActiveRecord::Point.new(12.32, -43.21) == val.x == val.y == val.z
1082
130
  ```
1083
131
 
1084
- *Hartley McGuire*
132
+ *Stephen Drew*
1085
133
 
1086
- * Add `config.active_record.validate_migration_timestamps` option for validating migration timestamps.
134
+ * Replace `SQLite3::Database#busy_timeout` with `#busy_handler_timeout=`.
1087
135
 
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.
136
+ Provides a non-GVL-blocking, fair retry interval busy handler implementation.
1092
137
 
1093
- *Adrianna Chang*
138
+ *Stephen Margheim*
1094
139
 
1095
- * Properly synchronize `Mysql2Adapter#active?` and `TrilogyAdapter#active?`.
140
+ * SQLite3Adapter: Translate `SQLite3::BusyException` into `ActiveRecord::StatementTimeout`.
1096
141
 
1097
- As well as `disconnect!` and `verify!`.
142
+ *Matthew Nguyen*
1098
143
 
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.
144
+ * Include schema name in `enable_extension` statements in `db/schema.rb`.
1102
145
 
1103
- *Jean Boussier*
146
+ The schema dumper will now include the schema name in generated
147
+ `enable_extension` statements if they differ from the current schema.
1104
148
 
1105
- * Support `:source_location` tag option for query log tags.
149
+ For example, if you have a migration:
1106
150
 
1107
151
  ```ruby
1108
- config.active_record.query_log_tags << :source_location
152
+ enable_extension "heroku_ext.pgcrypto"
153
+ enable_extension "pg_stat_statements"
1109
154
  ```
1110
155
 
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`
156
+ then the generated schema dump will also contain:
1120
157
 
1121
158
  ```ruby
1122
- class User
1123
- encrypts :name, encryptor: ActiveRecord::Encryption::Encryptor.new(compress: false)
1124
- end
159
+ enable_extension "heroku_ext.pgcrypto"
160
+ enable_extension "pg_stat_statements"
1125
161
  ```
1126
162
 
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.
163
+ *Tony Novak*
1175
164
 
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*
165
+ * Fix `ActiveRecord::Encryption::EncryptedAttributeType#type` to return
166
+ actual cast type.
1180
167
 
1181
- * Introduce `ActiveRecord::Transactions::ClassMethods#set_callback`.
168
+ *Vasiliy Ermolovich*
1182
169
 
1183
- It is identical to `ActiveSupport::Callbacks::ClassMethods#set_callback`
1184
- but with support for `after_commit` and `after_rollback` callback options.
170
+ * SQLite3Adapter: Bulk insert fixtures.
1185
171
 
1186
- *Joshua Young*
172
+ Previously one insert command was executed for each fixture, now they are
173
+ aggregated in a single bulk insert command.
1187
174
 
1188
- * Make `ActiveRecord::Encryption::Encryptor` agnostic of the serialization format used for encrypted data.
175
+ *Lázaro Nixon*
1189
176
 
1190
- Previously, the encryptor instance only allowed an encrypted value serialized as a `String` to be passed to the message serializer.
177
+ * PostgreSQLAdapter: Allow `disable_extension` to be called with schema-qualified name.
1191
178
 
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`.
179
+ For parity with `enable_extension`, the `disable_extension` method can be called with a schema-qualified
180
+ name (e.g. `disable_extension "myschema.pgcrypto"`). Note that PostgreSQL's `DROP EXTENSION` does not
181
+ actually take a schema name (unlike `CREATE EXTENSION`), so the resulting SQL statement will only name
182
+ the extension, e.g. `DROP EXTENSION IF EXISTS "pgcrypto"`.
1193
183
 
1194
- The default `ActiveRecord::Encryption::MessageSerializer` already ensures that only `String` objects are passed for deserialization.
184
+ *Tony Novak*
1195
185
 
1196
- *Maxime Réty*
186
+ * Make `create_schema` / `drop_schema` reversible in migrations.
1197
187
 
1198
- * Fix `encrypted_attribute?` to take into account context properties passed to `encrypts`.
188
+ Previously, `create_schema` and `drop_schema` were irreversible migration operations.
1199
189
 
1200
- *Maxime Réty*
190
+ *Tony Novak*
1201
191
 
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:
192
+ * Support batching using custom columns.
1205
193
 
1206
194
  ```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
- # ...
195
+ Product.in_batches(cursor: [:shop_id, :id]) do |relation|
196
+ # do something with relation
197
+ end
1214
198
  ```
1215
199
 
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`.
200
+ *fatkodima*
1224
201
 
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.
202
+ * Use SQLite `IMMEDIATE` transactions when possible.
1228
203
 
1229
- ```yaml
1230
- database: storage/development.sqlite3
1231
- timeout: 5000
1232
- pragmas:
1233
- journal_mode: off
1234
- temp_store: memory
1235
- ```
204
+ Transactions run against the SQLite3 adapter default to IMMEDIATE mode to improve concurrency support and avoid busy exceptions.
1236
205
 
1237
206
  *Stephen Margheim*
1238
207
 
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*
208
+ * Raise specific exception when a connection is not defined.
1247
209
 
1248
- * Add support for generated columns to the SQLite3 adapter.
210
+ The new `ConnectionNotDefined` exception provides connection name, shard and role accessors indicating the details of the connection that was requested.
1249
211
 
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.
212
+ *Hana Harencarova*, *Matthew Draper*
1252
213
 
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*
214
+ * Delete the deprecated constant `ActiveRecord::ImmutableRelation`.
1262
215
 
1263
- * TrilogyAdapter: ignore `host` if `socket` parameter is set.
216
+ *Xavier Noria*
1264
217
 
1265
- This allows to configure a connection on a UNIX socket via `DATABASE_URL`:
218
+ * Fix duplicate callback execution when child autosaves parent with `has_one` and `belongs_to`.
1266
219
 
1267
- ```
1268
- DATABASE_URL=trilogy://does-not-matter/my_db_production?socket=/var/run/mysql.sock
1269
- ```
220
+ Before, persisting a new child record with a new associated parent record would run `before_validation`,
221
+ `after_validation`, `before_save` and `after_save` callbacks twice.
1270
222
 
1271
- *Jean Boussier*
223
+ Now, these callbacks are only executed once as expected.
1272
224
 
1273
- * Make `assert_queries_count`, `assert_no_queries`, `assert_queries_match`, and
1274
- `assert_no_queries_match` assertions public.
225
+ *Joshua Young*
1275
226
 
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.
227
+ * `ActiveRecord::Encryption::Encryptor` now supports a `:compressor` option to customize the compression algorithm used.
1279
228
 
1280
229
  ```ruby
1281
- class ArticleTest < ActiveSupport::TestCase
1282
- test "queries are made" do
1283
- assert_queries_count(1) { Article.first }
230
+ module ZstdCompressor
231
+ def self.deflate(data)
232
+ Zstd.compress(data)
1284
233
  end
1285
234
 
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
235
+ def self.inflate(data)
236
+ Zstd.decompress(data)
1290
237
  end
1291
238
  end
1292
- ```
1293
-
1294
- *Petrik de Heus*, *fatkodima*
1295
239
 
1296
- * Fix `has_secure_token` calls the setter method on initialize.
1297
-
1298
- *Abeid Ahmed*
240
+ class User
241
+ encrypts :name, compressor: ZstdCompressor
242
+ end
243
+ ```
1299
244
 
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.
245
+ You disable compression by passing `compress: false`.
1303
246
 
1304
247
  ```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
248
+ class User
249
+ encrypts :name, compress: false
250
+ end
1308
251
  ```
1309
252
 
1310
- *Jean Boussier*, *Kevin McPhillips*
253
+ *heka1024*
1311
254
 
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).
255
+ * Add condensed `#inspect` for `ConnectionPool`, `AbstractAdapter`, and
256
+ `DatabaseConfig`.
1315
257
 
1316
- *Kevin McPhillips*
258
+ *Hartley McGuire*
1317
259
 
1318
- * `DatabaseConfigurations#configs_for` accepts a symbol in the `name` parameter.
260
+ * Add `.shard_keys`, `.sharded?`, & `.connected_to_all_shards` methods.
1319
261
 
1320
- *Andrew Novoselac*
262
+ ```ruby
263
+ class ShardedBase < ActiveRecord::Base
264
+ self.abstract_class = true
1321
265
 
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).
266
+ connects_to shards: {
267
+ shard_one: { writing: :shard_one },
268
+ shard_two: { writing: :shard_two }
269
+ }
270
+ end
1325
271
 
1326
- *João Alves*
272
+ class ShardedModel < ShardedBase
273
+ end
1327
274
 
1328
- * Make the output of `ActiveRecord::Core#inspect` configurable.
275
+ ShardedModel.shard_keys => [:shard_one, :shard_two]
276
+ ShardedModel.sharded? => true
277
+ ShardedBase.connected_to_all_shards { ShardedModel.current_shard } => [:shard_one, :shard_two]
278
+ ```
1329
279
 
1330
- By default, calling `inspect` on a record will yield a formatted string including just the `id`.
280
+ *Nony Dutton*
1331
281
 
1332
- ```ruby
1333
- Post.first.inspect #=> "#<Post id: 1>"
1334
- ```
282
+ * Add a `filter` option to `in_order_of` to prioritize certain values in the sorting without filtering the results
283
+ by these values.
1335
284
 
1336
- The attributes to be included in the output of `inspect` can be configured with
1337
- `ActiveRecord::Core#attributes_for_inspect`.
285
+ *Igor Depolli*
1338
286
 
1339
- ```ruby
1340
- Post.attributes_for_inspect = [:id, :title]
1341
- Post.first.inspect #=> "#<Post id: 1, title: "Hello, World!">"
1342
- ```
287
+ * Fix an issue where the IDs reader method did not return expected results
288
+ for preloaded associations in models using composite primary keys.
1343
289
 
1344
- With `attributes_for_inspect` set to `:all`, `inspect` will list all the record's attributes.
290
+ *Jay Ang*
1345
291
 
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
- ```
292
+ * Allow to configure `strict_loading_mode` globally or within a model.
1350
293
 
1351
- In `development` and `test` mode, `attributes_for_inspect` will be set to `:all` by default.
294
+ Defaults to `:all`, can be changed to `:n_plus_one_only`.
1352
295
 
1353
- You can also call `full_inspect` to get an inspection with all the attributes.
296
+ *Garen Torikian*
1354
297
 
1355
- The attributes in `attribute_for_inspect` will also be used for `pretty_print`.
298
+ * Add `ActiveRecord::Relation#readonly?`.
1356
299
 
1357
- *Andrew Novoselac*
300
+ Reflects if the relation has been marked as readonly.
1358
301
 
1359
- * Don't mark attributes as changed when reassigned to `Float::INFINITY` or
1360
- `-Float::INFINITY`.
302
+ *Theodor Tonum*
1361
303
 
1362
- *Maicol Bentancor*
304
+ * Improve `ActiveRecord::Store` to raise a descriptive exception if the column is not either
305
+ structured (e.g., PostgreSQL +hstore+/+json+, or MySQL +json+) or declared serializable via
306
+ `ActiveRecord.store`.
1363
307
 
1364
- * Support the `RETURNING` clause for MariaDB.
308
+ Previously, a `NoMethodError` would be raised when the accessor was read or written:
1365
309
 
1366
- *fatkodima*, *Nikolay Kondratyev*
310
+ NoMethodError: undefined method `accessor' for an instance of ActiveRecord::Type::Text
1367
311
 
1368
- * The SQLite3 adapter now implements the `supports_deferrable_constraints?` contract.
312
+ Now, a descriptive `ConfigurationError` is raised:
1369
313
 
1370
- Allows foreign keys to be deferred by adding the `:deferrable` key to the `foreign_key` options.
314
+ ActiveRecord::ConfigurationError: the column 'metadata' has not been configured as a store.
315
+ Please make sure the column is declared serializable via 'ActiveRecord.store' or, if your
316
+ database supports it, use a structured column type like hstore or json.
1371
317
 
1372
- ```ruby
1373
- add_reference :person, :alias, foreign_key: { deferrable: :deferred }
1374
- add_reference :alias, :person, foreign_key: { deferrable: :deferred }
1375
- ```
318
+ *Mike Dalessio*
1376
319
 
1377
- *Stephen Margheim*
320
+ * Fix inference of association model on nested models with the same demodularized name.
1378
321
 
1379
- * Add the `set_constraints` helper to PostgreSQL connections.
322
+ E.g. with the following setup:
1380
323
 
1381
324
  ```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!
325
+ class Nested::Post < ApplicationRecord
326
+ has_one :post, through: :other
1390
327
  end
1391
328
  ```
1392
329
 
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*
330
+ Before, `#post` would infer the model as `Nested::Post`, but now it correctly infers `Post`.
1402
331
 
1403
- * Add `nulls_last` and working `desc.nulls_first` for MySQL.
332
+ *Joshua Young*
1404
333
 
1405
- *Tristan Fellows*
334
+ * Add public method for checking if a table is ignored by the schema cache.
1406
335
 
1407
- * Allow for more complex hash arguments for `order` which mimics `where` in `ActiveRecord::Relation`.
336
+ 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
337
 
1409
338
  ```ruby
1410
- Topic.includes(:posts).order(posts: { created_at: :desc })
339
+ ActiveRecord.schema_cache_ignored_tables = ["developers"]
340
+ ActiveRecord.schema_cache_ignored_table?("developers")
341
+ => true
1411
342
  ```
1412
343
 
1413
- *Myles Boone*
344
+ *Eileen M. Uchitelle*
1414
345
 
1415
- Please check [7-1-stable](https://github.com/rails/rails/blob/7-1-stable/activerecord/CHANGELOG.md) for previous changes.
346
+ Please check [7-2-stable](https://github.com/rails/rails/blob/7-2-stable/activerecord/CHANGELOG.md) for previous changes.