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