activerecord 8.0.3 → 8.1.0.rc1

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 (160) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +520 -514
  3. data/README.rdoc +1 -1
  4. data/lib/active_record/association_relation.rb +1 -1
  5. data/lib/active_record/associations/association.rb +1 -1
  6. data/lib/active_record/associations/belongs_to_association.rb +2 -0
  7. data/lib/active_record/associations/builder/association.rb +16 -5
  8. data/lib/active_record/associations/builder/belongs_to.rb +17 -4
  9. data/lib/active_record/associations/builder/collection_association.rb +7 -3
  10. data/lib/active_record/associations/builder/has_one.rb +1 -1
  11. data/lib/active_record/associations/builder/singular_association.rb +33 -5
  12. data/lib/active_record/associations/collection_proxy.rb +22 -4
  13. data/lib/active_record/associations/deprecation.rb +88 -0
  14. data/lib/active_record/associations/errors.rb +3 -0
  15. data/lib/active_record/associations/join_dependency.rb +2 -0
  16. data/lib/active_record/associations/preloader/branch.rb +1 -0
  17. data/lib/active_record/associations.rb +159 -21
  18. data/lib/active_record/attribute_methods/serialization.rb +16 -3
  19. data/lib/active_record/attribute_methods/time_zone_conversion.rb +10 -2
  20. data/lib/active_record/attributes.rb +3 -0
  21. data/lib/active_record/autosave_association.rb +1 -1
  22. data/lib/active_record/base.rb +0 -2
  23. data/lib/active_record/coders/json.rb +14 -5
  24. data/lib/active_record/connection_adapters/abstract/connection_handler.rb +1 -3
  25. data/lib/active_record/connection_adapters/abstract/connection_pool/queue.rb +16 -3
  26. data/lib/active_record/connection_adapters/abstract/connection_pool/reaper.rb +51 -12
  27. data/lib/active_record/connection_adapters/abstract/connection_pool.rb +405 -72
  28. data/lib/active_record/connection_adapters/abstract/database_statements.rb +55 -40
  29. data/lib/active_record/connection_adapters/abstract/query_cache.rb +19 -3
  30. data/lib/active_record/connection_adapters/abstract/quoting.rb +15 -24
  31. data/lib/active_record/connection_adapters/abstract/schema_creation.rb +7 -2
  32. data/lib/active_record/connection_adapters/abstract/schema_definitions.rb +26 -34
  33. data/lib/active_record/connection_adapters/abstract/schema_dumper.rb +2 -1
  34. data/lib/active_record/connection_adapters/abstract/schema_statements.rb +85 -22
  35. data/lib/active_record/connection_adapters/abstract/transaction.rb +25 -3
  36. data/lib/active_record/connection_adapters/abstract_adapter.rb +86 -20
  37. data/lib/active_record/connection_adapters/abstract_mysql_adapter.rb +43 -13
  38. data/lib/active_record/connection_adapters/column.rb +17 -4
  39. data/lib/active_record/connection_adapters/mysql/database_statements.rb +4 -4
  40. data/lib/active_record/connection_adapters/mysql/schema_creation.rb +2 -0
  41. data/lib/active_record/connection_adapters/mysql/schema_definitions.rb +42 -5
  42. data/lib/active_record/connection_adapters/mysql/schema_statements.rb +26 -4
  43. data/lib/active_record/connection_adapters/mysql2/database_statements.rb +27 -22
  44. data/lib/active_record/connection_adapters/mysql2_adapter.rb +1 -2
  45. data/lib/active_record/connection_adapters/postgresql/column.rb +4 -0
  46. data/lib/active_record/connection_adapters/postgresql/database_statements.rb +17 -15
  47. data/lib/active_record/connection_adapters/postgresql/oid/array.rb +2 -2
  48. data/lib/active_record/connection_adapters/postgresql/oid/type_map_initializer.rb +1 -1
  49. data/lib/active_record/connection_adapters/postgresql/quoting.rb +21 -10
  50. data/lib/active_record/connection_adapters/postgresql/schema_creation.rb +8 -6
  51. data/lib/active_record/connection_adapters/postgresql/schema_definitions.rb +8 -21
  52. data/lib/active_record/connection_adapters/postgresql/schema_dumper.rb +66 -31
  53. data/lib/active_record/connection_adapters/postgresql/schema_statements.rb +81 -48
  54. data/lib/active_record/connection_adapters/postgresql_adapter.rb +23 -7
  55. data/lib/active_record/connection_adapters/schema_cache.rb +2 -2
  56. data/lib/active_record/connection_adapters/sqlite3/database_statements.rb +37 -25
  57. data/lib/active_record/connection_adapters/sqlite3/quoting.rb +0 -8
  58. data/lib/active_record/connection_adapters/sqlite3/schema_statements.rb +4 -13
  59. data/lib/active_record/connection_adapters/sqlite3_adapter.rb +54 -30
  60. data/lib/active_record/connection_adapters/trilogy/database_statements.rb +4 -3
  61. data/lib/active_record/connection_adapters/trilogy_adapter.rb +1 -1
  62. data/lib/active_record/connection_adapters.rb +1 -0
  63. data/lib/active_record/connection_handling.rb +2 -1
  64. data/lib/active_record/core.rb +5 -4
  65. data/lib/active_record/counter_cache.rb +33 -8
  66. data/lib/active_record/database_configurations/database_config.rb +5 -1
  67. data/lib/active_record/database_configurations/hash_config.rb +53 -9
  68. data/lib/active_record/database_configurations/url_config.rb +13 -3
  69. data/lib/active_record/database_configurations.rb +7 -3
  70. data/lib/active_record/delegated_type.rb +1 -1
  71. data/lib/active_record/dynamic_matchers.rb +54 -69
  72. data/lib/active_record/encryption/encryptable_record.rb +4 -4
  73. data/lib/active_record/encryption/encrypted_attribute_type.rb +1 -1
  74. data/lib/active_record/encryption/encryptor.rb +12 -0
  75. data/lib/active_record/encryption/scheme.rb +1 -1
  76. data/lib/active_record/enum.rb +24 -8
  77. data/lib/active_record/errors.rb +20 -4
  78. data/lib/active_record/explain.rb +1 -1
  79. data/lib/active_record/explain_registry.rb +51 -2
  80. data/lib/active_record/filter_attribute_handler.rb +73 -0
  81. data/lib/active_record/fixtures.rb +2 -2
  82. data/lib/active_record/gem_version.rb +3 -3
  83. data/lib/active_record/inheritance.rb +1 -1
  84. data/lib/active_record/insert_all.rb +12 -7
  85. data/lib/active_record/locking/optimistic.rb +7 -0
  86. data/lib/active_record/locking/pessimistic.rb +5 -0
  87. data/lib/active_record/log_subscriber.rb +2 -6
  88. data/lib/active_record/middleware/shard_selector.rb +34 -17
  89. data/lib/active_record/migration/command_recorder.rb +14 -1
  90. data/lib/active_record/migration/compatibility.rb +34 -24
  91. data/lib/active_record/migration/default_schema_versions_formatter.rb +30 -0
  92. data/lib/active_record/migration.rb +26 -16
  93. data/lib/active_record/model_schema.rb +36 -10
  94. data/lib/active_record/nested_attributes.rb +2 -0
  95. data/lib/active_record/persistence.rb +34 -3
  96. data/lib/active_record/query_cache.rb +22 -15
  97. data/lib/active_record/query_logs.rb +3 -7
  98. data/lib/active_record/railtie.rb +32 -3
  99. data/lib/active_record/railties/controller_runtime.rb +11 -6
  100. data/lib/active_record/railties/databases.rake +15 -3
  101. data/lib/active_record/railties/job_checkpoints.rb +15 -0
  102. data/lib/active_record/railties/job_runtime.rb +10 -11
  103. data/lib/active_record/reflection.rb +42 -3
  104. data/lib/active_record/relation/batches.rb +25 -11
  105. data/lib/active_record/relation/calculations.rb +20 -9
  106. data/lib/active_record/relation/delegation.rb +0 -1
  107. data/lib/active_record/relation/finder_methods.rb +27 -11
  108. data/lib/active_record/relation/predicate_builder/association_query_value.rb +9 -9
  109. data/lib/active_record/relation/predicate_builder/polymorphic_array_value.rb +7 -7
  110. data/lib/active_record/relation/predicate_builder.rb +9 -7
  111. data/lib/active_record/relation/query_attribute.rb +3 -1
  112. data/lib/active_record/relation/query_methods.rb +38 -28
  113. data/lib/active_record/relation/where_clause.rb +1 -8
  114. data/lib/active_record/relation.rb +24 -12
  115. data/lib/active_record/result.rb +44 -21
  116. data/lib/active_record/runtime_registry.rb +41 -58
  117. data/lib/active_record/sanitization.rb +2 -0
  118. data/lib/active_record/schema_dumper.rb +12 -10
  119. data/lib/active_record/scoping.rb +0 -1
  120. data/lib/active_record/signed_id.rb +43 -15
  121. data/lib/active_record/statement_cache.rb +13 -9
  122. data/lib/active_record/store.rb +44 -19
  123. data/lib/active_record/structured_event_subscriber.rb +85 -0
  124. data/lib/active_record/table_metadata.rb +5 -20
  125. data/lib/active_record/tasks/abstract_tasks.rb +76 -0
  126. data/lib/active_record/tasks/database_tasks.rb +25 -34
  127. data/lib/active_record/tasks/mysql_database_tasks.rb +3 -40
  128. data/lib/active_record/tasks/postgresql_database_tasks.rb +5 -39
  129. data/lib/active_record/tasks/sqlite_database_tasks.rb +14 -26
  130. data/lib/active_record/test_databases.rb +14 -4
  131. data/lib/active_record/test_fixtures.rb +27 -2
  132. data/lib/active_record/testing/query_assertions.rb +8 -2
  133. data/lib/active_record/timestamp.rb +4 -2
  134. data/lib/active_record/transaction.rb +2 -5
  135. data/lib/active_record/transactions.rb +32 -10
  136. data/lib/active_record/type/hash_lookup_type_map.rb +2 -1
  137. data/lib/active_record/type/internal/timezone.rb +7 -0
  138. data/lib/active_record/type/json.rb +15 -2
  139. data/lib/active_record/type/serialized.rb +11 -4
  140. data/lib/active_record/type/type_map.rb +1 -1
  141. data/lib/active_record/type_caster/connection.rb +2 -1
  142. data/lib/active_record/validations/associated.rb +1 -1
  143. data/lib/active_record.rb +65 -3
  144. data/lib/arel/alias_predication.rb +2 -0
  145. data/lib/arel/crud.rb +6 -11
  146. data/lib/arel/nodes/count.rb +2 -2
  147. data/lib/arel/nodes/function.rb +4 -10
  148. data/lib/arel/nodes/named_function.rb +2 -2
  149. data/lib/arel/nodes/node.rb +1 -1
  150. data/lib/arel/nodes.rb +0 -2
  151. data/lib/arel/select_manager.rb +7 -2
  152. data/lib/arel/visitors/dot.rb +0 -3
  153. data/lib/arel/visitors/postgresql.rb +55 -0
  154. data/lib/arel/visitors/sqlite.rb +55 -8
  155. data/lib/arel/visitors/to_sql.rb +3 -21
  156. data/lib/arel.rb +3 -1
  157. data/lib/rails/generators/active_record/application_record/USAGE +1 -1
  158. metadata +14 -10
  159. data/lib/active_record/explain_subscriber.rb +0 -34
  160. data/lib/active_record/normalization.rb +0 -163
