activerecord 7.2.2.2 → 8.0.0.beta1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of activerecord might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/CHANGELOG.md +172 -932
- data/README.rdoc +1 -1
- data/lib/active_record/associations/association.rb +25 -5
- data/lib/active_record/associations/builder/association.rb +7 -6
- data/lib/active_record/associations/collection_association.rb +10 -8
- data/lib/active_record/associations/disable_joins_association_scope.rb +1 -1
- data/lib/active_record/associations/has_many_through_association.rb +4 -9
- data/lib/active_record/associations/preloader/association.rb +2 -2
- data/lib/active_record/associations/singular_association.rb +8 -3
- data/lib/active_record/associations.rb +50 -32
- data/lib/active_record/asynchronous_queries_tracker.rb +28 -24
- data/lib/active_record/autosave_association.rb +69 -27
- data/lib/active_record/callbacks.rb +1 -1
- data/lib/active_record/connection_adapters/abstract/connection_handler.rb +16 -10
- data/lib/active_record/connection_adapters/abstract/connection_pool/queue.rb +0 -1
- data/lib/active_record/connection_adapters/abstract/connection_pool/reaper.rb +0 -1
- data/lib/active_record/connection_adapters/abstract/connection_pool.rb +0 -27
- data/lib/active_record/connection_adapters/abstract/database_statements.rb +90 -43
- data/lib/active_record/connection_adapters/abstract/query_cache.rb +8 -2
- data/lib/active_record/connection_adapters/abstract/quoting.rb +1 -1
- data/lib/active_record/connection_adapters/abstract/schema_definitions.rb +1 -1
- data/lib/active_record/connection_adapters/abstract/schema_statements.rb +27 -6
- data/lib/active_record/connection_adapters/abstract/transaction.rb +15 -5
- data/lib/active_record/connection_adapters/abstract_adapter.rb +24 -25
- data/lib/active_record/connection_adapters/abstract_mysql_adapter.rb +23 -45
- data/lib/active_record/connection_adapters/mysql/quoting.rb +0 -8
- data/lib/active_record/connection_adapters/mysql/schema_definitions.rb +2 -8
- data/lib/active_record/connection_adapters/mysql/schema_statements.rb +43 -45
- data/lib/active_record/connection_adapters/mysql2/database_statements.rb +42 -98
- data/lib/active_record/connection_adapters/mysql2_adapter.rb +1 -8
- data/lib/active_record/connection_adapters/postgresql/database_statements.rb +64 -42
- data/lib/active_record/connection_adapters/postgresql/oid/point.rb +10 -0
- data/lib/active_record/connection_adapters/postgresql/schema_creation.rb +0 -1
- data/lib/active_record/connection_adapters/postgresql/schema_statements.rb +50 -8
- data/lib/active_record/connection_adapters/postgresql_adapter.rb +41 -93
- data/lib/active_record/connection_adapters/schema_cache.rb +1 -3
- data/lib/active_record/connection_adapters/sqlite3/database_statements.rb +76 -100
- data/lib/active_record/connection_adapters/sqlite3/schema_creation.rb +0 -6
- data/lib/active_record/connection_adapters/sqlite3/schema_dumper.rb +13 -0
- data/lib/active_record/connection_adapters/sqlite3/schema_statements.rb +8 -1
- data/lib/active_record/connection_adapters/sqlite3_adapter.rb +55 -12
- data/lib/active_record/connection_adapters/trilogy/database_statements.rb +37 -67
- data/lib/active_record/connection_adapters/trilogy_adapter.rb +0 -17
- data/lib/active_record/connection_handling.rb +22 -0
- data/lib/active_record/core.rb +8 -33
- data/lib/active_record/encryption/config.rb +3 -1
- data/lib/active_record/encryption/encryptable_record.rb +4 -4
- data/lib/active_record/encryption/encrypted_attribute_type.rb +10 -1
- data/lib/active_record/encryption/encryptor.rb +15 -8
- data/lib/active_record/encryption/extended_deterministic_queries.rb +4 -2
- data/lib/active_record/encryption/scheme.rb +8 -1
- data/lib/active_record/errors.rb +13 -5
- data/lib/active_record/fixtures.rb +0 -1
- data/lib/active_record/future_result.rb +14 -10
- data/lib/active_record/gem_version.rb +4 -4
- data/lib/active_record/insert_all.rb +1 -1
- data/lib/active_record/marshalling.rb +1 -4
- data/lib/active_record/migration/command_recorder.rb +22 -5
- data/lib/active_record/migration/compatibility.rb +5 -2
- data/lib/active_record/migration.rb +35 -33
- data/lib/active_record/model_schema.rb +1 -1
- data/lib/active_record/nested_attributes.rb +4 -6
- data/lib/active_record/persistence.rb +128 -130
- data/lib/active_record/query_cache.rb +5 -4
- data/lib/active_record/query_logs.rb +98 -40
- data/lib/active_record/query_logs_formatter.rb +17 -28
- data/lib/active_record/querying.rb +6 -6
- data/lib/active_record/railtie.rb +3 -4
- data/lib/active_record/reflection.rb +9 -7
- data/lib/active_record/relation/batches/batch_enumerator.rb +4 -3
- data/lib/active_record/relation/batches.rb +132 -72
- data/lib/active_record/relation/calculations.rb +25 -20
- data/lib/active_record/relation/delegation.rb +25 -14
- data/lib/active_record/relation/finder_methods.rb +21 -22
- data/lib/active_record/relation/merger.rb +8 -8
- data/lib/active_record/relation/predicate_builder/polymorphic_array_value.rb +1 -1
- data/lib/active_record/relation/predicate_builder/relation_handler.rb +4 -3
- data/lib/active_record/relation/predicate_builder.rb +5 -0
- data/lib/active_record/relation/query_methods.rb +81 -75
- data/lib/active_record/relation/record_fetch_warning.rb +2 -2
- data/lib/active_record/relation/spawn_methods.rb +1 -1
- data/lib/active_record/relation.rb +72 -61
- data/lib/active_record/result.rb +68 -7
- data/lib/active_record/sanitization.rb +7 -6
- data/lib/active_record/schema_dumper.rb +5 -0
- data/lib/active_record/schema_migration.rb +2 -1
- data/lib/active_record/scoping/named.rb +5 -2
- data/lib/active_record/statement_cache.rb +12 -12
- data/lib/active_record/store.rb +7 -3
- data/lib/active_record/tasks/database_tasks.rb +24 -15
- data/lib/active_record/tasks/mysql_database_tasks.rb +0 -2
- data/lib/active_record/tasks/sqlite_database_tasks.rb +2 -2
- data/lib/active_record/test_fixtures.rb +12 -0
- data/lib/active_record/testing/query_assertions.rb +2 -2
- data/lib/active_record/token_for.rb +1 -1
- data/lib/active_record/validations/uniqueness.rb +8 -8
- data/lib/active_record.rb +15 -0
- data/lib/arel/collectors/bind.rb +1 -1
- data/lib/arel/visitors/sqlite.rb +0 -25
- metadata +14 -11
data/CHANGELOG.md
CHANGED
@@ -1,131 +1,67 @@
|
|
1
|
-
## Rails
|
1
|
+
## Rails 8.0.0.beta1 (September 26, 2024) ##
|
2
2
|
|
3
|
-
*
|
3
|
+
* Allow `drop_table` to accept an array of table names.
|
4
4
|
|
5
|
-
|
5
|
+
This will let you to drop multiple tables in a single call.
|
6
6
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
* No changes.
|
12
|
-
|
13
|
-
|
14
|
-
## Rails 7.2.2 (October 30, 2024) ##
|
15
|
-
|
16
|
-
* Fix support for `query_cache: false` in `database.yml`.
|
17
|
-
|
18
|
-
`query_cache: false` would no longer entirely disable the Active Record query cache.
|
7
|
+
```ruby
|
8
|
+
ActiveRecord::Base.lease_connection.drop_table(:users, :posts)
|
9
|
+
```
|
19
10
|
|
20
|
-
*
|
11
|
+
*Gabriel Sobrinho*
|
21
12
|
|
22
|
-
*
|
13
|
+
* Add support for PostgreSQL `IF NOT EXISTS` via the `:if_not_exists` option
|
14
|
+
on the `add_enum_value` method.
|
23
15
|
|
24
|
-
|
16
|
+
*Ariel Rzezak*
|
25
17
|
|
26
|
-
|
18
|
+
* When running `db:migrate` on a fresh database, load the database schema before running migrations.
|
27
19
|
|
28
20
|
*Andrew Novoselac*
|
29
21
|
|
30
|
-
*
|
31
|
-
|
32
|
-
*Kazuma Watanabe*
|
33
|
-
|
34
|
-
* Fix marshalling of unsaved associated records in 7.1 format.
|
35
|
-
|
36
|
-
The 7.1 format would only marshal associated records if the association was loaded.
|
37
|
-
But associations that would only contain unsaved records would be skipped.
|
38
|
-
|
39
|
-
*Jean Boussier*
|
40
|
-
|
41
|
-
* Fix incorrect SQL query when passing an empty hash to `ActiveRecord::Base.insert`.
|
42
|
-
|
43
|
-
*David Stosik*
|
44
|
-
|
45
|
-
* Allow to save records with polymorphic join tables that have `inverse_of`
|
46
|
-
specified.
|
47
|
-
|
48
|
-
*Markus Doits*
|
49
|
-
|
50
|
-
* Fix association scopes applying on the incorrect join when using a polymorphic `has_many through:`.
|
51
|
-
|
52
|
-
*Joshua Young*
|
53
|
-
|
54
|
-
* Fix `dependent: :destroy` for bi-directional has one through association.
|
55
|
-
|
56
|
-
Fixes #50948.
|
57
|
-
|
58
|
-
```ruby
|
59
|
-
class Left < ActiveRecord::Base
|
60
|
-
has_one :middle, dependent: :destroy
|
61
|
-
has_one :right, through: :middle
|
62
|
-
end
|
63
|
-
|
64
|
-
class Middle < ActiveRecord::Base
|
65
|
-
belongs_to :left, dependent: :destroy
|
66
|
-
belongs_to :right, dependent: :destroy
|
67
|
-
end
|
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.
|
68
24
|
|
69
|
-
|
70
|
-
has_one :middle, dependent: :destroy
|
71
|
-
has_one :left, through: :middle
|
72
|
-
end
|
73
|
-
```
|
74
|
-
In the above example `left.destroy` wouldn't destroy its associated `Right`
|
75
|
-
record.
|
25
|
+
Previously, using `.left_outer_joins` with the same child association would only join one of the parents.
|
76
26
|
|
77
|
-
|
27
|
+
Now it will correctly join both parents.
|
78
28
|
|
79
|
-
|
29
|
+
Fixes #41498.
|
80
30
|
|
81
|
-
|
31
|
+
*Garrett Blehm*
|
82
32
|
|
83
|
-
|
84
|
-
such as capybara, it could happen that a connection end up pinned by the
|
85
|
-
server thread rather than the test thread, causing
|
86
|
-
`"Cannot expire connection, it is owned by a different thread"` errors.
|
33
|
+
* Deprecate `unsigned_float` and `unsigned_decimal` short-hand column methods.
|
87
34
|
|
88
|
-
|
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.
|
89
37
|
|
90
|
-
|
38
|
+
https://dev.mysql.com/doc/refman/8.0/en/numeric-type-syntax.html
|
91
39
|
|
92
|
-
|
40
|
+
*Ryuta Kamizono*
|
93
41
|
|
94
|
-
|
95
|
-
User.with(foo: [User.select(:id), User.select(:id), User.select(:id)]).to_sql
|
96
|
-
undefined method `union' for an instance of Arel::Nodes::UnionAll (NoMethodError)
|
97
|
-
```
|
42
|
+
* Drop MySQL 5.5 support.
|
98
43
|
|
99
|
-
|
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.
|
100
47
|
|
101
|
-
*
|
48
|
+
*Ryuta Kamizono*
|
102
49
|
|
103
|
-
*
|
50
|
+
* Make Active Record asynchronous queries compatible with transactional fixtures.
|
104
51
|
|
105
|
-
|
52
|
+
Previously transactional fixtures would disable asynchronous queries, because transactional
|
53
|
+
fixtures impose all queries use the same connection.
|
106
54
|
|
107
|
-
|
108
|
-
|
109
|
-
causing "Cannot expire connection, it is owned by a different thread" errors in later tests.
|
55
|
+
Now asynchronous queries will use the connection pinned by transactional fixtures, and behave
|
56
|
+
much closer to production.
|
110
57
|
|
111
58
|
*Jean Boussier*
|
112
59
|
|
113
|
-
*
|
114
|
-
|
115
|
-
Fixes #52742
|
116
|
-
|
117
|
-
*Ryota Kitazawa*, *Takayuki Nagatomi*
|
118
|
-
|
119
|
-
* Fix an issue where `.left_outer_joins` used with multiple associations that have
|
120
|
-
the same child association but different parents does not join all parents.
|
121
|
-
|
122
|
-
Previously, using `.left_outer_joins` with the same child association would only join one of the parents.
|
60
|
+
* Deserialize binary data before decrypting
|
123
61
|
|
124
|
-
|
62
|
+
This ensures that we call `PG::Connection.unescape_bytea` on PostgreSQL before decryption.
|
125
63
|
|
126
|
-
|
127
|
-
|
128
|
-
*Garrett Blehm*
|
64
|
+
*Donal McBreen*
|
129
65
|
|
130
66
|
* Ensure `ActiveRecord::Encryption.config` is always ready before access.
|
131
67
|
|
@@ -149,958 +85,262 @@
|
|
149
85
|
|
150
86
|
*Ruy Rocha*
|
151
87
|
|
88
|
+
* Add support for SQLite3 full-text-search and other virtual tables.
|
152
89
|
|
153
|
-
|
154
|
-
|
155
|
-
* No changes.
|
156
|
-
|
157
|
-
|
158
|
-
## Rails 7.2.1.1 (October 15, 2024) ##
|
159
|
-
|
160
|
-
* No changes.
|
161
|
-
|
162
|
-
|
163
|
-
## Rails 7.2.1 (August 22, 2024) ##
|
90
|
+
Previously, adding sqlite3 virtual tables messed up `schema.rb`.
|
164
91
|
|
165
|
-
|
92
|
+
Now, virtual tables can safely be added using `create_virtual_table`.
|
166
93
|
|
167
|
-
*
|
94
|
+
*Zacharias Knudsen*
|
168
95
|
|
169
|
-
*
|
170
|
-
|
171
|
-
*fatkodima*
|
172
|
-
|
173
|
-
* Fix swallowing ignore order warning when batching using `BatchEnumerator`.
|
174
|
-
|
175
|
-
*fatkodima*
|
176
|
-
|
177
|
-
* Fix memory bloat on the connection pool when using the Fiber `IsolatedExecutionState`.
|
178
|
-
|
179
|
-
*Jean Boussier*
|
180
|
-
|
181
|
-
* Restore inferred association class with the same modularized name.
|
182
|
-
|
183
|
-
*Justin Ko*
|
184
|
-
|
185
|
-
* Fix `ActiveRecord::Base.inspect` to properly explain how to load schema information.
|
186
|
-
|
187
|
-
*Jean Boussier*
|
188
|
-
|
189
|
-
* Check invalid `enum` options for the new syntax.
|
190
|
-
|
191
|
-
The options using `_` prefix in the old syntax are invalid in the new syntax.
|
192
|
-
|
193
|
-
*Rafael Mendonça França*
|
194
|
-
|
195
|
-
* Fix `ActiveRecord::Encryption::EncryptedAttributeType#type` to return
|
196
|
-
actual cast type.
|
197
|
-
|
198
|
-
*Vasiliy Ermolovich*
|
199
|
-
|
200
|
-
* Fix `create_table` with `:auto_increment` option for MySQL adapter.
|
201
|
-
|
202
|
-
*fatkodima*
|
203
|
-
|
204
|
-
|
205
|
-
## Rails 7.2.0 (August 09, 2024) ##
|
206
|
-
|
207
|
-
* Handle commas in Sqlite3 default function definitions.
|
208
|
-
|
209
|
-
*Stephen Margheim*
|
210
|
-
|
211
|
-
* Fixes `validates_associated` raising an exception when configured with a
|
212
|
-
singular association and having `index_nested_attribute_errors` enabled.
|
213
|
-
|
214
|
-
*Martin Spickermann*
|
215
|
-
|
216
|
-
* The constant `ActiveRecord::ImmutableRelation` has been deprecated because
|
217
|
-
we want to reserve that name for a stronger sense of "immutable relation".
|
218
|
-
Please use `ActiveRecord::UnmodifiableRelation` instead.
|
219
|
-
|
220
|
-
*Xavier Noria*
|
221
|
-
|
222
|
-
* Add condensed `#inspect` for `ConnectionPool`, `AbstractAdapter`, and
|
223
|
-
`DatabaseConfig`.
|
224
|
-
|
225
|
-
*Hartley McGuire*
|
226
|
-
|
227
|
-
* Fixed a memory performance issue in Active Record attribute methods definition.
|
228
|
-
|
229
|
-
*Jean Boussier*
|
230
|
-
|
231
|
-
* Define the new Active Support notification event `start_transaction.active_record`.
|
232
|
-
|
233
|
-
This event is fired when database transactions or savepoints start, and
|
234
|
-
complements `transaction.active_record`, which is emitted when they finish.
|
235
|
-
|
236
|
-
The payload has the transaction (`:transaction`) and the connection (`:connection`).
|
237
|
-
|
238
|
-
*Xavier Noria*
|
239
|
-
|
240
|
-
* Fix an issue where the IDs reader method did not return expected results
|
241
|
-
for preloaded associations in models using composite primary keys.
|
242
|
-
|
243
|
-
*Jay Ang*
|
244
|
-
|
245
|
-
* The payload of `sql.active_record` Active Support notifications now has the current transaction in the `:transaction` key.
|
246
|
-
|
247
|
-
*Xavier Noria*
|
248
|
-
|
249
|
-
* The payload of `transaction.active_record` Active Support notifications now has the transaction the event is related to in the `:transaction` key.
|
250
|
-
|
251
|
-
*Xavier Noria*
|
252
|
-
|
253
|
-
* 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.
|
254
|
-
|
255
|
-
*Xavier Noria*
|
256
|
-
|
257
|
-
* Fix inference of association model on nested models with the same demodularized name.
|
258
|
-
|
259
|
-
E.g. with the following setup:
|
96
|
+
* Support use of alternative database interfaces via the `database_cli` ActiveRecord configuration option.
|
260
97
|
|
261
98
|
```ruby
|
262
|
-
|
263
|
-
|
99
|
+
Rails.application.configure do
|
100
|
+
config.active_record.database_cli = { postgresql: "pgcli" }
|
264
101
|
end
|
265
102
|
```
|
266
103
|
|
267
|
-
|
104
|
+
*T S Vallender*
|
268
105
|
|
269
|
-
|
106
|
+
* Add support for dumping table inheritance and native partitioning table definitions for PostgeSQL adapter
|
270
107
|
|
271
|
-
*
|
108
|
+
*Justin Talbott*
|
272
109
|
|
273
|
-
|
110
|
+
* Add support for `ActiveRecord::Point` type casts using `Hash` values
|
274
111
|
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
*fatkodima*
|
280
|
-
|
281
|
-
* Support `touch_all` in batches.
|
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.
|
282
116
|
|
283
117
|
```ruby
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
* Add support for `:if_not_exists` and `:force` options to `create_schema`.
|
290
|
-
|
291
|
-
*fatkodima*
|
292
|
-
|
293
|
-
* Fix `index_errors` having incorrect index in association validation errors.
|
294
|
-
|
295
|
-
*lulalala*
|
296
|
-
|
297
|
-
* Add `index_errors: :nested_attributes_order` mode.
|
298
|
-
|
299
|
-
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.
|
300
|
-
|
301
|
-
*lulalala*
|
302
|
-
|
303
|
-
* Add `Rails.application.config.active_record.postgresql_adapter_decode_dates` to opt out of decoding dates automatically with the postgresql adapter. Defaults to true.
|
304
|
-
|
305
|
-
*Joé Dupuis*
|
306
|
-
|
307
|
-
* Association option `query_constraints` is deprecated in favor of `foreign_key`.
|
308
|
-
|
309
|
-
*Nikita Vasilevsky*
|
310
|
-
|
311
|
-
* Add `ENV["SKIP_TEST_DATABASE_TRUNCATE"]` flag to speed up multi-process test runs on large DBs when all tests run within default transaction.
|
312
|
-
|
313
|
-
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.
|
314
|
-
|
315
|
-
*DHH*
|
316
|
-
|
317
|
-
* Added support for recursive common table expressions.
|
318
|
-
|
319
|
-
```ruby
|
320
|
-
Post.with_recursive(
|
321
|
-
post_and_replies: [
|
322
|
-
Post.where(id: 42),
|
323
|
-
Post.joins('JOIN post_and_replies ON posts.in_reply_to_id = post_and_replies.id'),
|
324
|
-
]
|
325
|
-
)
|
326
|
-
```
|
327
|
-
|
328
|
-
Generates the following SQL:
|
329
|
-
|
330
|
-
```sql
|
331
|
-
WITH RECURSIVE "post_and_replies" AS (
|
332
|
-
(SELECT "posts".* FROM "posts" WHERE "posts"."id" = 42)
|
333
|
-
UNION ALL
|
334
|
-
(SELECT "posts".* FROM "posts" JOIN post_and_replies ON posts.in_reply_to_id = post_and_replies.id)
|
335
|
-
)
|
336
|
-
SELECT "posts".* FROM "posts"
|
337
|
-
```
|
338
|
-
|
339
|
-
*ClearlyClaire*
|
340
|
-
|
341
|
-
* `validate_constraint` can be called in a `change_table` block.
|
342
|
-
|
343
|
-
ex:
|
344
|
-
```ruby
|
345
|
-
change_table :products do |t|
|
346
|
-
t.check_constraint "price > discounted_price", name: "price_check", validate: false
|
347
|
-
t.validate_check_constraint "price_check"
|
118
|
+
class PostgresqlPoint < ActiveRecord::Base
|
119
|
+
attribute :x, :point
|
120
|
+
attribute :y, :point
|
121
|
+
attribute :z, :point
|
348
122
|
end
|
349
|
-
```
|
350
|
-
|
351
|
-
*Cody Cutrer*
|
352
123
|
|
353
|
-
|
354
|
-
|
355
|
-
|
356
|
-
|
357
|
-
|
358
|
-
|
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
|
359
130
|
```
|
360
131
|
|
361
|
-
*
|
362
|
-
|
363
|
-
* Strict loading using `:n_plus_one_only` does not eagerly load child associations.
|
132
|
+
*Stephen Drew*
|
364
133
|
|
365
|
-
|
366
|
-
match intended behavior and to prevent non-deterministic order issues caused
|
367
|
-
by calling methods like `first` or `last`. As `first` and `last` don't cause
|
368
|
-
an N+1 by themselves, calling child associations will no longer raise.
|
369
|
-
Fixes #49473.
|
134
|
+
* Replace `SQLite3::Database#busy_timeout` with `#busy_handler_timeout=`.
|
370
135
|
|
371
|
-
|
136
|
+
Provides a non-GVL-blocking, fair retry interval busy handler implementation.
|
372
137
|
|
373
|
-
|
374
|
-
person = Person.find(1)
|
375
|
-
person.strict_loading!(mode: :n_plus_one_only)
|
376
|
-
person.posts.first
|
377
|
-
# SELECT * FROM posts WHERE person_id = 1; -- non-deterministic order
|
378
|
-
person.posts.first.firm # raises ActiveRecord::StrictLoadingViolationError
|
379
|
-
```
|
138
|
+
*Stephen Margheim*
|
380
139
|
|
381
|
-
|
140
|
+
* SQLite3Adapter: Translate `SQLite3::BusyException` into `ActiveRecord::StatementTimeout`.
|
382
141
|
|
383
|
-
|
384
|
-
person = Person.find(1)
|
385
|
-
person.strict_loading!(mode: :n_plus_one_only)
|
386
|
-
person.posts.first # this is 1+1, not N+1
|
387
|
-
# SELECT * FROM posts WHERE person_id = 1 ORDER BY id LIMIT 1;
|
388
|
-
person.posts.first.firm # no longer raises
|
389
|
-
```
|
390
|
-
|
391
|
-
*Reid Lynch*
|
142
|
+
*Matthew Nguyen*
|
392
143
|
|
393
|
-
*
|
144
|
+
* Include schema name in `enable_extension` statements in `db/schema.rb`.
|
394
145
|
|
395
|
-
|
146
|
+
The schema dumper will now include the schema name in generated
|
147
|
+
`enable_extension` statements if they differ from the current schema.
|
396
148
|
|
397
|
-
|
149
|
+
For example, if you have a migration:
|
398
150
|
|
399
151
|
```ruby
|
400
|
-
|
401
|
-
|
402
|
-
|
403
|
-
# After
|
404
|
-
Post.joins(:comments).pluck(posts: [:id], comments: [:id, :body])
|
152
|
+
enable_extension "heroku_ext.pgcrypto"
|
153
|
+
enable_extension "pg_stat_statements"
|
405
154
|
```
|
406
155
|
|
407
|
-
|
408
|
-
|
409
|
-
* Raise an `ActiveRecord::ActiveRecordError` error when the MySQL database returns an invalid version string.
|
410
|
-
|
411
|
-
*Kevin McPhillips*
|
412
|
-
|
413
|
-
* `ActiveRecord::Base.transaction` now yields an `ActiveRecord::Transaction` object.
|
414
|
-
|
415
|
-
This allows to register callbacks on it.
|
156
|
+
then the generated schema dump will also contain:
|
416
157
|
|
417
158
|
```ruby
|
418
|
-
|
419
|
-
|
420
|
-
transaction.after_commit do
|
421
|
-
PublishNotificationMailer.with(article: article).deliver_later
|
422
|
-
end
|
423
|
-
end
|
159
|
+
enable_extension "heroku_ext.pgcrypto"
|
160
|
+
enable_extension "pg_stat_statements"
|
424
161
|
```
|
425
162
|
|
426
|
-
*
|
427
|
-
|
428
|
-
* Add `ActiveRecord::Base.current_transaction`.
|
163
|
+
*Tony Novak*
|
429
164
|
|
430
|
-
|
165
|
+
* Fix `ActiveRecord::Encryption::EncryptedAttributeType#type` to return
|
166
|
+
actual cast type.
|
431
167
|
|
432
|
-
|
433
|
-
Article.current_transaction.after_commit do
|
434
|
-
PublishNotificationMailer.with(article: article).deliver_later
|
435
|
-
end
|
436
|
-
```
|
168
|
+
*Vasiliy Ermolovich*
|
437
169
|
|
438
|
-
|
170
|
+
* SQLite3Adapter: Bulk insert fixtures.
|
439
171
|
|
440
|
-
|
172
|
+
Previously one insert command was executed for each fixture, now they are
|
173
|
+
aggregated in a single bulk insert command.
|
441
174
|
|
442
|
-
|
443
|
-
to perform work after the state changes have been properly persisted.
|
175
|
+
*Lázaro Nixon*
|
444
176
|
|
445
|
-
|
446
|
-
def publish_article(article)
|
447
|
-
article.update(published: true)
|
448
|
-
ActiveRecord.after_all_transactions_commit do
|
449
|
-
PublishNotificationMailer.with(article: article).deliver_later
|
450
|
-
end
|
451
|
-
end
|
452
|
-
```
|
177
|
+
* PostgreSQLAdapter: Allow `disable_extension` to be called with schema-qualified name.
|
453
178
|
|
454
|
-
|
455
|
-
|
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"`.
|
456
183
|
|
457
|
-
|
184
|
+
*Tony Novak*
|
458
185
|
|
459
|
-
|
186
|
+
* Make `create_schema` / `drop_schema` reversible in migrations.
|
460
187
|
|
461
|
-
|
188
|
+
Previously, `create_schema` and `drop_schema` were irreversible migration operations.
|
462
189
|
|
463
|
-
|
464
|
-
values must be backfilled separately of the column addition (to not lock the table for too long)
|
465
|
-
and before the use of `:counter_cache` (otherwise methods like `size`/`any?`/etc, which use
|
466
|
-
counter caches internally, can produce incorrect results). People usually use database triggers
|
467
|
-
or callbacks on child associations while backfilling before introducing a counter cache
|
468
|
-
configuration to the association.
|
190
|
+
*Tony Novak*
|
469
191
|
|
470
|
-
|
192
|
+
* Support batching using custom columns.
|
471
193
|
|
472
194
|
```ruby
|
473
|
-
|
474
|
-
|
195
|
+
Product.in_batches(cursor: [:shop_id, :id]) do |relation|
|
196
|
+
# do something with relation
|
475
197
|
end
|
476
198
|
```
|
477
199
|
|
478
|
-
While the counter cache is not "active", the methods like `size`/`any?`/etc will not use it,
|
479
|
-
but get the results directly from the database. After the counter cache column is backfilled, simply
|
480
|
-
remove the `{ active: false }` part from the counter cache definition, and it will now be used by the
|
481
|
-
mentioned methods.
|
482
|
-
|
483
200
|
*fatkodima*
|
484
201
|
|
485
|
-
*
|
486
|
-
|
487
|
-
SELECT queries we construct by walking the Arel tree and / or with known model attributes
|
488
|
-
are idempotent and can safely be retried in the case of a connection error. Previously,
|
489
|
-
adapters such as `TrilogyAdapter` would raise `ActiveRecord::ConnectionFailed: Trilogy::EOFError`
|
490
|
-
when encountering a connection error mid-request.
|
491
|
-
|
492
|
-
*Adrianna Chang*
|
493
|
-
|
494
|
-
* Allow association's `foreign_key` to be composite.
|
495
|
-
|
496
|
-
`query_constraints` option was the only way to configure a composite foreign key by passing an `Array`.
|
497
|
-
Now it's possible to pass an Array value as `foreign_key` to achieve the same behavior of an association.
|
498
|
-
|
499
|
-
*Nikita Vasilevsky*
|
202
|
+
* Use SQLite `IMMEDIATE` transactions when possible.
|
500
203
|
|
501
|
-
|
204
|
+
Transactions run against the SQLite3 adapter default to IMMEDIATE mode to improve concurrency support and avoid busy exceptions.
|
502
205
|
|
503
|
-
|
504
|
-
Now it's possible to explicitly set it as composite on the association.
|
505
|
-
|
506
|
-
*Nikita Vasilevsky*
|
507
|
-
|
508
|
-
* Add `config.active_record.permanent_connection_checkout` setting.
|
509
|
-
|
510
|
-
Controls whether `ActiveRecord::Base.connection` raises an error, emits a deprecation warning, or neither.
|
511
|
-
|
512
|
-
`ActiveRecord::Base.connection` checkouts a database connection from the pool and keeps it leased until the end of
|
513
|
-
the request or job. This behavior can be undesirable in environments that use many more threads or fibers than there
|
514
|
-
is available connections.
|
515
|
-
|
516
|
-
This configuration can be used to track down and eliminate code that calls `ActiveRecord::Base.connection` and
|
517
|
-
migrate it to use `ActiveRecord::Base.with_connection` instead.
|
518
|
-
|
519
|
-
The default behavior remains unchanged, and there is currently no plans to change the default.
|
520
|
-
|
521
|
-
*Jean Boussier*
|
522
|
-
|
523
|
-
* Add dirties option to uncached.
|
524
|
-
|
525
|
-
This adds a `dirties` option to `ActiveRecord::Base.uncached` and
|
526
|
-
`ActiveRecord::ConnectionAdapters::ConnectionPool#uncached`.
|
527
|
-
|
528
|
-
When set to `true` (the default), writes will clear all query caches belonging to the current thread.
|
529
|
-
When set to `false`, writes to the affected connection pool will not clear any query cache.
|
530
|
-
|
531
|
-
This is needed by Solid Cache so that cache writes do not clear query caches.
|
532
|
-
|
533
|
-
*Donal McBreen*
|
534
|
-
|
535
|
-
* Deprecate `ActiveRecord::Base.connection` in favor of `.lease_connection`.
|
536
|
-
|
537
|
-
The method has been renamed as `lease_connection` to better reflect that the returned
|
538
|
-
connection will be held for the duration of the request or job.
|
539
|
-
|
540
|
-
This deprecation is a soft deprecation, no warnings will be issued and there is no
|
541
|
-
current plan to remove the method.
|
542
|
-
|
543
|
-
*Jean Boussier*
|
544
|
-
|
545
|
-
* Deprecate `ActiveRecord::ConnectionAdapters::ConnectionPool#connection`.
|
546
|
-
|
547
|
-
The method has been renamed as `lease_connection` to better reflect that the returned
|
548
|
-
connection will be held for the duration of the request or job.
|
206
|
+
*Stephen Margheim*
|
549
207
|
|
550
|
-
|
208
|
+
* Raise specific exception when a connection is not defined.
|
551
209
|
|
552
|
-
|
210
|
+
The new `ConnectionNotDefined` exception provides connection name, shard and role accessors indicating the details of the connection that was requested.
|
553
211
|
|
554
|
-
|
555
|
-
assert_equal "Ruby on Rails", web_sites(:rubyonrails).name
|
556
|
-
assert_equal "Ruby on Rails", fixture(:web_sites, :rubyonrails).name
|
557
|
-
```
|
212
|
+
*Hana Harencarova*, *Matthew Draper*
|
558
213
|
|
559
|
-
|
560
|
-
|
561
|
-
* Using `Model.query_constraints` with a single non-primary-key column used to raise as expected, but with an
|
562
|
-
incorrect error message.
|
214
|
+
* Delete the deprecated constant `ActiveRecord::ImmutableRelation`.
|
563
215
|
|
564
|
-
|
216
|
+
*Xavier Noria*
|
565
217
|
|
566
|
-
|
218
|
+
* Fix duplicate callback execution when child autosaves parent with `has_one` and `belongs_to`.
|
567
219
|
|
568
|
-
|
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.
|
569
222
|
|
570
|
-
|
571
|
-
an `ActiveRecord::ReadonlyAttributeError` when the foreign key attribute is marked as read-only.
|
223
|
+
Now, these callbacks are only executed once as expected.
|
572
224
|
|
573
225
|
*Joshua Young*
|
574
226
|
|
575
|
-
*
|
576
|
-
|
577
|
-
*Rafael Mendonça França*
|
578
|
-
|
579
|
-
* Deprecate `Rails.application.config.active_record.commit_transaction_on_non_local_return`.
|
580
|
-
|
581
|
-
*Rafael Mendonça França*
|
582
|
-
|
583
|
-
* Remove deprecated support to pass `rewhere` to `ActiveRecord::Relation#merge`.
|
584
|
-
|
585
|
-
*Rafael Mendonça França*
|
586
|
-
|
587
|
-
* Remove deprecated support to pass `deferrable: true` to `add_foreign_key`.
|
588
|
-
|
589
|
-
*Rafael Mendonça França*
|
590
|
-
|
591
|
-
* Remove deprecated support to quote `ActiveSupport::Duration`.
|
592
|
-
|
593
|
-
*Rafael Mendonça França*
|
594
|
-
|
595
|
-
* Remove deprecated `#quote_bound_value`.
|
596
|
-
|
597
|
-
*Rafael Mendonça França*
|
598
|
-
|
599
|
-
* Remove deprecated `ActiveRecord::ConnectionAdapters::ConnectionPool#connection_klass`.
|
600
|
-
|
601
|
-
*Rafael Mendonça França*
|
602
|
-
|
603
|
-
* Remove deprecated support to apply `#connection_pool_list`, `#active_connections?`, `#clear_active_connections!`,
|
604
|
-
`#clear_reloadable_connections!`, `#clear_all_connections!` and `#flush_idle_connections!` to the connections pools
|
605
|
-
for the current role when the `role` argument isn't provided.
|
606
|
-
|
607
|
-
*Rafael Mendonça França*
|
608
|
-
|
609
|
-
* Remove deprecated `#all_connection_pools`.
|
610
|
-
|
611
|
-
*Rafael Mendonça França*
|
612
|
-
|
613
|
-
* Remove deprecated `ActiveRecord::ConnectionAdapters::SchemaCache#data_sources`.
|
614
|
-
|
615
|
-
*Rafael Mendonça França*
|
616
|
-
|
617
|
-
* Remove deprecated `ActiveRecord::ConnectionAdapters::SchemaCache.load_from`.
|
618
|
-
|
619
|
-
*Rafael Mendonça França*
|
620
|
-
|
621
|
-
* Remove deprecated `#all_foreign_keys_valid?` from database adapters.
|
622
|
-
|
623
|
-
*Rafael Mendonça França*
|
624
|
-
|
625
|
-
* Remove deprecated support to passing coder and class as second argument to `serialize`.
|
626
|
-
|
627
|
-
*Rafael Mendonça França*
|
628
|
-
|
629
|
-
* Remove deprecated support to `ActiveRecord::Base#read_attribute(:id)` to return the custom primary key value.
|
630
|
-
|
631
|
-
*Rafael Mendonça França*
|
632
|
-
|
633
|
-
* Remove deprecated `TestFixtures.fixture_path`.
|
634
|
-
|
635
|
-
*Rafael Mendonça França*
|
636
|
-
|
637
|
-
* Remove deprecated behavior to support referring to a singular association by its plural name.
|
638
|
-
|
639
|
-
*Rafael Mendonça França*
|
640
|
-
|
641
|
-
* Deprecate `Rails.application.config.active_record.allow_deprecated_singular_associations_name`.
|
642
|
-
|
643
|
-
*Rafael Mendonça França*
|
644
|
-
|
645
|
-
* Remove deprecated support to passing `SchemaMigration` and `InternalMetadata` classes as arguments to
|
646
|
-
`ActiveRecord::MigrationContext`.
|
647
|
-
|
648
|
-
*Rafael Mendonça França*
|
649
|
-
|
650
|
-
* Remove deprecated `ActiveRecord::Migration.check_pending!` method.
|
651
|
-
|
652
|
-
*Rafael Mendonça França*
|
653
|
-
|
654
|
-
* Remove deprecated `ActiveRecord::LogSubscriber.runtime` method.
|
655
|
-
|
656
|
-
*Rafael Mendonça França*
|
657
|
-
|
658
|
-
* Remove deprecated `ActiveRecord::LogSubscriber.runtime=` method.
|
659
|
-
|
660
|
-
*Rafael Mendonça França*
|
661
|
-
|
662
|
-
* Remove deprecated `ActiveRecord::LogSubscriber.reset_runtime` method.
|
663
|
-
|
664
|
-
*Rafael Mendonça França*
|
665
|
-
|
666
|
-
* Remove deprecated support to define `explain` in the connection adapter with 2 arguments.
|
667
|
-
|
668
|
-
*Rafael Mendonça França*
|
669
|
-
|
670
|
-
* Remove deprecated `ActiveRecord::ActiveJobRequiredError`.
|
671
|
-
|
672
|
-
*Rafael Mendonça França*
|
673
|
-
|
674
|
-
* Remove deprecated `ActiveRecord::Base.clear_active_connections!`.
|
675
|
-
|
676
|
-
*Rafael Mendonça França*
|
677
|
-
|
678
|
-
* Remove deprecated `ActiveRecord::Base.clear_reloadable_connections!`.
|
679
|
-
|
680
|
-
*Rafael Mendonça França*
|
681
|
-
|
682
|
-
* Remove deprecated `ActiveRecord::Base.clear_all_connections!`.
|
683
|
-
|
684
|
-
*Rafael Mendonça França*
|
685
|
-
|
686
|
-
* Remove deprecated `ActiveRecord::Base.flush_idle_connections!`.
|
687
|
-
|
688
|
-
*Rafael Mendonça França*
|
689
|
-
|
690
|
-
* Remove deprecated `name` argument from `ActiveRecord::Base.remove_connection`.
|
691
|
-
|
692
|
-
*Rafael Mendonça França*
|
693
|
-
|
694
|
-
* Remove deprecated support to call `alias_attribute` with non-existent attribute names.
|
695
|
-
|
696
|
-
*Rafael Mendonça França*
|
697
|
-
|
698
|
-
* Remove deprecated `Rails.application.config.active_record.suppress_multiple_database_warning`.
|
699
|
-
|
700
|
-
*Rafael Mendonça França*
|
701
|
-
|
702
|
-
* Add `ActiveRecord::Encryption::MessagePackMessageSerializer`.
|
703
|
-
|
704
|
-
Serialize data to the MessagePack format, for efficient storage in binary columns.
|
705
|
-
|
706
|
-
The binary encoding requires around 30% less space than the base64 encoding
|
707
|
-
used by the default serializer.
|
708
|
-
|
709
|
-
*Donal McBreen*
|
710
|
-
|
711
|
-
* Add support for encrypting binary columns.
|
712
|
-
|
713
|
-
Ensure encryption and decryption pass `Type::Binary::Data` around for binary data.
|
714
|
-
|
715
|
-
Previously encrypting binary columns with the `ActiveRecord::Encryption::MessageSerializer`
|
716
|
-
incidentally worked for MySQL and SQLite, but not PostgreSQL.
|
717
|
-
|
718
|
-
*Donal McBreen*
|
719
|
-
|
720
|
-
* Deprecated `ENV["SCHEMA_CACHE"]` in favor of `schema_cache_path` in the database configuration.
|
721
|
-
|
722
|
-
*Rafael Mendonça França*
|
723
|
-
|
724
|
-
* Add `ActiveRecord::Base.with_connection` as a shortcut for leasing a connection for a short duration.
|
725
|
-
|
726
|
-
The leased connection is yielded, and for the duration of the block, any call to `ActiveRecord::Base.connection`
|
727
|
-
will yield that same connection.
|
728
|
-
|
729
|
-
This is useful to perform a few database operations without causing a connection to be leased for the
|
730
|
-
entire duration of the request or job.
|
731
|
-
|
732
|
-
*Jean Boussier*
|
733
|
-
|
734
|
-
* Deprecate `config.active_record.warn_on_records_fetched_greater_than` now that `sql.active_record`
|
735
|
-
notification includes `:row_count` field.
|
736
|
-
|
737
|
-
*Jason Nochlin*
|
738
|
-
|
739
|
-
* The fix ensures that the association is joined using the appropriate join type
|
740
|
-
(either inner join or left outer join) based on the existing joins in the scope.
|
741
|
-
|
742
|
-
This prevents unintentional overrides of existing join types and ensures consistency in the generated SQL queries.
|
743
|
-
|
744
|
-
Example:
|
745
|
-
|
746
|
-
|
227
|
+
* `ActiveRecord::Encryption::Encryptor` now supports a `:compressor` option to customize the compression algorithm used.
|
747
228
|
|
748
229
|
```ruby
|
749
|
-
|
750
|
-
|
751
|
-
|
752
|
-
|
753
|
-
*Saleh Alhaddad*
|
754
|
-
|
755
|
-
* Fix an issue where `ActiveRecord::Encryption` configurations are not ready before the loading
|
756
|
-
of Active Record models, when an application is eager loaded. As a result, encrypted attributes
|
757
|
-
could be misconfigured in some cases.
|
758
|
-
|
759
|
-
*Maxime Réty*
|
760
|
-
|
761
|
-
* Deprecate defining an `enum` with keyword arguments.
|
230
|
+
module ZstdCompressor
|
231
|
+
def self.deflate(data)
|
232
|
+
Zstd.compress(data)
|
233
|
+
end
|
762
234
|
|
763
|
-
|
764
|
-
|
765
|
-
|
766
|
-
enum color: [:red, :blue],
|
767
|
-
type: [:instance, :class]
|
768
|
-
|
769
|
-
# GOOD
|
770
|
-
enum :color, [:red, :blue]
|
771
|
-
enum :type, [:instance, :class]
|
235
|
+
def self.inflate(data)
|
236
|
+
Zstd.decompress(data)
|
237
|
+
end
|
772
238
|
end
|
773
|
-
```
|
774
|
-
|
775
|
-
*Hartley McGuire*
|
776
|
-
|
777
|
-
* Add `config.active_record.validate_migration_timestamps` option for validating migration timestamps.
|
778
|
-
|
779
|
-
When set, validates that the timestamp prefix for a migration is no more than a day ahead of
|
780
|
-
the timestamp associated with the current time. This is designed to prevent migrations prefixes
|
781
|
-
from being hand-edited to future timestamps, which impacts migration generation and other
|
782
|
-
migration commands.
|
783
239
|
|
784
|
-
|
785
|
-
|
786
|
-
|
787
|
-
|
788
|
-
As well as `disconnect!` and `verify!`.
|
789
|
-
|
790
|
-
This generally isn't a big problem as connections must not be shared between
|
791
|
-
threads, but is required when running transactional tests or system tests
|
792
|
-
and could lead to a SEGV.
|
793
|
-
|
794
|
-
*Jean Boussier*
|
795
|
-
|
796
|
-
* Support `:source_location` tag option for query log tags.
|
797
|
-
|
798
|
-
```ruby
|
799
|
-
config.active_record.query_log_tags << :source_location
|
240
|
+
class User
|
241
|
+
encrypts :name, compressor: ZstdCompressor
|
242
|
+
end
|
800
243
|
```
|
801
244
|
|
802
|
-
|
803
|
-
(note, there is also a `config.active_record.verbose_query_logs` that serves the same purpose)
|
804
|
-
or occasionally on production for debugging purposes.
|
805
|
-
|
806
|
-
*fatkodima*
|
807
|
-
|
808
|
-
* Add an option to `ActiveRecord::Encryption::Encryptor` to disable compression.
|
809
|
-
|
810
|
-
Allow compression to be disabled by setting `compress: false`
|
245
|
+
You disable compression by passing `compress: false`.
|
811
246
|
|
812
247
|
```ruby
|
813
|
-
|
814
|
-
|
815
|
-
|
248
|
+
class User
|
249
|
+
encrypts :name, compress: false
|
250
|
+
end
|
816
251
|
```
|
817
252
|
|
818
|
-
*
|
819
|
-
|
820
|
-
* Deprecate passing strings to `ActiveRecord::Tasks::DatabaseTasks.cache_dump_filename`.
|
821
|
-
|
822
|
-
A `ActiveRecord::DatabaseConfigurations::DatabaseConfig` object should be passed instead.
|
823
|
-
|
824
|
-
*Rafael Mendonça França*
|
825
|
-
|
826
|
-
* Add `row_count` field to `sql.active_record` notification.
|
827
|
-
|
828
|
-
This field returns the amount of rows returned by the query that emitted the notification.
|
829
|
-
|
830
|
-
This metric is useful in cases where one wants to detect queries with big result sets.
|
831
|
-
|
832
|
-
*Marvin Bitterlich*
|
833
|
-
|
834
|
-
* Consistently raise an `ArgumentError` when passing an invalid argument to a nested attributes association writer.
|
835
|
-
|
836
|
-
Previously, this would only raise on collection associations and produce a generic error on singular associations.
|
837
|
-
|
838
|
-
Now, it will raise on both collection and singular associations.
|
839
|
-
|
840
|
-
*Joshua Young*
|
841
|
-
|
842
|
-
* Fix single quote escapes on default generated MySQL columns.
|
253
|
+
*heka1024*
|
843
254
|
|
844
|
-
|
845
|
-
|
846
|
-
Previously, the schema dump would output a string with double escapes for generated columns with single quotes in the default expression.
|
847
|
-
|
848
|
-
This would result in issues when importing the schema on a fresh instance of a MySQL database.
|
849
|
-
|
850
|
-
Now, the string will not be escaped and will be valid Ruby upon importing of the schema.
|
851
|
-
|
852
|
-
*Yash Kapadia*
|
853
|
-
|
854
|
-
* Fix Migrations with versions older than 7.1 validating options given to
|
855
|
-
`add_reference` and `t.references`.
|
255
|
+
* Add condensed `#inspect` for `ConnectionPool`, `AbstractAdapter`, and
|
256
|
+
`DatabaseConfig`.
|
856
257
|
|
857
258
|
*Hartley McGuire*
|
858
259
|
|
859
|
-
* Add
|
860
|
-
|
861
|
-
*JP Rosevear*
|
862
|
-
|
863
|
-
* Make `schema_dump`, `query_cache`, `replica` and `database_tasks` configurable via `DATABASE_URL`.
|
864
|
-
|
865
|
-
This wouldn't always work previously because boolean values would be interpreted as strings.
|
866
|
-
|
867
|
-
e.g. `DATABASE_URL=postgres://localhost/foo?schema_dump=false` now properly disable dumping the schema
|
868
|
-
cache.
|
869
|
-
|
870
|
-
*Mike Coutermarsh*, *Jean Boussier*
|
871
|
-
|
872
|
-
* Introduce `ActiveRecord::Transactions::ClassMethods#set_callback`.
|
873
|
-
|
874
|
-
It is identical to `ActiveSupport::Callbacks::ClassMethods#set_callback`
|
875
|
-
but with support for `after_commit` and `after_rollback` callback options.
|
876
|
-
|
877
|
-
*Joshua Young*
|
878
|
-
|
879
|
-
* Make `ActiveRecord::Encryption::Encryptor` agnostic of the serialization format used for encrypted data.
|
880
|
-
|
881
|
-
Previously, the encryptor instance only allowed an encrypted value serialized as a `String` to be passed to the message serializer.
|
882
|
-
|
883
|
-
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`.
|
884
|
-
|
885
|
-
The default `ActiveRecord::Encryption::MessageSerializer` already ensures that only `String` objects are passed for deserialization.
|
886
|
-
|
887
|
-
*Maxime Réty*
|
888
|
-
|
889
|
-
* Fix `encrypted_attribute?` to take into account context properties passed to `encrypts`.
|
890
|
-
|
891
|
-
*Maxime Réty*
|
892
|
-
|
893
|
-
* The object returned by `explain` now responds to `pluck`, `first`,
|
894
|
-
`last`, `average`, `count`, `maximum`, `minimum`, and `sum`. Those
|
895
|
-
new methods run `EXPLAIN` on the corresponding queries:
|
260
|
+
* Add `.shard_keys`, `.sharded?`, & `.connected_to_all_shards` methods.
|
896
261
|
|
897
262
|
```ruby
|
898
|
-
|
899
|
-
|
900
|
-
# ...
|
901
|
-
|
902
|
-
User.all.explain.maximum(:id)
|
903
|
-
# EXPLAIN SELECT MAX(`users`.`id`) FROM `users`
|
904
|
-
# ...
|
905
|
-
```
|
906
|
-
|
907
|
-
*Petrik de Heus*
|
908
|
-
|
909
|
-
* Fixes an issue where `validates_associated` `:on` option wasn't respected
|
910
|
-
when validating associated records.
|
911
|
-
|
912
|
-
*Austen Madden*, *Alex Ghiculescu*, *Rafał Brize*
|
913
|
-
|
914
|
-
* Allow overriding SQLite defaults from `database.yml`.
|
915
|
-
|
916
|
-
Any PRAGMA configuration set under the `pragmas` key in the configuration
|
917
|
-
file takes precedence over Rails' defaults, and additional PRAGMAs can be
|
918
|
-
set as well.
|
919
|
-
|
920
|
-
```yaml
|
921
|
-
database: storage/development.sqlite3
|
922
|
-
timeout: 5000
|
923
|
-
pragmas:
|
924
|
-
journal_mode: off
|
925
|
-
temp_store: memory
|
926
|
-
```
|
927
|
-
|
928
|
-
*Stephen Margheim*
|
929
|
-
|
930
|
-
* Remove warning message when running SQLite in production, but leave it unconfigured.
|
931
|
-
|
932
|
-
There are valid use cases for running SQLite in production. However, it must be done
|
933
|
-
with care, so instead of a warning most users won't see anyway, it's preferable to
|
934
|
-
leave the configuration commented out to force them to think about having the database
|
935
|
-
on a persistent volume etc.
|
936
|
-
|
937
|
-
*Jacopo Beschi*, *Jean Boussier*
|
938
|
-
|
939
|
-
* Add support for generated columns to the SQLite3 adapter.
|
940
|
-
|
941
|
-
Generated columns (both stored and dynamic) are supported since version 3.31.0 of SQLite.
|
942
|
-
This adds support for those to the SQLite3 adapter.
|
263
|
+
class ShardedBase < ActiveRecord::Base
|
264
|
+
self.abstract_class = true
|
943
265
|
|
944
|
-
|
945
|
-
|
946
|
-
|
947
|
-
|
948
|
-
t.virtual :name_lower, type: :string, as: 'LOWER(name)', stored: true
|
266
|
+
connects_to shards: {
|
267
|
+
shard_one: { writing: :shard_one },
|
268
|
+
shard_two: { writing: :shard_two }
|
269
|
+
}
|
949
270
|
end
|
950
|
-
```
|
951
|
-
|
952
|
-
*Stephen Margheim*
|
953
|
-
|
954
|
-
* TrilogyAdapter: ignore `host` if `socket` parameter is set.
|
955
|
-
|
956
|
-
This allows to configure a connection on a UNIX socket via `DATABASE_URL`:
|
957
|
-
|
958
|
-
```
|
959
|
-
DATABASE_URL=trilogy://does-not-matter/my_db_production?socket=/var/run/mysql.sock
|
960
|
-
```
|
961
|
-
|
962
|
-
*Jean Boussier*
|
963
|
-
|
964
|
-
* Make `assert_queries_count`, `assert_no_queries`, `assert_queries_match`, and
|
965
|
-
`assert_no_queries_match` assertions public.
|
966
|
-
|
967
|
-
To assert the expected number of queries are made, Rails internally uses `assert_queries_count` and
|
968
|
-
`assert_no_queries`. To assert that specific SQL queries are made, `assert_queries_match` and
|
969
|
-
`assert_no_queries_match` are used. These assertions can now be used in applications as well.
|
970
|
-
|
971
|
-
```ruby
|
972
|
-
class ArticleTest < ActiveSupport::TestCase
|
973
|
-
test "queries are made" do
|
974
|
-
assert_queries_count(1) { Article.first }
|
975
|
-
end
|
976
271
|
|
977
|
-
|
978
|
-
assert_queries_match(/ADD FOREIGN KEY/i, include_schema: true) do
|
979
|
-
@connection.add_foreign_key(:comments, :posts)
|
980
|
-
end
|
981
|
-
end
|
272
|
+
class ShardedModel < ShardedBase
|
982
273
|
end
|
983
|
-
```
|
984
|
-
|
985
|
-
*Petrik de Heus*, *fatkodima*
|
986
|
-
|
987
|
-
* Fix `has_secure_token` calls the setter method on initialize.
|
988
|
-
|
989
|
-
*Abeid Ahmed*
|
990
274
|
|
991
|
-
|
992
|
-
|
993
|
-
|
994
|
-
|
995
|
-
```ruby
|
996
|
-
# ENV['DATABASE_URL'] = "mysql://localhost/example_database"
|
997
|
-
config.active_record.protocol_adapters.mysql = "trilogy"
|
998
|
-
# will connect to MySQL using the trilogy adapter
|
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]
|
999
278
|
```
|
1000
279
|
|
1001
|
-
*
|
1002
|
-
|
1003
|
-
* In cases where MySQL returns `warning_count` greater than zero, but returns no warnings when
|
1004
|
-
the `SHOW WARNINGS` query is executed, `ActiveRecord.db_warnings_action` proc will still be
|
1005
|
-
called with a generic warning message rather than silently ignoring the warning(s).
|
1006
|
-
|
1007
|
-
*Kevin McPhillips*
|
1008
|
-
|
1009
|
-
* `DatabaseConfigurations#configs_for` accepts a symbol in the `name` parameter.
|
1010
|
-
|
1011
|
-
*Andrew Novoselac*
|
1012
|
-
|
1013
|
-
* Fix `where(field: values)` queries when `field` is a serialized attribute
|
1014
|
-
(for example, when `field` uses `ActiveRecord::Base.serialize` or is a JSON
|
1015
|
-
column).
|
1016
|
-
|
1017
|
-
*João Alves*
|
280
|
+
*Nony Dutton*
|
1018
281
|
|
1019
|
-
*
|
282
|
+
* Add a `filter` option to `in_order_of` to prioritize certain values in the sorting without filtering the results
|
283
|
+
by these values.
|
1020
284
|
|
1021
|
-
|
285
|
+
*Igor Depolli*
|
1022
286
|
|
1023
|
-
|
1024
|
-
|
1025
|
-
```
|
1026
|
-
|
1027
|
-
The attributes to be included in the output of `inspect` can be configured with
|
1028
|
-
`ActiveRecord::Core#attributes_for_inspect`.
|
1029
|
-
|
1030
|
-
```ruby
|
1031
|
-
Post.attributes_for_inspect = [:id, :title]
|
1032
|
-
Post.first.inspect #=> "#<Post id: 1, title: "Hello, World!">"
|
1033
|
-
```
|
287
|
+
* Fix an issue where the IDs reader method did not return expected results
|
288
|
+
for preloaded associations in models using composite primary keys.
|
1034
289
|
|
1035
|
-
|
290
|
+
*Jay Ang*
|
1036
291
|
|
1037
|
-
|
1038
|
-
Post.attributes_for_inspect = :all
|
1039
|
-
Post.first.inspect #=> "#<Post id: 1, title: "Hello, World!", published_at: "2023-10-23 14:28:11 +0000">"
|
1040
|
-
```
|
292
|
+
* Allow to configure `strict_loading_mode` globally or within a model.
|
1041
293
|
|
1042
|
-
|
294
|
+
Defaults to `:all`, can be changed to `:n_plus_one_only`.
|
1043
295
|
|
1044
|
-
|
296
|
+
*Garen Torikian*
|
1045
297
|
|
1046
|
-
|
298
|
+
* Add `ActiveRecord::Relation#readonly?`.
|
1047
299
|
|
1048
|
-
|
300
|
+
Reflects if the relation has been marked as readonly.
|
1049
301
|
|
1050
|
-
*
|
1051
|
-
`-Float::INFINITY`.
|
302
|
+
*Theodor Tonum*
|
1052
303
|
|
1053
|
-
|
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`.
|
1054
307
|
|
1055
|
-
|
308
|
+
Previously, a `NoMethodError` would be raised when the accessor was read or written:
|
1056
309
|
|
1057
|
-
|
310
|
+
NoMethodError: undefined method `accessor' for an instance of ActiveRecord::Type::Text
|
1058
311
|
|
1059
|
-
|
312
|
+
Now, a descriptive `ConfigurationError` is raised:
|
1060
313
|
|
1061
|
-
|
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.
|
1062
317
|
|
1063
|
-
|
1064
|
-
add_reference :person, :alias, foreign_key: { deferrable: :deferred }
|
1065
|
-
add_reference :alias, :person, foreign_key: { deferrable: :deferred }
|
1066
|
-
```
|
318
|
+
*Mike Dalessio*
|
1067
319
|
|
1068
|
-
|
320
|
+
* Fix inference of association model on nested models with the same demodularized name.
|
1069
321
|
|
1070
|
-
|
322
|
+
E.g. with the following setup:
|
1071
323
|
|
1072
324
|
```ruby
|
1073
|
-
Post
|
1074
|
-
|
1075
|
-
Post.transaction do
|
1076
|
-
Post.connection.set_constraints(:deferred)
|
1077
|
-
p = Post.create!(user_id: -1)
|
1078
|
-
u = User.create!
|
1079
|
-
p.user = u
|
1080
|
-
p.save!
|
325
|
+
class Nested::Post < ApplicationRecord
|
326
|
+
has_one :post, through: :other
|
1081
327
|
end
|
1082
328
|
```
|
1083
329
|
|
1084
|
-
|
1085
|
-
|
1086
|
-
* Include `ActiveModel::API` in `ActiveRecord::Base`.
|
1087
|
-
|
1088
|
-
*Sean Doyle*
|
1089
|
-
|
1090
|
-
* Ensure `#signed_id` outputs `url_safe` strings.
|
1091
|
-
|
1092
|
-
*Jason Meller*
|
330
|
+
Before, `#post` would infer the model as `Nested::Post`, but now it correctly infers `Post`.
|
1093
331
|
|
1094
|
-
*
|
332
|
+
*Joshua Young*
|
1095
333
|
|
1096
|
-
|
334
|
+
* Add public method for checking if a table is ignored by the schema cache.
|
1097
335
|
|
1098
|
-
|
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.
|
1099
337
|
|
1100
338
|
```ruby
|
1101
|
-
|
339
|
+
ActiveRecord.schema_cache_ignored_tables = ["developers"]
|
340
|
+
ActiveRecord.schema_cache_ignored_table?("developers")
|
341
|
+
=> true
|
1102
342
|
```
|
1103
343
|
|
1104
|
-
*
|
344
|
+
*Eileen M. Uchitelle*
|
1105
345
|
|
1106
|
-
Please check [7-
|
346
|
+
Please check [7-2-stable](https://github.com/rails/rails/blob/7-2-stable/activerecord/CHANGELOG.md) for previous changes.
|