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