data/CHANGELOG.md CHANGED
@@ -1,4 +1,78 @@
1
- ## Rails 8.0.3 (September 22, 2025) ##
1
+ ## Rails 8.1.0.rc1 (October 15, 2025) ##
2
+
3
+ * Add replicas to test database parallelization setup.
4
+
5
+ Setup and configuration of databases for parallel testing now includes replicas.
6
+
7
+ This fixes an issue when using a replica database, database selector middleware,
8
+ and non-transactional tests, where integration tests running in parallel would select
9
+ the base test database, i.e. `db_test`, instead of the numbered parallel worker database,
10
+ i.e. `db_test_{n}`.
11
+
12
+ *Adam Maas*
13
+
14
+ * Support virtual (not persisted) generated columns on PostgreSQL 18+
15
+
16
+ PostgreSQL 18 introduces virtual (not persisted) generated columns,
17
+ which are now the default unless the `stored: true` option is explicitly specified on PostgreSQL 18+.
18
+
19
+ ```ruby
20
+ create_table :users do |t|
21
+ t.string :name
22
+ t.virtual :lower_name, type: :string, as: "LOWER(name)", stored: false
23
+ t.virtual :name_length, type: :integer, as: "LENGTH(name)"
24
+ end
25
+ ```
26
+
27
+ *Yasuo Honda*
28
+
29
+ * Optimize schema dumping to prevent duplicate file generation.
30
+
31
+ `ActiveRecord::Tasks::DatabaseTasks.dump_all` now tracks which schema files
32
+ have already been dumped and skips dumping the same file multiple times.
33
+ This improves performance when multiple database configurations share the
34
+ same schema dump path.
35
+
36
+ *Mikey Gough*, *Hartley McGuire*
37
+
38
+ * Add structured events for Active Record:
39
+ - `active_record.strict_loading_violation`
40
+ - `active_record.sql`
41
+
42
+ *Gannon McGibbon*
43
+
44
+ * Add support for integer shard keys.
45
+ ```ruby
46
+ # Now accepts symbols as shard keys.
47
+ ActiveRecord::Base.connects_to(shards: {
48
+ 1: { writing: :primary_shard_one, reading: :primary_shard_one },
49
+ 2: { writing: :primary_shard_two, reading: :primary_shard_two},
50
+ })
51
+
52
+ ActiveRecord::Base.connected_to(shard: 1) do
53
+ # ..
54
+ end
55
+ ```
56
+
57
+ *Nony Dutton*
58
+
59
+ * Add `ActiveRecord::Base.only_columns`
60
+
61
+ Similar in use case to `ignored_columns` but listing columns to consider rather than the ones
62
+ to ignore.
63
+
64
+ Can be useful when working with a legacy or shared database schema, or to make safe schema change
65
+ in two deploys rather than three.
66
+
67
+ *Anton Kandratski*
68
+
69
+ * Use `PG::Connection#close_prepared` (protocol level Close) to deallocate
70
+ prepared statements when available.
71
+
72
+ To enable its use, you must have pg >= 1.6.0, libpq >= 17, and a PostgreSQL
73
+ database version >= 17.
74
+
75
+ *Hartley McGuire*, *Andrew Jackson*
2
76
 
3
77
  * Fix query cache for pinned connections in multi threaded transactional tests
4
78
 
@@ -9,16 +83,15 @@
9
83
 
10
84
  *Heinrich Lee Yu*, *Jean Boussier*
11
85
 
12
- * Don't add `id_value` attribute alias when attribute/column with that name already exists.
13
-
14
- *Rob Lewis*
86
+ * Fix time attribute dirty tracking with timezone conversions.
15
87
 
16
- * Fix false positive change detection involving STI and polymorphic has one relationships.
88
+ Time-only attributes now maintain a fixed date of 2000-01-01 during timezone conversions,
89
+ preventing them from being incorrectly marked as changed due to date shifts.
17
90
 
18
- Polymorphic `has_one` relationships would always be considered changed when defined in a STI child
19
- class, causing nedless extra autosaves.
91
+ This fixes an issue where time attributes would be marked as changed when setting the same time value
92
+ due to timezone conversion causing internal date shifts.
20
93
 
21
- *David Fritsch*
94
+ *Prateek Choudhary*
22
95
 
23
96
  * Skip calling `PG::Connection#cancel` in `cancel_any_running_query`
24
97
  when using libpq >= 18 with pg < 1.6.0, due to incompatibility.
@@ -26,28 +99,82 @@
26
99
 
27
100
  *Yasuo Honda*, *Lars Kanis*
28
101
 
29
- * Fix stale association detection for polymorphic `belongs_to`.
102
+ * Don't add `id_value` attribute alias when attribute/column with that name already exists.
30
103
 
31
- *Florent Beaurain*, *Thomas Crambert*
104
+ *Rob Lewis*
32
105
 
33
- * Fix removal of PostgreSQL version comments in `structure.sql` for latest PostgreSQL versions which include `\restrict`
106
+ ## Rails 8.1.0.beta1 (September 04, 2025) ##
34
107
 
35
- *Brendan Weibrecht*
108
+ * Remove deprecated `:unsigned_float` and `:unsigned_decimal` column methods for MySQL.
36
109
 
37
- * Allow setting `schema_format` in database configuration.
110
+ *Rafael Mendonça França*
38
111
 
39
- ```
40
- primary:
41
- schema_format: ruby
42
- ```
112
+ * Remove deprecated `:retries` option for the SQLite3 adapter.
43
113
 
44
- Useful in multi-database setups to have different formats per-database.
114
+ *Rafael Mendonça França*
45
115
 
46
- *T S Vallender*
116
+ * Introduce new database configuration options `keepalive`, `max_age`, and
117
+ `min_connections` -- and rename `pool` to `max_connections` to match.
47
118
 
48
- * Use ntuples to populate row_count instead of count for Postgres
119
+ There are no changes to default behavior, but these allow for more specific
120
+ control over pool behavior.
49
121
 
50
- *Jonathan Calvert*
122
+ *Matthew Draper*, *Chris AtLee*, *Rachael Wright-Munn*
123
+
124
+ * Move `LIMIT` validation from query generation to when `limit()` is called.
125
+
126
+ *Hartley McGuire*, *Shuyang*
127
+
128
+ * Add `ActiveRecord::CheckViolation` error class for check constraint violations.
129
+
130
+ *Ryuta Kamizono*
131
+
132
+ * Add `ActiveRecord::ExclusionViolation` error class for exclusion constraint violations.
133
+
134
+ When an exclusion constraint is violated in PostgreSQL, the error will now be raised
135
+ as `ActiveRecord::ExclusionViolation` instead of the generic `ActiveRecord::StatementInvalid`,
136
+ making it easier to handle these specific constraint violations in application code.
137
+
138
+ This follows the same pattern as other constraint violation error classes like
139
+ `RecordNotUnique` for unique constraint violations and `InvalidForeignKey` for
140
+ foreign key constraint violations.
141
+
142
+ *Ryuta Kamizono*
143
+
144
+ * Attributes filtered by `filter_attributes` will now also be filtered by `filter_parameters`
145
+ so sensitive information is not leaked.
146
+
147
+ *Jill Klang*
148
+
149
+ * Add `connection.current_transaction.isolation` API to check current transaction's isolation level.
150
+
151
+ Returns the isolation level if it was explicitly set via the `isolation:` parameter
152
+ or through `ActiveRecord.with_transaction_isolation_level`, otherwise returns `nil`.
153
+ Nested transactions return the parent transaction's isolation level.
154
+
155
+ ```ruby
156
+ # Returns nil when no transaction
157
+ User.connection.current_transaction.isolation # => nil
158
+
159
+ # Returns explicitly set isolation level
160
+ User.transaction(isolation: :serializable) do
161
+ User.connection.current_transaction.isolation # => :serializable
162
+ end
163
+
164
+ # Returns nil when isolation not explicitly set
165
+ User.transaction do
166
+ User.connection.current_transaction.isolation # => nil
167
+ end
168
+
169
+ # Nested transactions inherit parent's isolation
170
+ User.transaction(isolation: :read_committed) do
171
+ User.transaction do
172
+ User.connection.current_transaction.isolation # => :read_committed
173
+ end
174
+ end
175
+ ```
176
+
177
+ *Kir Shatrov*
51
178
 
52
179
  * Fix `#merge` with `#or` or `#and` and a mixture of attributes and SQL strings resulting in an incorrect query.
53
180
 
@@ -87,722 +214,601 @@
87
214
 
88
215
  *Joshua Young*
89
216
 
90
- * Fix inline `has_and_belongs_to_many` fixtures for tables with composite primary keys.
91
-
92
- *fatkodima*
93
-
94
- * Fix migration log message for down operations.
95
-
96
- *Bernardo Barreto*
97
-
98
- * Prepend `extra_flags` in postgres' `structure_load`
99
-
100
- When specifying `structure_load_flags` with a postgres adapter, the flags
101
- were appended to the default flags, instead of prepended.
102
- This caused issues with flags not being taken into account by postgres.
103
-
104
- *Alice Loeser*
105
-
106
- * Fix `annotate` comments to propagate to `update_all`/`delete_all`.
217
+ * Make schema dumper to account for `ActiveRecord.dump_schemas` when dumping in `:ruby` format.
107
218
 
108
219
  *fatkodima*
109
220
 
110
- * Fix checking whether an unpersisted record is `include?`d in a strictly
111
- loaded `has_and_belongs_to_many` association.
112
-
113
- *Hartley McGuire*
114
-
115
- * `create_or_find_by` will now correctly rollback a transaction.
116
-
117
- When using `create_or_find_by`, raising a ActiveRecord::Rollback error
118
- in a `after_save` callback had no effect, the transaction was committed
119
- and a record created.
120
-
121
- *Edouard Chin*
122
-
123
- * Gracefully handle `Timeout.timeout` firing during connection configuration.
124
-
125
- Use of `Timeout.timeout` could result in improperly initialized database connection.
126
-
127
- This could lead to a partially configured connection being used, resulting in various exceptions,
128
- the most common being with the PostgreSQLAdapter raising `undefined method 'key?' for nil`
129
- or `TypeError: wrong argument type nil (expected PG::TypeMap)`.
130
-
131
- *Jean Boussier*
132
-
133
- * Fix stale state for composite foreign keys in belongs_to associations.
134
-
135
- *Varun Sharma*
136
-
137
-
138
- ## Rails 8.0.2.1 (August 13, 2025) ##
139
-
140
- * Call inspect on ids in RecordNotFound error
141
-
142
- [CVE-2025-55193]
143
-
144
- *Gannon McGibbon*, *John Hawthorn*
221
+ * Add `:touch` option to `update_column`/`update_columns` methods.
145
222
 
223
+ ```ruby
224
+ # Will update :updated_at/:updated_on alongside :nice column.
225
+ user.update_column(:nice, true, touch: true)
146
226
 
147
- ## Rails 8.0.2 (March 12, 2025) ##
227
+ # Will update :updated_at/:updated_on alongside :last_ip column
228
+ user.update_columns(last_ip: request.remote_ip, touch: true)
229
+ ```
148
230
 
149
- * Fix inverting `rename_enum_value` when `:from`/`:to` are provided.
231
+ *Dmitrii Ivliev*
150
232
 
151
- *fatkodima*
233
+ * Optimize Active Record batching further when using ranges.
152
234
 
153
- * Prevent persisting invalid record.
235
+ Tested on a PostgreSQL table with 10M records and batches of 10k records, the generation
236
+ of relations for the 1000 batches was `4.8x` faster (`6.8s` vs. `1.4s`), used `900x`
237
+ less bandwidth (`180MB` vs. `0.2MB`) and allocated `45x` less memory (`490MB` vs. `11MB`).
154
238
 
155
- *Edouard Chin*
239
+ *Maxime Réty*, *fatkodima*
156
240
 
157
- * Fix inverting `drop_table` without options.
241
+ * Include current character length in error messages for index and table name length validations.
158
242
 
159
- *fatkodima*
160
-
161
- * Fix count with group by qualified name on loaded relation.
243
+ *Joshua Young*
162
244
 
163
- *Ryuta Kamizono*
245
+ * Add `rename_schema` method for PostgreSQL.
164
246
 
165
- * Fix `sum` with qualified name on loaded relation.
247
+ *T S Vallender*
166
248
 
167
- *Chris Gunther*
249
+ * Implement support for deprecating associations:
168
250
 
169
- * The SQLite3 adapter quotes non-finite Numeric values like "Infinity" and "NaN".
251
+ ```ruby
252
+ has_many :posts, deprecated: true
253
+ ```
170
254
 
171
- *Mike Dalessio*
255
+ With that, Active Record will report any usage of the `posts` association.
172
256
 
173
- * Handle libpq returning a database version of 0 on no/bad connection in `PostgreSQLAdapter`.
257
+ Three reporting modes are supported (`:warn`, `:raise`, and `:notify`), and
258
+ backtraces can be enabled or disabled. Defaults are `:warn` mode and
259
+ disabled backtraces.
174
260
 
175
- Before, this version would be cached and an error would be raised during connection configuration when
176
- comparing it with the minimum required version for the adapter. This meant that the connection could
177
- never be successfully configured on subsequent reconnection attempts.
261
+ Please, check the docs for further details.
178
262
 
179
- Now, this is treated as a connection failure consistent with libpq, raising a `ActiveRecord::ConnectionFailed`
180
- and ensuring the version isn't cached, which allows the version to be retrieved on the next connection attempt.
263
+ *Xavier Noria*
181
264
 
182
- *Joshua Young*, *Rian McGuire*
265
+ * PostgreSQL adapter create DB now supports `locale_provider` and `locale`.
183
266
 
184
- * Fix error handling during connection configuration.
267
+ *Bengt-Ove Hollaender*
185
268
 
186
- Active Record wasn't properly handling errors during the connection configuration phase.
187
- This could lead to a partially configured connection being used, resulting in various exceptions,
188
- the most common being with the PostgreSQLAdapter raising `undefined method `key?' for nil`
189
- or `TypeError: wrong argument type nil (expected PG::TypeMap)`.
269
+ * Use ntuples to populate row_count instead of count for Postgres
190
270
 
191
- *Jean Boussier*
271
+ *Jonathan Calvert*
192
272
 
193
- * Fix a case where a non-retryable query could be marked retryable.
273
+ * Fix checking whether an unpersisted record is `include?`d in a strictly
274
+ loaded `has_and_belongs_to_many` association.
194
275
 
195
276
  *Hartley McGuire*
196
277
 
197
- * Handle circular references when autosaving associations.
198
-
199
- *zzak*
200
-
201
- * PoolConfig no longer keeps a reference to the connection class.
278
+ * Add ability to change transaction isolation for all pools within a block.
202
279
 
203
- Keeping a reference to the class caused subtle issues when combined with reloading in
204
- development. Fixes #54343.
280
+ This functionality is useful if your application needs to change the database
281
+ transaction isolation for a request or action.
205
282
 
206
- *Mike Dalessio*
283
+ Calling `ActiveRecord.with_transaction_isolation_level(level) {}` in an around filter or
284
+ middleware will set the transaction isolation for all pools accessed within the block,
285
+ but not for the pools that aren't.
207
286
 
208
- * Fix SQL notifications sometimes not sent when using async queries.
287
+ This works with explicit and implicit transactions:
209
288
 
210
289
  ```ruby
211
- Post.async_count
212
- ActiveSupport::Notifications.subscribed(->(*) { "Will never reach here" }) do
213
- Post.count
290
+ ActiveRecord.with_transaction_isolation_level(:read_committed) do
291
+ Tag.transaction do # opens a transaction explicitly
292
+ Tag.create!
293
+ end
214
294
  end
215
295
  ```
216
296
 
217
- In rare circumstances and under the right race condition, Active Support notifications
218
- would no longer be dispatched after using an asynchronous query.
219
- This is now fixed.
220
-
221
- *Edouard Chin*
222
-
223
- * Fix support for PostgreSQL enum types with commas in their name.
224
-
225
- *Arthur Hess*
226
-
227
- * Fix inserts on MySQL with no RETURNING support for a table with multiple auto populated columns.
228
-
229
- *Nikita Vasilevsky*
230
-
231
- * Fix joining on a scoped association with string joins and bind parameters.
232
-
233
297
  ```ruby
234
- class Instructor < ActiveRecord::Base
235
- has_many :instructor_roles, -> { active }
236
- end
237
-
238
- class InstructorRole < ActiveRecord::Base
239
- scope :active, -> {
240
- joins("JOIN students ON instructor_roles.student_id = students.id")
241
- .where(students { status: 1 })
242
- }
298
+ ActiveRecord.with_transaction_isolation_level(:read_committed) do
299
+ Tag.create! # opens a transaction implicitly
243
300
  end
244
-
245
- Instructor.joins(:instructor_roles).first
246
301
  ```
247
302
 
248
- The above example would result in `ActiveRecord::StatementInvalid` because the
249
- `active` scope bind parameters would be lost.
250
-
251
- *Jean Boussier*
252
-
253
- * Fix a potential race condition with system tests and transactional fixtures.
254
-
255
- *Sjoerd Lagarde*
303
+ *Eileen M. Uchitelle*
256
304
 
257
- * Fix autosave associations to no longer validated unmodified associated records.
305
+ * Raise `ActiveRecord::MissingRequiredOrderError` when order dependent finder methods (e.g. `#first`, `#last`) are
306
+ called without `order` values on the relation, and the model does not have any order columns (`implicit_order_column`,
307
+ `query_constraints`, or `primary_key`) to fall back on.
258
308
 
259
- Active Record was incorrectly performing validation on associated record that
260
- weren't created nor modified as part of the transaction:
309
+ This change will be introduced with a new framework default for Rails 8.1, and the current behavior of not raising
310
+ an error has been deprecated with the aim of removing the configuration option in Rails 8.2.
261
311
 
262
312
  ```ruby
263
- Post.create!(author: User.find(1)) # Fail if user is invalid
313
+ config.active_record.raise_on_missing_required_finder_order_columns = true
264
314
  ```
265
315
 
266
- *Jean Boussier*
267
-
268
- * Remember when a database connection has recently been verified (for
269
- two seconds, by default), to avoid repeated reverifications during a
270
- single request.
271
-
272
- This should recreate a similar rate of verification as in Rails 7.1,
273
- where connections are leased for the duration of a request, and thus
274
- only verified once.
275
-
276
- *Matthew Draper*
277
-
278
-
279
- ## Rails 8.0.1 (December 13, 2024) ##
280
-
281
- * Fix removing foreign keys with :restrict action for MySQL.
282
-
283
- *fatkodima*
284
-
285
- * Fix a race condition in `ActiveRecord::Base#method_missing` when lazily defining attributes.
286
-
287
- If multiple thread were concurrently triggering attribute definition on the same model,
288
- it could result in a `NoMethodError` being raised.
289
-
290
- *Jean Boussier*
291
-
292
- * Fix MySQL default functions getting dropped when changing a column's nullability.
293
-
294
- *Bastian Bartmann*
295
-
296
- * Fix `add_unique_constraint`/`add_check_constraint`/`add_foreign_key` to be revertible when given invalid options.
297
-
298
- *fatkodima*
299
-
300
- * Fix asynchronous destroying of polymorphic `belongs_to` associations.
301
-
302
- *fatkodima*
303
-
304
- * Fix `insert_all` to not update existing records.
305
-
306
- *fatkodima*
307
-
308
- * `NOT VALID` constraints should not dump in `create_table`.
309
-
310
- *Ryuta Kamizono*
311
-
312
- * Fix finding by nil composite primary key association.
313
-
314
- *fatkodima*
315
-
316
- * Properly reset composite primary key configuration when setting a primary key.
317
-
318
- *fatkodima*
319
-
320
- * Fix Mysql2Adapter support for prepared statements
321
-
322
- Using prepared statements with MySQL could result in a `NoMethodError` exception.
323
-
324
- *Jean Boussier*, *Leo Arnold*, *zzak*
325
-
326
- * Fix parsing of SQLite foreign key names when they contain non-ASCII characters
327
-
328
- *Zacharias Knudsen*
329
-
330
- * Fix parsing of MySQL 8.0.16+ CHECK constraints when they contain new lines.
331
-
332
- *Steve Hill*
333
-
334
- * Ensure normalized attribute queries use `IS NULL` consistently for `nil` and normalized `nil` values.
335
-
336
316
  *Joshua Young*
337
317
 
338
- * Fix `sum` when performing a grouped calculation.
318
+ * `:class_name` is now invalid in polymorphic `belongs_to` associations.
339
319
 
340
- `User.group(:friendly).sum` no longer worked. This is fixed.
320
+ Reason is `:class_name` does not make sense in those associations because
321
+ the class name of target records is dynamic and stored in the type column.
341
322
 
342
- *Edouard Chin*
323
+ Existing polymorphic associations setting this option can just delete it.
324
+ While it did not raise, it had no effect anyway.
343
325
 
344
- * Restore back the ability to pass only database name to `DATABASE_URL`.
326
+ *Xavier Noria*
345
327
 
346
- *fatkodima*
328
+ * Add support for multiple databases to `db:migrate:reset`.
347
329
 
330
+ *Joé Dupuis*
348
331
 
349
- ## Rails 8.0.0.1 (December 10, 2024) ##
332
+ * Add `affected_rows` to `ActiveRecord::Result`.
350
333
 
351
- * No changes.
334
+ *Jenny Shen*
352
335
 
336
+ * Enable passing retryable SqlLiterals to `#where`.
353
337
 
354
- ## Rails 8.0.0 (November 07, 2024) ##
338
+ *Hartley McGuire*
355
339
 
356
- * Fix support for `query_cache: false` in `database.yml`.
340
+ * Set default for primary keys in `insert_all`/`upsert_all`.
357
341
 
358
- `query_cache: false` would no longer entirely disable the Active Record query cache.
342
+ Previously in Postgres, updating and inserting new records in one upsert wasn't possible
343
+ due to null primary key values. `nil` primary key values passed into `insert_all`/`upsert_all`
344
+ are now implicitly set to the default insert value specified by adapter.
359
345
 
360
- *zzak*
346
+ *Jenny Shen*
361
347
 
348
+ * Add a load hook `active_record_database_configurations` for `ActiveRecord::DatabaseConfigurations`
362
349
 
363
- ## Rails 8.0.0.rc2 (October 30, 2024) ##
350
+ *Mike Dalessio*
364
351
 
365
- * NULLS NOT DISTINCT works with UNIQUE CONSTRAINT as well as UNIQUE INDEX.
352
+ * Use `TRUE` and `FALSE` for SQLite queries with boolean columns.
366
353
 
367
- *Ryuta Kamizono*
354
+ *Hartley McGuire*
368
355
 
369
- * The `db:prepare` task no longer loads seeds when a non-primary database is created.
356
+ * Bump minimum supported SQLite to 3.23.0.
370
357
 
371
- Previously, the `db:prepare` task would load seeds whenever a new database
372
- is created, leading to potential loss of data if a database is added to an
373
- existing environment.
358
+ *Hartley McGuire*
374
359
 
375
- Introduces a new database config property `seeds` to control whether seeds
376
- are loaded during `db:prepare` which defaults to `true` for primary database
377
- configs and `false` otherwise.
360
+ * Allow allocated Active Records to lookup associations.
378
361
 
379
- Fixes #53348.
362
+ Previously, the association cache isn't setup on allocated record objects, so association
363
+ lookups will crash. Test frameworks like mocha use allocate to check for stubbable instance
364
+ methods, which can trigger an association lookup.
380
365
 
381
- *Mike Dalessio*
366
+ *Gannon McGibbon*
382
367
 
383
- * `PG::UnableToSend: no connection to the server` is now retryable as a connection-related exception
368
+ * Encryption now supports `support_unencrypted_data: true` being set per-attribute.
384
369
 
385
- *Kazuma Watanabe*
370
+ Previously this only worked if `ActiveRecord::Encryption.config.support_unencrypted_data == true`.
371
+ Now, if the global config is turned off, you can still opt in for a specific attribute.
386
372
 
387
- * Fix strict loading propagation even if statement cache is not used.
373
+ ```ruby
374
+ # ActiveRecord::Encryption.config.support_unencrypted_data = true
375
+ class User < ActiveRecord::Base
376
+ encrypts :name, support_unencrypted_data: false # only supports encrypted data
377
+ encrypts :email # supports encrypted or unencrypted data
378
+ end
379
+ ```
388
380
 
389
- *Ryuta Kamizono*
381
+ ```ruby
382
+ # ActiveRecord::Encryption.config.support_unencrypted_data = false
383
+ class User < ActiveRecord::Base
384
+ encrypts :name, support_unencrypted_data: true # supports encrypted or unencrypted data
385
+ encrypts :email # only supports encrypted data
386
+ end
387
+ ```
390
388
 
391
- * Allow `rename_enum` accepts two from/to name arguments as `rename_table` does so.
389
+ *Alex Ghiculescu*
392
390
 
393
- *Ryuta Kamizono*
391
+ * Model generator no longer needs a database connection to validate column types.
394
392
 
393
+ *Mike Dalessio*
395
394
 
396
- ## Rails 8.0.0.rc1 (October 19, 2024) ##
395
+ * Allow signed ID verifiers to be configurable via `Rails.application.message_verifiers`
397
396
 
398
- * Remove deprecated support to setting `ENV["SCHEMA_CACHE"]`.
397
+ Prior to this change, the primary way to configure signed ID verifiers was
398
+ to set `signed_id_verifier` on each model class:
399
399
 
400
- *Rafael Mendonça França*
400
+ ```ruby
401
+ Post.signed_id_verifier = ActiveSupport::MessageVerifier.new(...)
402
+ Comment.signed_id_verifier = ActiveSupport::MessageVerifier.new(...)
403
+ ```
401
404
 
402
- * Remove deprecated support to passing a database name to `cache_dump_filename`.
405
+ And if the developer did not set `signed_id_verifier`, a verifier would be
406
+ instantiated with a secret derived from `secret_key_base` and the following
407
+ options:
403
408
 
404
- *Rafael Mendonça França*
409
+ ```ruby
410
+ { digest: "SHA256", serializer: JSON, url_safe: true }
411
+ ```
405
412
 
406
- * Remove deprecated `ActiveRecord::ConnectionAdapters::ConnectionPool#connection`.
413
+ Thus it was cumbersome to rotate configuration for all verifiers.
407
414
 
408
- *Rafael Mendonça França*
415
+ This change defines a new Rails config: [`config.active_record.use_legacy_signed_id_verifier`][].
416
+ The default value is `:generate_and_verify`, which preserves the previous
417
+ behavior. However, when set to `:verify`, signed ID verifiers will use
418
+ configuration from `Rails.application.message_verifiers` (specifically,
419
+ `Rails.application.message_verifiers["active_record/signed_id"]`) to
420
+ generate and verify signed IDs, but will also verify signed IDs using the
421
+ older configuration.
409
422
 
410
- * Remove deprecated `config.active_record.sqlite3_deprecated_warning`.
423
+ To avoid complication, the new behavior only applies when `signed_id_verifier_secret`
424
+ is not set on a model class or any of its ancestors. Additionally,
425
+ `signed_id_verifier_secret` is now deprecated. If you are currently setting
426
+ `signed_id_verifier_secret` on a model class, you can set `signed_id_verifier`
427
+ instead:
411
428
 
412
- *Rafael Mendonça França*
429
+ ```ruby
430
+ # BEFORE
431
+ Post.signed_id_verifier_secret = "my secret"
413
432
 
414
- * Remove deprecated `config.active_record.warn_on_records_fetched_greater_than`.
433
+ # AFTER
434
+ Post.signed_id_verifier = ActiveSupport::MessageVerifier.new("my secret", digest: "SHA256", serializer: JSON, url_safe: true)
435
+ ```
415
436
 
416
- *Rafael Mendonça França*
437
+ To ease migration, `signed_id_verifier` has also been changed to behave as a
438
+ `class_attribute` (i.e. inheritable), but _only when `signed_id_verifier_secret`
439
+ is not set_:
417
440
 
418
- * Remove deprecated support for defining `enum` with keyword arguments.
441
+ ```ruby
442
+ # BEFORE
443
+ ActiveRecord::Base.signed_id_verifier = ActiveSupport::MessageVerifier.new(...)
444
+ Post.signed_id_verifier == ActiveRecord::Base.signed_id_verifier # => false
419
445
 
420
- *Rafael Mendonça França*
446
+ # AFTER
447
+ ActiveRecord::Base.signed_id_verifier = ActiveSupport::MessageVerifier.new(...)
448
+ Post.signed_id_verifier == ActiveRecord::Base.signed_id_verifier # => true
421
449
 
422
- * Remove deprecated support to finding database adapters that aren't registered to Active Record.
450
+ Post.signed_id_verifier_secret = "my secret" # => deprecation warning
451
+ Post.signed_id_verifier == ActiveRecord::Base.signed_id_verifier # => false
452
+ ```
423
453
 
424
- *Rafael Mendonça França*
454
+ Note, however, that it is recommended to eventually migrate from
455
+ model-specific verifiers to a unified configuration managed by
456
+ `Rails.application.message_verifiers`. `ActiveSupport::MessageVerifier#rotate`
457
+ can facilitate that transition. For example:
425
458
 
426
- * Remove deprecated `config.active_record.allow_deprecated_singular_associations_name`.
459
+ ```ruby
460
+ # BEFORE
461
+ # Generate and verify signed Post IDs using Post-specific configuration
462
+ Post.signed_id_verifier = ActiveSupport::MessageVerifier.new("post secret", ...)
427
463
 
428
- *Rafael Mendonça França*
464
+ # AFTER
465
+ # Generate and verify signed Post IDs using the unified configuration
466
+ Post.signed_id_verifier = Post.signed_id_verifier.dup
467
+ # Fall back to Post-specific configuration when verifying signed IDs
468
+ Post.signed_id_verifier.rotate("post secret", ...)
469
+ ```
429
470
 
430
- * Remove deprecated `config.active_record.commit_transaction_on_non_local_return`.
471
+ [`config.active_record.use_legacy_signed_id_verifier`]: https://guides.rubyonrails.org/v8.1/configuring.html#config-active-record-use-legacy-signed-id-verifier
431
472
 
432
- *Rafael Mendonça França*
473
+ *Ali Sepehri*, *Jonathan Hefner*
433
474
 
434
- * Fix incorrect SQL query when passing an empty hash to `ActiveRecord::Base.insert`.
475
+ * Prepend `extra_flags` in postgres' `structure_load`
435
476
 
436
- *David Stosik*
477
+ When specifying `structure_load_flags` with a postgres adapter, the flags
478
+ were appended to the default flags, instead of prepended.
479
+ This caused issues with flags not being taken into account by postgres.
437
480
 
438
- * Allow to save records with polymorphic join tables that have `inverse_of`
439
- specified.
481
+ *Alice Loeser*
440
482
 
441
- *Markus Doits*
483
+ * Allow bypassing primary key/constraint addition in `implicit_order_column`
442
484
 
443
- * Fix association scopes applying on the incorrect join when using a polymorphic `has_many through:`.
485
+ When specifying multiple columns in an array for `implicit_order_column`, adding
486
+ `nil` as the last element will prevent appending the primary key to order
487
+ conditions. This allows more precise control of indexes used by
488
+ generated queries. It should be noted that this feature does introduce the risk
489
+ of API misbehavior if the specified columns are not fully unique.
444
490
 
445
- *Joshua Young*
491
+ *Issy Long*
446
492
 
447
- * Allow `ActiveRecord::Base#pluck` to accept hash arguments with symbol and string values.
493
+ * Allow setting the `schema_format` via database configuration.
448
494
 
449
- ```ruby
450
- Post.joins(:comments).pluck(:id, comments: :id)
451
- Post.joins(:comments).pluck("id", "comments" => "id")
495
+ ```
496
+ primary:
497
+ schema_format: ruby
452
498
  ```
453
499
 
454
- *Joshua Young*
455
-
456
- * Make Float distinguish between `float4` and `float8` in PostgreSQL.
457
-
458
- Fixes #52742
500
+ Useful for multi-database setups when apps require different formats per-database.
459
501
 
460
- *Ryota Kitazawa*, *Takayuki Nagatomi*
502
+ *T S Vallender*
461
503
 
504
+ * Support disabling indexes for MySQL v8.0.0+ and MariaDB v10.6.0+
462
505
 
463
- ## Rails 8.0.0.beta1 (September 26, 2024) ##
506
+ MySQL 8.0.0 added an option to disable indexes from being used by the query
507
+ optimizer by making them "invisible". This allows the index to still be maintained
508
+ and updated but no queries will be permitted to use it. This can be useful for adding
509
+ new invisible indexes or making existing indexes invisible before dropping them
510
+ to ensure queries are not negatively affected.
511
+ See https://dev.mysql.com/blog-archive/mysql-8-0-invisible-indexes/ for more details.
464
512
 
465
- * Allow `drop_table` to accept an array of table names.
513
+ MariaDB 10.6.0 also added support for this feature by allowing indexes to be "ignored"
514
+ in queries. See https://mariadb.com/kb/en/ignored-indexes/ for more details.
466
515
 
467
- This will let you to drop multiple tables in a single call.
516
+ Active Record now supports this option for MySQL 8.0.0+ and MariaDB 10.6.0+ for
517
+ index creation and alteration where the new index option `enabled: true/false` can be
518
+ passed to column and index methods as below:
468
519
 
469
520
  ```ruby
470
- ActiveRecord::Base.lease_connection.drop_table(:users, :posts)
521
+ add_index :users, :email, enabled: false
522
+ enable_index :users, :email
523
+ add_column :users, :dob, :string, index: { enabled: false }
524
+
525
+ change_table :users do |t|
526
+ t.index :name, enabled: false
527
+ t.index :dob
528
+ t.disable_index :dob
529
+ t.column :username, :string, index: { enabled: false }
530
+ t.references :account, index: { enabled: false }
531
+ end
532
+
533
+ create_table :users do |t|
534
+ t.string :name, index: { enabled: false }
535
+ t.string :email
536
+ t.index :email, enabled: false
537
+ end
471
538
  ```
472
539
 
473
- *Gabriel Sobrinho*
540
+ *Merve Taner*
474
541
 
475
- * Add support for PostgreSQL `IF NOT EXISTS` via the `:if_not_exists` option
476
- on the `add_enum_value` method.
542
+ * Respect `implicit_order_column` in `ActiveRecord::Relation#reverse_order`.
477
543
 
478
- *Ariel Rzezak*
544
+ *Joshua Young*
479
545
 
480
- * When running `db:migrate` on a fresh database, load the databases schemas before running migrations.
546
+ * Add column types to `ActiveRecord::Result` for SQLite3.
481
547
 
482
- *Andrew Novoselac*, *Marek Kasztelnik*
548
+ *Andrew Kane*
483
549
 
484
- * Fix an issue where `.left_outer_joins` used with multiple associations that have
485
- the same child association but different parents does not join all parents.
550
+ * Raise `ActiveRecord::ReadOnlyError` when pessimistically locking with a readonly role.
486
551
 
487
- Previously, using `.left_outer_joins` with the same child association would only join one of the parents.
552
+ *Joshua Young*
488
553
 
489
- Now it will correctly join both parents.
554
+ * Fix using the `SQLite3Adapter`'s `dbconsole` method outside of a Rails application.
490
555
 
491
- Fixes #41498.
556
+ *Hartley McGuire*
492
557
 
493
- *Garrett Blehm*
558
+ * Fix migrating multiple databases with `ActiveRecord::PendingMigration` action.
494
559
 
495
- * Deprecate `unsigned_float` and `unsigned_decimal` short-hand column methods.
560
+ *Gannon McGibbon*
496
561
 
497
- As of MySQL 8.0.17, the UNSIGNED attribute is deprecated for columns of type FLOAT, DOUBLE,
498
- and DECIMAL. Consider using a simple CHECK constraint instead for such columns.
562
+ * Enable automatically retrying idempotent association queries on connection
563
+ errors.
499
564
 
500
- https://dev.mysql.com/doc/refman/8.0/en/numeric-type-syntax.html
565
+ *Hartley McGuire*
501
566
 
502
- *Ryuta Kamizono*
567
+ * Add `allow_retry` to `sql.active_record` instrumentation.
503
568
 
504
- * Drop MySQL 5.5 support.
569
+ This enables identifying queries which queries are automatically retryable on connection errors.
505
570
 
506
- MySQL 5.5 is the only version that does not support datetime with precision,
507
- which we have supported in the core. Now we support MySQL 5.6.4 or later, which
508
- is the first version to support datetime with precision.
571
+ *Hartley McGuire*
509
572
 
510
- *Ryuta Kamizono*
573
+ * Better support UPDATE with JOIN for Postgresql and SQLite3
511
574
 
512
- * Make Active Record asynchronous queries compatible with transactional fixtures.
575
+ Previously when generating update queries with one or more JOIN clauses,
576
+ Active Record would use a sub query which would prevent to reference the joined
577
+ tables in the `SET` clause, for instance:
513
578
 
514
- Previously transactional fixtures would disable asynchronous queries, because transactional
515
- fixtures impose all queries use the same connection.
579
+ ```ruby
580
+ Comment.joins(:post).update_all("title = posts.title")
581
+ ```
516
582
 
517
- Now asynchronous queries will use the connection pinned by transactional fixtures, and behave
518
- much closer to production.
583
+ This is now supported as long as the relation doesn't also use a `LIMIT`, `ORDER` or
584
+ `GROUP BY` clause. This was supported by the MySQL adapter for a long time.
519
585
 
520
586
  *Jean Boussier*
521
587
 
522
- * Deserialize binary data before decrypting
523
-
524
- This ensures that we call `PG::Connection.unescape_bytea` on PostgreSQL before decryption.
525
-
526
- *Donal McBreen*
527
-
528
- * Ensure `ActiveRecord::Encryption.config` is always ready before access.
529
-
530
- Previously, `ActiveRecord::Encryption` configuration was deferred until `ActiveRecord::Base`
531
- was loaded. Therefore, accessing `ActiveRecord::Encryption.config` properties before
532
- `ActiveRecord::Base` was loaded would give incorrect results.
533
-
534
- `ActiveRecord::Encryption` now has its own loading hook so that its configuration is set as
535
- soon as needed.
536
-
537
- When `ActiveRecord::Base` is loaded, even lazily, it in turn triggers the loading of
538
- `ActiveRecord::Encryption`, thus preserving the original behavior of having its config ready
539
- before any use of `ActiveRecord::Base`.
540
-
541
- *Maxime Réty*
588
+ * Introduce a before-fork hook in `ActiveSupport::Testing::Parallelization` to clear existing
589
+ connections, to avoid fork-safety issues with the mysql2 adapter.
542
590
 
543
- * Add `TimeZoneConverter#==` method, so objects will be properly compared by
544
- their type, scale, limit & precision.
591
+ Fixes #41776
545
592
 
546
- Address #52699.
593
+ *Mike Dalessio*, *Donal McBreen*
547
594
 
548
- *Ruy Rocha*
549
-
550
- * Add support for SQLite3 full-text-search and other virtual tables.
551
-
552
- Previously, adding sqlite3 virtual tables messed up `schema.rb`.
595
+ * PoolConfig no longer keeps a reference to the connection class.
553
596
 
554
- Now, virtual tables can safely be added using `create_virtual_table`.
597
+ Keeping a reference to the class caused subtle issues when combined with reloading in
598
+ development. Fixes #54343.
555
599
 
556
- *Zacharias Knudsen*
600
+ *Mike Dalessio*
557
601
 
558
- * Support use of alternative database interfaces via the `database_cli` ActiveRecord configuration option.
602
+ * Fix SQL notifications sometimes not sent when using async queries.
559
603
 
560
604
  ```ruby
561
- Rails.application.configure do
562
- config.active_record.database_cli = { postgresql: "pgcli" }
605
+ Post.async_count
606
+ ActiveSupport::Notifications.subscribed(->(*) { "Will never reach here" }) do
607
+ Post.count
563
608
  end
564
609
  ```
565
610
 
566
- *T S Vallender*
611
+ In rare circumstances and under the right race condition, Active Support notifications
612
+ would no longer be dispatched after using an asynchronous query.
613
+ This is now fixed.
567
614
 
568
- * Add support for dumping table inheritance and native partitioning table definitions for PostgeSQL adapter
615
+ *Edouard Chin*
569
616
 
570
- *Justin Talbott*
617
+ * Eliminate queries loading dumped schema cache on Postgres
571
618
 
572
- * Add support for `ActiveRecord::Point` type casts using `Hash` values
619
+ Improve resiliency by avoiding needing to open a database connection to load the
620
+ type map while defining attribute methods at boot when a schema cache file is
621
+ configured on PostgreSQL databases.
573
622
 
574
- This allows `ActiveRecord::Point` to be cast or serialized from a hash
575
- with `:x` and `:y` keys of numeric values, mirroring the functionality of
576
- existing casts for string and array values. Both string and symbol keys are
577
- supported.
623
+ *James Coleman*
578
624
 
579
- ```ruby
580
- class PostgresqlPoint < ActiveRecord::Base
581
- attribute :x, :point
582
- attribute :y, :point
583
- attribute :z, :point
584
- end
625
+ * `ActiveRecord::Coder::JSON` can be instantiated
585
626
 
586
- val = PostgresqlPoint.new({
587
- x: '(12.34, -43.21)',
588
- y: [12.34, '-43.21'],
589
- z: {x: '12.34', y: -43.21}
590
- })
591
- ActiveRecord::Point.new(12.32, -43.21) == val.x == val.y == val.z
627
+ Options can now be passed to `ActiveRecord::Coder::JSON` when instantiating the coder. This allows:
628
+ ```ruby
629
+ serialize :config, coder: ActiveRecord::Coder::JSON.new(symbolize_names: true)
592
630
  ```
631
+ *matthaigh27*
593
632
 
594
- *Stephen Drew*
633
+ * Deprecate using `insert_all`/`upsert_all` with unpersisted records in associations.
595
634
 
596
- * Replace `SQLite3::Database#busy_timeout` with `#busy_handler_timeout=`.
635
+ Using these methods on associations containing unpersisted records will now
636
+ show a deprecation warning, as the unpersisted records will be lost after
637
+ the operation.
597
638
 
598
- Provides a non-GVL-blocking, fair retry interval busy handler implementation.
639
+ *Nick Schwaderer*
599
640
 
600
- *Stephen Margheim*
641
+ * Make column name optional for `index_exists?`.
601
642
 
602
- * SQLite3Adapter: Translate `SQLite3::BusyException` into `ActiveRecord::StatementTimeout`.
643
+ This aligns well with `remove_index` signature as well, where
644
+ index name doesn't need to be derived from the column names.
603
645
 
604
- *Matthew Nguyen*
646
+ *Ali Ismayiliov*
605
647
 
606
- * Include schema name in `enable_extension` statements in `db/schema.rb`.
648
+ * Change the payload name of `sql.active_record` notification for eager
649
+ loading from "SQL" to "#{model.name} Eager Load".
607
650
 
608
- The schema dumper will now include the schema name in generated
609
- `enable_extension` statements if they differ from the current schema.
651
+ *zzak*
610
652
 
611
- For example, if you have a migration:
653
+ * Enable automatically retrying idempotent `#exists?` queries on connection
654
+ errors.
612
655
 
613
- ```ruby
614
- enable_extension "heroku_ext.pgcrypto"
615
- enable_extension "pg_stat_statements"
616
- ```
656
+ *Hartley McGuire*, *classidied*
617
657
 
618
- then the generated schema dump will also contain:
658
+ * Deprecate usage of unsupported methods in conjunction with `update_all`:
619
659
 
620
- ```ruby
621
- enable_extension "heroku_ext.pgcrypto"
622
- enable_extension "pg_stat_statements"
623
- ```
660
+ `update_all` will now print a deprecation message if a query includes either `WITH`,
661
+ `WITH RECURSIVE` or `DISTINCT` statements. Those were never supported and were ignored
662
+ when generating the SQL query.
624
663
 
625
- *Tony Novak*
664
+ An error will be raised in a future Rails release. This behavior will be consistent
665
+ with `delete_all` which currently raises an error for unsupported statements.
626
666
 
627
- * Fix `ActiveRecord::Encryption::EncryptedAttributeType#type` to return
628
- actual cast type.
667
+ *Edouard Chin*
629
668
 
630
- *Vasiliy Ermolovich*
669
+ * The table columns inside `schema.rb` are now sorted alphabetically.
631
670
 
632
- * SQLite3Adapter: Bulk insert fixtures.
671
+ Previously they'd be sorted by creation order, which can cause merge conflicts when two
672
+ branches modify the same table concurrently.
633
673
 
634
- Previously one insert command was executed for each fixture, now they are
635
- aggregated in a single bulk insert command.
674
+ *John Duff*
636
675
 
637
- *Lázaro Nixon*
676
+ * Introduce versions formatter for the schema dumper.
638
677
 
639
- * PostgreSQLAdapter: Allow `disable_extension` to be called with schema-qualified name.
678
+ It is now possible to override how schema dumper formats versions information inside the
679
+ `structure.sql` file. Currently, the versions are simply sorted in the decreasing order.
680
+ Within large teams, this can potentially cause many merge conflicts near the top of the list.
640
681
 
641
- For parity with `enable_extension`, the `disable_extension` method can be called with a schema-qualified
642
- name (e.g. `disable_extension "myschema.pgcrypto"`). Note that PostgreSQL's `DROP EXTENSION` does not
643
- actually take a schema name (unlike `CREATE EXTENSION`), so the resulting SQL statement will only name
644
- the extension, e.g. `DROP EXTENSION IF EXISTS "pgcrypto"`.
682
+ Now, the custom formatter can be provided with a custom sorting logic (e.g. by hash values
683
+ of the versions), which can greatly reduce the number of conflicts.
645
684
 
646
- *Tony Novak*
685
+ *fatkodima*
647
686
 
648
- * Make `create_schema` / `drop_schema` reversible in migrations.
687
+ * Serialized attributes can now be marked as comparable.
649
688
 
650
- Previously, `create_schema` and `drop_schema` were irreversible migration operations.
689
+ A not rare issue when working with serialized attributes is that the serialized representation of an object
690
+ can change over time. Either because you are migrating from one serializer to the other (e.g. YAML to JSON or to msgpack),
691
+ or because the serializer used subtly changed its output.
651
692
 
652
- *Tony Novak*
693
+ One example is libyaml that used to have some extra trailing whitespaces, and recently fixed that.
694
+ When this sorts of thing happen, you end up with lots of records that report being changed even though
695
+ they aren't, which in the best case leads to a lot more writes to the database and in the worst case lead to nasty bugs.
653
696
 
654
- * Support batching using custom columns.
697
+ The solution is to instead compare the deserialized representation of the object, however Active Record
698
+ can't assume the deserialized object has a working `==` method. Hence why this new functionality is opt-in.
655
699
 
656
700
  ```ruby
657
- Product.in_batches(cursor: [:shop_id, :id]) do |relation|
658
- # do something with relation
659
- end
701
+ serialize :config, type: Hash, coder: JSON, comparable: true
660
702
  ```
661
703
 
662
- *fatkodima*
663
-
664
- * Use SQLite `IMMEDIATE` transactions when possible.
665
-
666
- Transactions run against the SQLite3 adapter default to IMMEDIATE mode to improve concurrency support and avoid busy exceptions.
667
-
668
- *Stephen Margheim*
669
-
670
- * Raise specific exception when a connection is not defined.
671
-
672
- The new `ConnectionNotDefined` exception provides connection name, shard and role accessors indicating the details of the connection that was requested.
673
-
674
- *Hana Harencarova*, *Matthew Draper*
704
+ *Jean Boussier*
675
705
 
676
- * Delete the deprecated constant `ActiveRecord::ImmutableRelation`.
706
+ * Fix MySQL default functions getting dropped when changing a column's nullability.
677
707
 
678
- *Xavier Noria*
708
+ *Bastian Bartmann*
679
709
 
680
- * Fix duplicate callback execution when child autosaves parent with `has_one` and `belongs_to`.
710
+ * SQLite extensions can be configured in `config/database.yml`.
681
711
 
682
- Before, persisting a new child record with a new associated parent record would run `before_validation`,
683
- `after_validation`, `before_save` and `after_save` callbacks twice.
712
+ The database configuration option `extensions:` allows an application to load SQLite extensions
713
+ when using `sqlite3` >= v2.4.0. The array members may be filesystem paths or the names of
714
+ modules that respond to `.to_path`:
684
715
 
685
- Now, these callbacks are only executed once as expected.
716
+ ``` yaml
717
+ development:
718
+ adapter: sqlite3
719
+ extensions:
720
+ - SQLean::UUID # module name responding to `.to_path`
721
+ - .sqlpkg/nalgeon/crypto/crypto.so # or a filesystem path
722
+ - <%= AppExtensions.location %> # or ruby code returning a path
723
+ ```
686
724
 
687
- *Joshua Young*
725
+ *Mike Dalessio*
688
726
 
689
- * `ActiveRecord::Encryption::Encryptor` now supports a `:compressor` option to customize the compression algorithm used.
727
+ * `ActiveRecord::Middleware::ShardSelector` supports granular database connection switching.
690
728
 
691
- ```ruby
692
- module ZstdCompressor
693
- def self.deflate(data)
694
- Zstd.compress(data)
695
- end
729
+ A new configuration option, `class_name:`, is introduced to
730
+ `config.active_record.shard_selector` to allow an application to specify the abstract connection
731
+ class to be switched by the shard selection middleware. The default class is
732
+ `ActiveRecord::Base`.
696
733
 
697
- def self.inflate(data)
698
- Zstd.decompress(data)
699
- end
700
- end
734
+ For example, this configuration tells `ShardSelector` to switch shards using
735
+ `AnimalsRecord.connected_to`:
701
736
 
702
- class User
703
- encrypts :name, compressor: ZstdCompressor
704
- end
705
737
  ```
706
-
707
- You disable compression by passing `compress: false`.
708
-
709
- ```ruby
710
- class User
711
- encrypts :name, compress: false
712
- end
738
+ config.active_record.shard_selector = { class_name: "AnimalsRecord" }
713
739
  ```
714
740
 
715
- *heka1024*
716
-
717
- * Add condensed `#inspect` for `ConnectionPool`, `AbstractAdapter`, and
718
- `DatabaseConfig`.
719
-
720
- *Hartley McGuire*
721
-
722
- * Add `.shard_keys`, `.sharded?`, & `.connected_to_all_shards` methods.
723
-
724
- ```ruby
725
- class ShardedBase < ActiveRecord::Base
726
- self.abstract_class = true
727
-
728
- connects_to shards: {
729
- shard_one: { writing: :shard_one },
730
- shard_two: { writing: :shard_two }
731
- }
732
- end
741
+ *Mike Dalessio*
733
742
 
734
- class ShardedModel < ShardedBase
735
- end
743
+ * Reset relations after `insert_all`/`upsert_all`.
736
744
 
737
- ShardedModel.shard_keys => [:shard_one, :shard_two]
738
- ShardedModel.sharded? => true
739
- ShardedBase.connected_to_all_shards { ShardedModel.current_shard } => [:shard_one, :shard_two]
740
- ```
745
+ Bulk insert/upsert methods will now call `reset` if used on a relation, matching the behavior of `update_all`.
741
746
 
742
- *Nony Dutton*
747
+ *Milo Winningham*
743
748
 
744
- * Add a `filter` option to `in_order_of` to prioritize certain values in the sorting without filtering the results
745
- by these values.
749
+ * Use `_N` as a parallel tests databases suffixes
746
750
 
747
- *Igor Depolli*
751
+ Peviously, `-N` was used as a suffix. This can cause problems for RDBMSes
752
+ which do not support dashes in database names.
748
753
 
749
- * Fix an issue where the IDs reader method did not return expected results
750
- for preloaded associations in models using composite primary keys.
751
-
752
- *Jay Ang*
754
+ *fatkodima*
753
755
 
754
- * Allow to configure `strict_loading_mode` globally or within a model.
756
+ * Remember when a database connection has recently been verified (for
757
+ two seconds, by default), to avoid repeated reverifications during a
758
+ single request.
755
759
 
756
- Defaults to `:all`, can be changed to `:n_plus_one_only`.
760
+ This should recreate a similar rate of verification as in Rails 7.1,
761
+ where connections are leased for the duration of a request, and thus
762
+ only verified once.
757
763
 
758
- *Garen Torikian*
764
+ *Matthew Draper*
759
765
 
760
- * Add `ActiveRecord::Relation#readonly?`.
766
+ * Allow to reset cache counters for multiple records.
761
767
 
762
- Reflects if the relation has been marked as readonly.
768
+ ```
769
+ Aircraft.reset_counters([1, 2, 3], :wheels_count)
770
+ ```
763
771
 
764
- *Theodor Tonum*
772
+ It produces much fewer queries compared to the custom implementation using looping over ids.
773
+ Previously: `O(ids.size * counters.size)` queries, now: `O(ids.size + counters.size)` queries.
765
774
 
766
- * Improve `ActiveRecord::Store` to raise a descriptive exception if the column is not either
767
- structured (e.g., PostgreSQL +hstore+/+json+, or MySQL +json+) or declared serializable via
768
- `ActiveRecord.store`.
775
+ *fatkodima*
769
776
 
770
- Previously, a `NoMethodError` would be raised when the accessor was read or written:
777
+ * Add `affected_rows` to `sql.active_record` Notification.
771
778
 
772
- NoMethodError: undefined method `accessor' for an instance of ActiveRecord::Type::Text
779
+ *Hartley McGuire*
773
780
 
774
- Now, a descriptive `ConfigurationError` is raised:
781
+ * Fix `sum` when performing a grouped calculation.
775
782
 
776
- ActiveRecord::ConfigurationError: the column 'metadata' has not been configured as a store.
777
- Please make sure the column is declared serializable via 'ActiveRecord.store' or, if your
778
- database supports it, use a structured column type like hstore or json.
783
+ `User.group(:friendly).sum` no longer worked. This is fixed.
779
784
 
780
- *Mike Dalessio*
785
+ *Edouard Chin*
781
786
 
782
- * Fix inference of association model on nested models with the same demodularized name.
787
+ * Add support for enabling or disabling transactional tests per database.
783
788
 
784
- E.g. with the following setup:
789
+ A test class can now override the default `use_transactional_tests` setting
790
+ for individual databases, which can be useful if some databases need their
791
+ current state to be accessible to an external process while tests are running.
785
792
 
786
793
  ```ruby
787
- class Nested::Post < ApplicationRecord
788
- has_one :post, through: :other
794
+ class MostlyTransactionalTest < ActiveSupport::TestCase
795
+ self.use_transactional_tests = true
796
+ skip_transactional_tests_for_database :shared
789
797
  end
790
798
  ```
791
799
 
792
- Before, `#post` would infer the model as `Nested::Post`, but now it correctly infers `Post`.
800
+ *Matthew Cheetham*, *Morgan Mareve*
793
801
 
794
- *Joshua Young*
802
+ * Cast `query_cache` value when using URL configuration.
795
803
 
796
- * Add public method for checking if a table is ignored by the schema cache.
804
+ *zzak*
797
805
 
798
- 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.
806
+ * NULLS NOT DISTINCT works with UNIQUE CONSTRAINT as well as UNIQUE INDEX.
799
807
 
800
- ```ruby
801
- ActiveRecord.schema_cache_ignored_tables = ["developers"]
802
- ActiveRecord.schema_cache_ignored_table?("developers")
803
- => true
804
- ```
808
+ *Ryuta Kamizono*
805
809
 
806
- *Eileen M. Uchitelle*
810
+ * `PG::UnableToSend: no connection to the server` is now retryable as a connection-related exception
811
+
812
+ *Kazuma Watanabe*
807
813
 
808
- Please check [7-2-stable](https://github.com/rails/rails/blob/7-2-stable/activerecord/CHANGELOG.md) for previous changes.
814
+ Please check [8-0-stable](https://github.com/rails/rails/blob/8-0-stable/activerecord/CHANGELOG.md) for previous changes.