activerecord 7.1.4.1 → 7.2.2.1
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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +643 -2274
- data/README.rdoc +15 -15
- data/examples/performance.rb +2 -2
- data/lib/active_record/association_relation.rb +1 -1
- data/lib/active_record/associations/alias_tracker.rb +25 -19
- data/lib/active_record/associations/association.rb +15 -8
- data/lib/active_record/associations/belongs_to_association.rb +14 -7
- data/lib/active_record/associations/belongs_to_polymorphic_association.rb +3 -2
- data/lib/active_record/associations/builder/belongs_to.rb +1 -0
- data/lib/active_record/associations/builder/has_and_belongs_to_many.rb +2 -2
- data/lib/active_record/associations/builder/has_many.rb +3 -4
- data/lib/active_record/associations/builder/has_one.rb +3 -4
- data/lib/active_record/associations/collection_association.rb +7 -1
- data/lib/active_record/associations/collection_proxy.rb +14 -1
- data/lib/active_record/associations/errors.rb +265 -0
- data/lib/active_record/associations/has_many_association.rb +1 -1
- data/lib/active_record/associations/has_many_through_association.rb +7 -1
- data/lib/active_record/associations/join_dependency/join_association.rb +30 -27
- data/lib/active_record/associations/join_dependency.rb +4 -4
- data/lib/active_record/associations/nested_error.rb +47 -0
- data/lib/active_record/associations/preloader/association.rb +2 -1
- data/lib/active_record/associations/preloader/branch.rb +7 -1
- data/lib/active_record/associations/preloader/through_association.rb +1 -3
- data/lib/active_record/associations/singular_association.rb +6 -0
- data/lib/active_record/associations/through_association.rb +1 -1
- data/lib/active_record/associations.rb +59 -292
- data/lib/active_record/attribute_assignment.rb +0 -2
- data/lib/active_record/attribute_methods/composite_primary_key.rb +84 -0
- data/lib/active_record/attribute_methods/primary_key.rb +23 -55
- data/lib/active_record/attribute_methods/read.rb +1 -13
- data/lib/active_record/attribute_methods/serialization.rb +4 -24
- data/lib/active_record/attribute_methods/time_zone_conversion.rb +11 -6
- data/lib/active_record/attribute_methods.rb +54 -63
- data/lib/active_record/attributes.rb +61 -47
- data/lib/active_record/autosave_association.rb +12 -29
- data/lib/active_record/base.rb +2 -3
- data/lib/active_record/callbacks.rb +1 -1
- data/lib/active_record/connection_adapters/abstract/connection_handler.rb +24 -107
- data/lib/active_record/connection_adapters/abstract/connection_pool/reaper.rb +1 -0
- data/lib/active_record/connection_adapters/abstract/connection_pool.rb +270 -65
- data/lib/active_record/connection_adapters/abstract/database_statements.rb +34 -17
- data/lib/active_record/connection_adapters/abstract/query_cache.rb +189 -74
- data/lib/active_record/connection_adapters/abstract/quoting.rb +65 -91
- data/lib/active_record/connection_adapters/abstract/schema_definitions.rb +1 -1
- data/lib/active_record/connection_adapters/abstract/schema_statements.rb +15 -6
- data/lib/active_record/connection_adapters/abstract/transaction.rb +125 -62
- data/lib/active_record/connection_adapters/abstract_adapter.rb +24 -44
- data/lib/active_record/connection_adapters/abstract_mysql_adapter.rb +40 -10
- data/lib/active_record/connection_adapters/mysql/database_statements.rb +9 -1
- data/lib/active_record/connection_adapters/mysql/quoting.rb +43 -48
- data/lib/active_record/connection_adapters/mysql/schema_statements.rb +6 -0
- data/lib/active_record/connection_adapters/mysql2/database_statements.rb +16 -15
- data/lib/active_record/connection_adapters/mysql2_adapter.rb +5 -23
- data/lib/active_record/connection_adapters/pool_config.rb +7 -6
- data/lib/active_record/connection_adapters/postgresql/database_statements.rb +27 -4
- data/lib/active_record/connection_adapters/postgresql/oid/cidr.rb +1 -1
- data/lib/active_record/connection_adapters/postgresql/oid/interval.rb +1 -1
- data/lib/active_record/connection_adapters/postgresql/oid/uuid.rb +14 -4
- data/lib/active_record/connection_adapters/postgresql/quoting.rb +58 -58
- data/lib/active_record/connection_adapters/postgresql/schema_definitions.rb +20 -0
- data/lib/active_record/connection_adapters/postgresql/schema_statements.rb +17 -11
- data/lib/active_record/connection_adapters/postgresql_adapter.rb +29 -24
- data/lib/active_record/connection_adapters/schema_cache.rb +123 -128
- data/lib/active_record/connection_adapters/sqlite3/column.rb +14 -1
- data/lib/active_record/connection_adapters/sqlite3/database_statements.rb +10 -6
- data/lib/active_record/connection_adapters/sqlite3/quoting.rb +44 -46
- data/lib/active_record/connection_adapters/sqlite3/schema_creation.rb +22 -0
- data/lib/active_record/connection_adapters/sqlite3/schema_definitions.rb +13 -0
- data/lib/active_record/connection_adapters/sqlite3/schema_dumper.rb +16 -0
- data/lib/active_record/connection_adapters/sqlite3/schema_statements.rb +25 -2
- data/lib/active_record/connection_adapters/sqlite3_adapter.rb +125 -75
- data/lib/active_record/connection_adapters/trilogy/database_statements.rb +15 -15
- data/lib/active_record/connection_adapters/trilogy_adapter.rb +19 -48
- data/lib/active_record/connection_adapters.rb +121 -0
- data/lib/active_record/connection_handling.rb +56 -41
- data/lib/active_record/core.rb +86 -38
- data/lib/active_record/counter_cache.rb +18 -9
- data/lib/active_record/database_configurations/connection_url_resolver.rb +8 -3
- data/lib/active_record/database_configurations/database_config.rb +19 -4
- data/lib/active_record/database_configurations/hash_config.rb +38 -34
- data/lib/active_record/database_configurations/url_config.rb +20 -1
- data/lib/active_record/database_configurations.rb +1 -1
- data/lib/active_record/delegated_type.rb +24 -0
- data/lib/active_record/dynamic_matchers.rb +2 -2
- data/lib/active_record/encryption/encryptable_record.rb +3 -3
- data/lib/active_record/encryption/encrypted_attribute_type.rb +24 -4
- data/lib/active_record/encryption/encryptor.rb +18 -3
- data/lib/active_record/encryption/key_provider.rb +1 -1
- data/lib/active_record/encryption/message_pack_message_serializer.rb +76 -0
- data/lib/active_record/encryption/message_serializer.rb +4 -0
- data/lib/active_record/encryption/null_encryptor.rb +4 -0
- data/lib/active_record/encryption/read_only_null_encryptor.rb +4 -0
- data/lib/active_record/encryption.rb +2 -0
- data/lib/active_record/enum.rb +19 -2
- data/lib/active_record/errors.rb +46 -20
- data/lib/active_record/explain.rb +13 -24
- data/lib/active_record/fixtures.rb +37 -31
- data/lib/active_record/future_result.rb +8 -4
- data/lib/active_record/gem_version.rb +2 -2
- data/lib/active_record/inheritance.rb +4 -2
- data/lib/active_record/insert_all.rb +18 -15
- data/lib/active_record/integration.rb +4 -1
- data/lib/active_record/internal_metadata.rb +48 -34
- data/lib/active_record/locking/optimistic.rb +7 -6
- data/lib/active_record/log_subscriber.rb +0 -21
- data/lib/active_record/marshalling.rb +4 -1
- data/lib/active_record/message_pack.rb +1 -1
- data/lib/active_record/migration/command_recorder.rb +2 -3
- data/lib/active_record/migration/compatibility.rb +5 -3
- data/lib/active_record/migration/default_strategy.rb +4 -5
- data/lib/active_record/migration/pending_migration_connection.rb +2 -2
- data/lib/active_record/migration.rb +85 -76
- data/lib/active_record/model_schema.rb +32 -68
- data/lib/active_record/nested_attributes.rb +24 -5
- data/lib/active_record/normalization.rb +3 -7
- data/lib/active_record/persistence.rb +30 -352
- data/lib/active_record/query_cache.rb +19 -8
- data/lib/active_record/query_logs.rb +15 -0
- data/lib/active_record/querying.rb +21 -9
- data/lib/active_record/railtie.rb +42 -57
- data/lib/active_record/railties/controller_runtime.rb +13 -4
- data/lib/active_record/railties/databases.rake +40 -43
- data/lib/active_record/reflection.rb +98 -36
- data/lib/active_record/relation/batches/batch_enumerator.rb +15 -2
- data/lib/active_record/relation/batches.rb +14 -8
- data/lib/active_record/relation/calculations.rb +96 -63
- data/lib/active_record/relation/delegation.rb +8 -11
- data/lib/active_record/relation/finder_methods.rb +16 -2
- data/lib/active_record/relation/merger.rb +4 -6
- data/lib/active_record/relation/predicate_builder/array_handler.rb +2 -2
- data/lib/active_record/relation/predicate_builder/association_query_value.rb +9 -3
- data/lib/active_record/relation/predicate_builder.rb +3 -3
- data/lib/active_record/relation/query_methods.rb +224 -58
- data/lib/active_record/relation/record_fetch_warning.rb +3 -0
- data/lib/active_record/relation/spawn_methods.rb +2 -18
- data/lib/active_record/relation/where_clause.rb +7 -19
- data/lib/active_record/relation.rb +496 -72
- data/lib/active_record/result.rb +31 -44
- data/lib/active_record/runtime_registry.rb +39 -0
- data/lib/active_record/sanitization.rb +24 -19
- data/lib/active_record/schema.rb +8 -6
- data/lib/active_record/schema_dumper.rb +19 -9
- data/lib/active_record/schema_migration.rb +30 -14
- data/lib/active_record/scoping/named.rb +1 -0
- data/lib/active_record/signed_id.rb +20 -1
- data/lib/active_record/statement_cache.rb +7 -7
- data/lib/active_record/table_metadata.rb +1 -10
- data/lib/active_record/tasks/database_tasks.rb +81 -42
- data/lib/active_record/tasks/mysql_database_tasks.rb +1 -1
- data/lib/active_record/tasks/postgresql_database_tasks.rb +1 -1
- data/lib/active_record/tasks/sqlite_database_tasks.rb +2 -1
- data/lib/active_record/test_fixtures.rb +86 -89
- data/lib/active_record/testing/query_assertions.rb +121 -0
- data/lib/active_record/timestamp.rb +2 -2
- data/lib/active_record/token_for.rb +22 -12
- data/lib/active_record/touch_later.rb +1 -1
- data/lib/active_record/transaction.rb +132 -0
- data/lib/active_record/transactions.rb +70 -14
- data/lib/active_record/translation.rb +0 -2
- data/lib/active_record/type/serialized.rb +1 -3
- data/lib/active_record/type_caster/connection.rb +4 -4
- data/lib/active_record/validations/associated.rb +9 -3
- data/lib/active_record/validations/uniqueness.rb +15 -10
- data/lib/active_record/validations.rb +4 -1
- data/lib/active_record.rb +148 -39
- data/lib/arel/alias_predication.rb +1 -1
- data/lib/arel/collectors/bind.rb +2 -0
- data/lib/arel/collectors/composite.rb +7 -0
- data/lib/arel/collectors/sql_string.rb +1 -1
- data/lib/arel/collectors/substitute_binds.rb +1 -1
- data/lib/arel/nodes/binary.rb +0 -6
- data/lib/arel/nodes/bound_sql_literal.rb +9 -5
- data/lib/arel/nodes/{and.rb → nary.rb} +5 -2
- data/lib/arel/nodes/node.rb +4 -3
- data/lib/arel/nodes/sql_literal.rb +7 -0
- data/lib/arel/nodes.rb +2 -2
- data/lib/arel/predications.rb +1 -1
- data/lib/arel/select_manager.rb +1 -1
- data/lib/arel/tree_manager.rb +3 -2
- data/lib/arel/update_manager.rb +2 -1
- data/lib/arel/visitors/dot.rb +1 -0
- data/lib/arel/visitors/mysql.rb +9 -4
- data/lib/arel/visitors/postgresql.rb +1 -12
- data/lib/arel/visitors/sqlite.rb +25 -0
- data/lib/arel/visitors/to_sql.rb +29 -16
- data/lib/arel.rb +7 -3
- data/lib/rails/generators/active_record/migration/templates/create_table_migration.rb.tt +4 -1
- metadata +18 -12
data/CHANGELOG.md
CHANGED
@@ -1,2729 +1,1098 @@
|
|
1
|
-
## Rails 7.
|
1
|
+
## Rails 7.2.2.1 (December 10, 2024) ##
|
2
2
|
|
3
3
|
* No changes.
|
4
4
|
|
5
5
|
|
6
|
-
## Rails 7.
|
6
|
+
## Rails 7.2.2 (October 30, 2024) ##
|
7
7
|
|
8
|
-
*
|
8
|
+
* Fix support for `query_cache: false` in `database.yml`.
|
9
9
|
|
10
|
-
|
10
|
+
`query_cache: false` would no longer entirely disable the Active Record query cache.
|
11
11
|
|
12
|
-
*
|
12
|
+
*zzak*
|
13
13
|
|
14
|
-
|
14
|
+
* Set `.attributes_for_inspect` to `:all` by default.
|
15
15
|
|
16
|
-
|
16
|
+
For new applications it is set to `[:id]` in config/environment/production.rb.
|
17
17
|
|
18
|
-
|
18
|
+
In the console all the attributes are always shown.
|
19
19
|
|
20
|
-
*
|
20
|
+
*Andrew Novoselac*
|
21
21
|
|
22
|
-
|
22
|
+
* `PG::UnableToSend: no connection to the server` is now retryable as a connection-related exception
|
23
23
|
|
24
|
-
*
|
24
|
+
*Kazuma Watanabe*
|
25
25
|
|
26
|
-
|
26
|
+
* Fix marshalling of unsaved associated records in 7.1 format.
|
27
27
|
|
28
|
-
|
28
|
+
The 7.1 format would only marshal associated records if the association was loaded.
|
29
|
+
But associations that would only contain unsaved records would be skipped.
|
29
30
|
|
30
31
|
*Jean Boussier*
|
31
32
|
|
32
|
-
* Fix
|
33
|
-
|
34
|
-
*Joel Lubrano*
|
35
|
-
|
36
|
-
* Fix running migrations on other databases when `database_tasks: false` on primary.
|
37
|
-
|
38
|
-
*fatkodima*
|
39
|
-
|
40
|
-
* Fix non-partial inserts for models with composite identity primary keys.
|
41
|
-
|
42
|
-
*fatkodima*
|
43
|
-
|
44
|
-
* Fix `ActiveRecord::Relation#touch_all` with custom attribute aliased as attribute for update.
|
45
|
-
|
46
|
-
*fatkodima*
|
47
|
-
|
48
|
-
* Fix a crash when an Executor wrapped fork exit.
|
49
|
-
|
50
|
-
*Joé Dupuis*
|
51
|
-
|
52
|
-
* Fix `destroy_async` job for owners with composite primary keys.
|
53
|
-
|
54
|
-
*fatkodima*
|
55
|
-
|
56
|
-
* Ensure pre-7.1 migrations use legacy index names when using `rename_table`.
|
57
|
-
|
58
|
-
*fatkodima*
|
59
|
-
|
60
|
-
* Allow `primary_key:` association option to be composite.
|
61
|
-
|
62
|
-
*Nikita Vasilevsky*
|
63
|
-
|
64
|
-
* Do not try to alias on key update when raw SQL is supplied.
|
65
|
-
|
66
|
-
*Gabriel Amaral*
|
67
|
-
|
68
|
-
* Memoize `key_provider` from `key` or deterministic `key_provider` if any.
|
33
|
+
* Fix incorrect SQL query when passing an empty hash to `ActiveRecord::Base.insert`.
|
69
34
|
|
70
|
-
*
|
35
|
+
*David Stosik*
|
71
36
|
|
72
|
-
*
|
37
|
+
* Allow to save records with polymorphic join tables that have `inverse_of`
|
38
|
+
specified.
|
73
39
|
|
74
|
-
*
|
75
|
-
|
76
|
-
* Fix predicate builder for polymorphic models referencing models with composite primary keys.
|
77
|
-
|
78
|
-
*fatkodima*
|
79
|
-
|
80
|
-
* Fix `update_all/delete_all` on CPK model relation with join subquery.
|
81
|
-
|
82
|
-
*Nikita Vasilevsky*
|
83
|
-
|
84
|
-
* Remove memoization to accept `key_provider` overridden by `with_encryption_context`.
|
85
|
-
|
86
|
-
*John Hawthorn*
|
87
|
-
|
88
|
-
* Raise error for Trilogy when prepared_statements is true.
|
89
|
-
|
90
|
-
Trilogy doesn't currently support prepared statements. The error that
|
91
|
-
applications would see is a `StatementInvalid` error. This doesn't quite point
|
92
|
-
you to the fact this isn't supported. So raise a more appropriate error
|
93
|
-
pointing to what to change.
|
94
|
-
|
95
|
-
*Eileen M. Uchitelle*
|
96
|
-
|
97
|
-
* Fix loading schema cache when all databases have disabled database tasks.
|
98
|
-
|
99
|
-
*fatkodima*
|
100
|
-
|
101
|
-
* Always request `primary_key` in `RETURNING` if no other columns requested.
|
40
|
+
*Markus Doits*
|
102
41
|
|
103
|
-
|
42
|
+
* Fix association scopes applying on the incorrect join when using a polymorphic `has_many through:`.
|
104
43
|
|
105
|
-
*
|
44
|
+
*Joshua Young*
|
106
45
|
|
107
|
-
|
108
|
-
a serialized instance, it didn't trigger loading the schema and defining
|
109
|
-
attribute methods.
|
46
|
+
* Fix `dependent: :destroy` for bi-directional has one through association.
|
110
47
|
|
111
|
-
|
48
|
+
Fixes #50948.
|
112
49
|
|
113
|
-
|
50
|
+
```ruby
|
51
|
+
class Left < ActiveRecord::Base
|
52
|
+
has_one :middle, dependent: :destroy
|
53
|
+
has_one :right, through: :middle
|
54
|
+
end
|
114
55
|
|
115
|
-
|
56
|
+
class Middle < ActiveRecord::Base
|
57
|
+
belongs_to :left, dependent: :destroy
|
58
|
+
belongs_to :right, dependent: :destroy
|
59
|
+
end
|
116
60
|
|
117
|
-
|
61
|
+
class Right < ActiveRecord::Base
|
62
|
+
has_one :middle, dependent: :destroy
|
63
|
+
has_one :left, through: :middle
|
64
|
+
end
|
65
|
+
```
|
66
|
+
In the above example `left.destroy` wouldn't destroy its associated `Right`
|
67
|
+
record.
|
118
68
|
|
119
|
-
|
120
|
-
they should have been.
|
69
|
+
*Andy Stewart*
|
121
70
|
|
122
|
-
|
71
|
+
* Properly handle lazily pinned connection pools.
|
123
72
|
|
124
|
-
|
73
|
+
Fixes #53147.
|
125
74
|
|
126
|
-
|
127
|
-
|
128
|
-
|
75
|
+
When using transactional fixtures with system tests to similar tools
|
76
|
+
such as capybara, it could happen that a connection end up pinned by the
|
77
|
+
server thread rather than the test thread, causing
|
78
|
+
`"Cannot expire connection, it is owned by a different thread"` errors.
|
129
79
|
|
130
80
|
*Jean Boussier*
|
131
81
|
|
132
|
-
* Fix
|
133
|
-
for preloaded associations in models using composite primary keys.
|
134
|
-
|
135
|
-
*Jay Ang*
|
136
|
-
|
137
|
-
* PostgreSQL `Cidr#change?` detects the address prefix change.
|
138
|
-
|
139
|
-
*Taketo Takashima*
|
140
|
-
|
141
|
-
* Fix Active Record serialization to not include instantiated but not loaded associations
|
142
|
-
|
143
|
-
*Jean Boussier*, *Ben Kyriakou*
|
144
|
-
|
145
|
-
* Allow `Sqlite3Adapter` to use `sqlite3` gem version `2.x`
|
146
|
-
|
147
|
-
*Mike Dalessio*
|
148
|
-
|
149
|
-
* Strict loading using `:n_plus_one_only` does not eagerly load child associations.
|
150
|
-
|
151
|
-
With this change, child associations are no longer eagerly loaded, to
|
152
|
-
match intended behavior and to prevent non-deterministic order issues caused
|
153
|
-
by calling methods like `first` or `last`. As `first` and `last` don't cause
|
154
|
-
an N+1 by themselves, calling child associations will no longer raise.
|
155
|
-
Fixes #49473.
|
156
|
-
|
157
|
-
Before:
|
82
|
+
* Fix `ActiveRecord::Base.with` to accept more than two sub queries.
|
158
83
|
|
159
|
-
|
160
|
-
person = Person.find(1)
|
161
|
-
person.strict_loading!(mode: :n_plus_one_only)
|
162
|
-
person.posts.first
|
163
|
-
# SELECT * FROM posts WHERE person_id = 1; -- non-deterministic order
|
164
|
-
person.posts.first.firm # raises ActiveRecord::StrictLoadingViolationError
|
165
|
-
```
|
166
|
-
|
167
|
-
After:
|
84
|
+
Fixes #53110.
|
168
85
|
|
169
86
|
```ruby
|
170
|
-
|
171
|
-
|
172
|
-
person.posts.first # this is 1+1, not N+1
|
173
|
-
# SELECT * FROM posts WHERE person_id = 1 ORDER BY id LIMIT 1;
|
174
|
-
person.posts.first.firm # no longer raises
|
87
|
+
User.with(foo: [User.select(:id), User.select(:id), User.select(:id)]).to_sql
|
88
|
+
undefined method `union' for an instance of Arel::Nodes::UnionAll (NoMethodError)
|
175
89
|
```
|
176
90
|
|
177
|
-
|
178
|
-
|
179
|
-
* Using `Model.query_constraints` with a single non-primary-key column used to raise as expected, but with an
|
180
|
-
incorrect error message. This has been fixed to raise with a more appropriate error message.
|
181
|
-
|
182
|
-
*Joshua Young*
|
183
|
-
|
184
|
-
* Fix `has_one` association autosave setting the foreign key attribute when it is unchanged.
|
185
|
-
|
186
|
-
This behaviour is also inconsistent with autosaving `belongs_to` and can have unintended side effects like raising
|
187
|
-
an `ActiveRecord::ReadonlyAttributeError` when the foreign key attribute is marked as read-only.
|
188
|
-
|
189
|
-
*Joshua Young*
|
190
|
-
|
191
|
-
* Fix an issue where `ActiveRecord::Encryption` configurations are not ready before the loading
|
192
|
-
of Active Record models, when an application is eager loaded. As a result, encrypted attributes
|
193
|
-
could be misconfigured in some cases.
|
194
|
-
|
195
|
-
*Maxime Réty*
|
196
|
-
|
197
|
-
* Properly synchronize `Mysql2Adapter#active?` and `TrilogyAdapter#active?`
|
198
|
-
|
199
|
-
As well as `disconnect!` and `verify!`.
|
200
|
-
|
201
|
-
This generally isn't a big problem as connections must not be shared between
|
202
|
-
threads, but is required when running transactional tests or system tests
|
203
|
-
and could lead to a SEGV.
|
204
|
-
|
205
|
-
*Jean Boussier*
|
206
|
-
|
207
|
-
* Fix counter caches when the foreign key is composite.
|
208
|
-
|
209
|
-
If the model holding the counter cache had a composite primary key,
|
210
|
-
inserting a dependent record would fail with an `ArgumentError`
|
211
|
-
`Expected corresponding value for...`
|
91
|
+
The above now works as expected.
|
212
92
|
|
213
93
|
*fatkodima*
|
214
94
|
|
215
|
-
*
|
216
|
-
|
217
|
-
Before this change, if you have multiple databases configured in your
|
218
|
-
application, and had schema cache present, Rails would load the same
|
219
|
-
cache to all databases.
|
220
|
-
|
221
|
-
*Rafael Mendonça França*
|
95
|
+
* Properly release pinned connections with non joinable connections.
|
222
96
|
|
223
|
-
|
97
|
+
Fixes #52973
|
224
98
|
|
225
|
-
|
226
|
-
|
99
|
+
When running system tests with transactional fixtures on, it could happen that
|
100
|
+
the connection leased by the Puma thread wouldn't be properly released back to the pool,
|
101
|
+
causing "Cannot expire connection, it is owned by a different thread" errors in later tests.
|
227
102
|
|
228
|
-
*
|
103
|
+
*Jean Boussier*
|
229
104
|
|
230
|
-
*
|
105
|
+
* Make Float distinguish between `float4` and `float8` in PostgreSQL.
|
231
106
|
|
232
|
-
|
107
|
+
Fixes #52742
|
233
108
|
|
234
|
-
*
|
109
|
+
*Ryota Kitazawa*, *Takayuki Nagatomi*
|
235
110
|
|
236
|
-
|
111
|
+
* Fix an issue where `.left_outer_joins` used with multiple associations that have
|
112
|
+
the same child association but different parents does not join all parents.
|
237
113
|
|
238
|
-
Previously,
|
114
|
+
Previously, using `.left_outer_joins` with the same child association would only join one of the parents.
|
239
115
|
|
240
|
-
|
116
|
+
Now it will correctly join both parents.
|
241
117
|
|
242
|
-
|
118
|
+
Fixes #41498.
|
243
119
|
|
244
|
-
*
|
120
|
+
*Garrett Blehm*
|
245
121
|
|
246
|
-
*
|
247
|
-
`t.references`.
|
122
|
+
* Ensure `ActiveRecord::Encryption.config` is always ready before access.
|
248
123
|
|
249
|
-
|
124
|
+
Previously, `ActiveRecord::Encryption` configuration was deferred until `ActiveRecord::Base`
|
125
|
+
was loaded. Therefore, accessing `ActiveRecord::Encryption.config` properties before
|
126
|
+
`ActiveRecord::Base` was loaded would give incorrect results.
|
250
127
|
|
128
|
+
`ActiveRecord::Encryption` now has its own loading hook so that its configuration is set as
|
129
|
+
soon as needed.
|
251
130
|
|
252
|
-
|
131
|
+
When `ActiveRecord::Base` is loaded, even lazily, it in turn triggers the loading of
|
132
|
+
`ActiveRecord::Encryption`, thus preserving the original behavior of having its config ready
|
133
|
+
before any use of `ActiveRecord::Base`.
|
253
134
|
|
254
|
-
*
|
135
|
+
*Maxime Réty*
|
255
136
|
|
137
|
+
* Add `TimeZoneConverter#==` method, so objects will be properly compared by
|
138
|
+
their type, scale, limit & precision.
|
256
139
|
|
257
|
-
|
140
|
+
Address #52699.
|
258
141
|
|
259
|
-
*
|
142
|
+
*Ruy Rocha*
|
260
143
|
|
261
144
|
|
262
|
-
## Rails 7.1.
|
145
|
+
## Rails 7.2.1.2 (October 23, 2024) ##
|
263
146
|
|
264
147
|
* No changes.
|
265
148
|
|
266
149
|
|
267
|
-
## Rails 7.1.
|
150
|
+
## Rails 7.2.1.1 (October 15, 2024) ##
|
268
151
|
|
269
152
|
* No changes.
|
270
153
|
|
271
154
|
|
272
|
-
## Rails 7.1
|
273
|
-
|
274
|
-
* Fix Migrations with versions older than 7.1 validating options given to
|
275
|
-
`add_reference`.
|
276
|
-
|
277
|
-
*Hartley McGuire*
|
278
|
-
|
279
|
-
* Ensure `reload` sets correct owner for each association.
|
280
|
-
|
281
|
-
*Dmytro Savochkin*
|
155
|
+
## Rails 7.2.1 (August 22, 2024) ##
|
282
156
|
|
283
|
-
* Fix
|
284
|
-
|
285
|
-
*fatkodima*
|
286
|
-
|
287
|
-
* Fix `load_async` to work with query cache.
|
288
|
-
|
289
|
-
*fatkodima*
|
290
|
-
|
291
|
-
* Fix polymorphic `belongs_to` to correctly use parent's `query_constraints`.
|
292
|
-
|
293
|
-
*fatkodima*
|
294
|
-
|
295
|
-
* Fix `Preloader` to not generate a query for already loaded association with `query_constraints`.
|
296
|
-
|
297
|
-
*fatkodima*
|
298
|
-
|
299
|
-
* Fix multi-database polymorphic preloading with equivalent table names.
|
300
|
-
|
301
|
-
When preloading polymorphic associations, if two models pointed to two
|
302
|
-
tables with the same name but located in different databases, the
|
303
|
-
preloader would only load one.
|
304
|
-
|
305
|
-
*Ari Summer*
|
306
|
-
|
307
|
-
* Fix `encrypted_attribute?` to take into account context properties passed to `encrypts`.
|
157
|
+
* Fix detection for `enum` columns with parallelized tests and PostgreSQL.
|
308
158
|
|
309
|
-
*
|
159
|
+
*Rafael Mendonça França*
|
310
160
|
|
311
|
-
*
|
161
|
+
* Allow to eager load nested nil associations.
|
312
162
|
|
313
163
|
*fatkodima*
|
314
164
|
|
315
|
-
* Fix
|
316
|
-
|
317
|
-
`ShipPart.async_count` could return a raw integer rather than a Promise
|
318
|
-
if it found the result in the query cache.
|
165
|
+
* Fix swallowing ignore order warning when batching using `BatchEnumerator`.
|
319
166
|
|
320
167
|
*fatkodima*
|
321
168
|
|
322
|
-
* Fix
|
323
|
-
|
324
|
-
The method was incorrectly setting a default scope around its block:
|
325
|
-
|
326
|
-
```ruby
|
327
|
-
Post.where(published: true).transaction do
|
328
|
-
Post.count # SELECT COUNT(*) FROM posts WHERE published = FALSE;
|
329
|
-
end
|
330
|
-
```
|
331
|
-
|
332
|
-
*Jean Boussier*
|
333
|
-
|
334
|
-
* Fix calling `async_pluck` on a `none` relation.
|
335
|
-
|
336
|
-
`Model.none.async_pluck(:id)` was returning a naked value
|
337
|
-
instead of a promise.
|
169
|
+
* Fix memory bloat on the connection pool when using the Fiber `IsolatedExecutionState`.
|
338
170
|
|
339
171
|
*Jean Boussier*
|
340
172
|
|
341
|
-
*
|
342
|
-
|
343
|
-
`Model.none.load_async` was returning a broken result.
|
344
|
-
|
345
|
-
*Lucas Mazza*
|
346
|
-
|
347
|
-
* TrilogyAdapter: ignore `host` if `socket` parameter is set.
|
173
|
+
* Restore inferred association class with the same modularized name.
|
348
174
|
|
349
|
-
|
175
|
+
*Justin Ko*
|
350
176
|
|
351
|
-
|
352
|
-
DATABASE_URL=trilogy://does-not-matter/my_db_production?socket=/var/run/mysql.sock
|
353
|
-
```
|
177
|
+
* Fix `ActiveRecord::Base.inspect` to properly explain how to load schema information.
|
354
178
|
|
355
179
|
*Jean Boussier*
|
356
180
|
|
357
|
-
*
|
358
|
-
|
359
|
-
*Abeid Ahmed*
|
360
|
-
|
361
|
-
* Allow using `object_id` as a database column name.
|
362
|
-
It was available before rails 7.1 and may be used as a part of polymorphic relationship to `object` where `object` can be any other database record.
|
363
|
-
|
364
|
-
*Mikhail Doronin*
|
365
|
-
|
366
|
-
* Fix `rails db:create:all` to not touch databases before they are created.
|
367
|
-
|
368
|
-
*fatkodima*
|
369
|
-
|
370
|
-
|
371
|
-
## Rails 7.1.2 (November 10, 2023) ##
|
372
|
-
|
373
|
-
* Fix renaming primary key index when renaming a table with a UUID primary key
|
374
|
-
in PostgreSQL.
|
375
|
-
|
376
|
-
*fatkodima*
|
377
|
-
|
378
|
-
* Fix `where(field: values)` queries when `field` is a serialized attribute
|
379
|
-
(for example, when `field` uses `ActiveRecord::Base.serialize` or is a JSON
|
380
|
-
column).
|
381
|
-
|
382
|
-
*João Alves*
|
383
|
-
|
384
|
-
* Prevent marking broken connections as verified.
|
385
|
-
|
386
|
-
*Daniel Colson*
|
387
|
-
|
388
|
-
* Don't mark Float::INFINITY as changed when reassigning it
|
389
|
-
|
390
|
-
When saving a record with a float infinite value, it shouldn't mark as changed
|
391
|
-
|
392
|
-
*Maicol Bentancor*
|
393
|
-
|
394
|
-
* `ActiveRecord::Base.table_name` now returns `nil` instead of raising
|
395
|
-
"undefined method `abstract_class?` for Object:Class".
|
396
|
-
|
397
|
-
*a5-stable*
|
398
|
-
|
399
|
-
* Fix upserting for custom `:on_duplicate` and `:unique_by` consisting of all
|
400
|
-
inserts keys.
|
181
|
+
* Check invalid `enum` options for the new syntax.
|
401
182
|
|
402
|
-
|
403
|
-
|
404
|
-
* Fixed an [issue](https://github.com/rails/rails/issues/49809) where saving a
|
405
|
-
record could innappropriately `dup` its attributes.
|
406
|
-
|
407
|
-
*Jonathan Hefner*
|
408
|
-
|
409
|
-
* Dump schema only for a specific db for rollback/up/down tasks for multiple dbs.
|
410
|
-
|
411
|
-
*fatkodima*
|
412
|
-
|
413
|
-
* Fix `NoMethodError` when casting a PostgreSQL `money` value that uses a
|
414
|
-
comma as its radix point and has no leading currency symbol. For example,
|
415
|
-
when casting `"3,50"`.
|
416
|
-
|
417
|
-
*Andreas Reischuck* and *Jonathan Hefner*
|
183
|
+
The options using `_` prefix in the old syntax are invalid in the new syntax.
|
418
184
|
|
419
|
-
*
|
420
|
-
Non-column-backed attributes must be previously declared with an explicit
|
421
|
-
type. For example:
|
422
|
-
|
423
|
-
```ruby
|
424
|
-
class Post < ActiveRecord::Base
|
425
|
-
attribute :topic, :string
|
426
|
-
enum topic: %i[science tech engineering math]
|
427
|
-
end
|
428
|
-
```
|
429
|
-
|
430
|
-
*Jonathan Hefner*
|
185
|
+
*Rafael Mendonça França*
|
431
186
|
|
432
|
-
*
|
187
|
+
* Fix `ActiveRecord::Encryption::EncryptedAttributeType#type` to return
|
188
|
+
actual cast type.
|
433
189
|
|
434
|
-
*
|
190
|
+
*Vasiliy Ermolovich*
|
435
191
|
|
436
|
-
*
|
192
|
+
* Fix `create_table` with `:auto_increment` option for MySQL adapter.
|
437
193
|
|
438
194
|
*fatkodima*
|
439
195
|
|
440
|
-
* Fix detecting `IDENTITY` columns for PostgreSQL < 10.
|
441
|
-
|
442
|
-
*fatkodima*
|
443
196
|
|
197
|
+
## Rails 7.2.0 (August 09, 2024) ##
|
444
198
|
|
445
|
-
|
199
|
+
* Handle commas in Sqlite3 default function definitions.
|
446
200
|
|
447
|
-
*
|
201
|
+
*Stephen Margheim*
|
448
202
|
|
449
|
-
|
203
|
+
* Fixes `validates_associated` raising an exception when configured with a
|
204
|
+
singular association and having `index_nested_attribute_errors` enabled.
|
450
205
|
|
451
|
-
*
|
452
|
-
down migrating `rename_table` in older migrations.
|
206
|
+
*Martin Spickermann*
|
453
207
|
|
454
|
-
|
208
|
+
* The constant `ActiveRecord::ImmutableRelation` has been deprecated because
|
209
|
+
we want to reserve that name for a stronger sense of "immutable relation".
|
210
|
+
Please use `ActiveRecord::UnmodifiableRelation` instead.
|
455
211
|
|
456
|
-
*
|
457
|
-
to be present when running when running test on CI.
|
212
|
+
*Xavier Noria*
|
458
213
|
|
459
|
-
|
214
|
+
* Add condensed `#inspect` for `ConnectionPool`, `AbstractAdapter`, and
|
215
|
+
`DatabaseConfig`.
|
460
216
|
|
217
|
+
*Hartley McGuire*
|
461
218
|
|
462
|
-
|
219
|
+
* Fixed a memory performance issue in Active Record attribute methods definition.
|
463
220
|
|
464
|
-
*
|
221
|
+
*Jean Boussier*
|
465
222
|
|
223
|
+
* Define the new Active Support notification event `start_transaction.active_record`.
|
466
224
|
|
467
|
-
|
225
|
+
This event is fired when database transactions or savepoints start, and
|
226
|
+
complements `transaction.active_record`, which is emitted when they finish.
|
468
227
|
|
469
|
-
|
228
|
+
The payload has the transaction (`:transaction`) and the connection (`:connection`).
|
470
229
|
|
471
|
-
*
|
230
|
+
*Xavier Noria*
|
472
231
|
|
473
|
-
*
|
474
|
-
|
232
|
+
* Fix an issue where the IDs reader method did not return expected results
|
233
|
+
for preloaded associations in models using composite primary keys.
|
475
234
|
|
476
|
-
|
477
|
-
where overridden in the class that included the concern.
|
235
|
+
*Jay Ang*
|
478
236
|
|
479
|
-
|
237
|
+
* The payload of `sql.active_record` Active Support notifications now has the current transaction in the `:transaction` key.
|
480
238
|
|
239
|
+
*Xavier Noria*
|
481
240
|
|
482
|
-
|
241
|
+
* The payload of `transaction.active_record` Active Support notifications now has the transaction the event is related to in the `:transaction` key.
|
483
242
|
|
484
|
-
*
|
243
|
+
*Xavier Noria*
|
485
244
|
|
486
|
-
|
487
|
-
Just naming it unique constraints is not misleading.
|
245
|
+
* 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.
|
488
246
|
|
489
|
-
|
247
|
+
*Xavier Noria*
|
490
248
|
|
491
|
-
|
492
|
-
add_unique_key :sections, [:position], deferrable: :deferred, name: "unique_section_position"
|
493
|
-
remove_unique_key :sections, name: "unique_section_position"
|
494
|
-
```
|
249
|
+
* Fix inference of association model on nested models with the same demodularized name.
|
495
250
|
|
496
|
-
|
251
|
+
E.g. with the following setup:
|
497
252
|
|
498
253
|
```ruby
|
499
|
-
|
500
|
-
|
254
|
+
class Nested::Post < ApplicationRecord
|
255
|
+
has_one :post, through: :other
|
256
|
+
end
|
501
257
|
```
|
502
258
|
|
503
|
-
|
504
|
-
|
505
|
-
* Fix duplicate quoting for check constraint expressions in schema dump when using MySQL
|
506
|
-
|
507
|
-
A check constraint with an expression, that already contains quotes, lead to an invalid schema
|
508
|
-
dump with the mysql2 adapter.
|
259
|
+
Before, `#post` would infer the model as `Nested::Post`, but now it correctly infers `Post`.
|
509
260
|
|
510
|
-
|
511
|
-
|
512
|
-
*Felix Tscheulin*
|
513
|
-
|
514
|
-
* Performance tune the SQLite3 adapter connection configuration
|
515
|
-
|
516
|
-
For Rails applications, the Write-Ahead-Log in normal syncing mode with a capped journal size, a healthy shared memory buffer and a shared cache will perform, on average, 2× better.
|
517
|
-
|
518
|
-
*Stephen Margheim*
|
519
|
-
|
520
|
-
* Allow SQLite3 `busy_handler` to be configured with simple max number of `retries`
|
521
|
-
|
522
|
-
Retrying busy connections without delay is a preferred practice for performance-sensitive applications. Add support for a `database.yml` `retries` integer, which is used in a simple `busy_handler` function to retry busy connections without exponential backoff up to the max number of `retries`.
|
261
|
+
*Joshua Young*
|
523
262
|
|
524
|
-
|
263
|
+
* PostgreSQL `Cidr#change?` detects the address prefix change.
|
525
264
|
|
526
|
-
*
|
265
|
+
*Taketo Takashima*
|
527
266
|
|
528
|
-
|
267
|
+
* Change `BatchEnumerator#destroy_all` to return the total number of affected rows.
|
529
268
|
|
530
|
-
|
269
|
+
Previously, it always returned `nil`.
|
531
270
|
|
532
|
-
*
|
271
|
+
*fatkodima*
|
533
272
|
|
534
|
-
|
535
|
-
Now, the adapter will appropriately receive and use `"Ruby on Rails"`.
|
273
|
+
* Support `touch_all` in batches.
|
536
274
|
|
537
275
|
```ruby
|
538
|
-
|
276
|
+
Post.in_batches.touch_all
|
539
277
|
```
|
540
278
|
|
541
|
-
*Stephen Margheim*
|
542
|
-
|
543
|
-
* Dump PostgreSQL schemas as part of the schema dump.
|
544
|
-
|
545
|
-
*Lachlan Sylvester*
|
546
|
-
|
547
|
-
|
548
|
-
## Rails 7.1.0.beta1 (September 13, 2023) ##
|
549
|
-
|
550
|
-
* Encryption now supports `support_unencrypted_data` being set per-attribute.
|
551
|
-
|
552
|
-
You can now opt out of `support_unencrypted_data` on a specific encrypted attribute.
|
553
|
-
This only has an effect if `ActiveRecord::Encryption.config.support_unencrypted_data == true`.
|
554
|
-
|
555
|
-
```ruby
|
556
|
-
class User < ActiveRecord::Base
|
557
|
-
encrypts :name, deterministic: true, support_unencrypted_data: false
|
558
|
-
encrypts :email, deterministic: true
|
559
|
-
end
|
560
|
-
```
|
561
|
-
|
562
|
-
*Alex Ghiculescu*
|
563
|
-
|
564
|
-
* Add instrumentation for Active Record transactions
|
565
|
-
|
566
|
-
Allows subscribing to transaction events for tracking/instrumentation. The event payload contains the connection and the outcome (commit, rollback, restart, incomplete), as well as timing details.
|
567
|
-
|
568
|
-
```ruby
|
569
|
-
ActiveSupport::Notifications.subscribe("transaction.active_record") do |event|
|
570
|
-
puts "Transaction event occurred!"
|
571
|
-
connection = event.payload[:connection]
|
572
|
-
puts "Connection: #{connection.inspect}"
|
573
|
-
end
|
574
|
-
```
|
575
|
-
|
576
|
-
*Daniel Colson*, *Ian Candy*
|
577
|
-
|
578
|
-
* Support composite foreign keys via migration helpers.
|
579
|
-
|
580
|
-
```ruby
|
581
|
-
# Assuming "carts" table has "(shop_id, user_id)" as a primary key.
|
582
|
-
|
583
|
-
add_foreign_key(:orders, :carts, primary_key: [:shop_id, :user_id])
|
584
|
-
|
585
|
-
remove_foreign_key(:orders, :carts, primary_key: [:shop_id, :user_id])
|
586
|
-
foreign_key_exists?(:orders, :carts, primary_key: [:shop_id, :user_id])
|
587
|
-
```
|
588
|
-
|
589
|
-
*fatkodima*
|
590
|
-
|
591
|
-
* Adds support for `if_not_exists` when adding a check constraint.
|
592
|
-
|
593
|
-
```ruby
|
594
|
-
add_check_constraint :posts, "post_type IN ('blog', 'comment', 'share')", if_not_exists: true
|
595
|
-
```
|
596
|
-
|
597
|
-
*Cody Cutrer*
|
598
|
-
|
599
|
-
* Raise an `ArgumentError` when `#accepts_nested_attributes_for` is declared more than once for an association in
|
600
|
-
the same class. Previously, the last declaration would silently override the previous one. Overriding in a subclass
|
601
|
-
is still allowed.
|
602
|
-
|
603
|
-
*Joshua Young*
|
604
|
-
|
605
|
-
* Deprecate `rewhere` argument on `#merge`.
|
606
|
-
|
607
|
-
The `rewhere` argument on `#merge`is deprecated without replacement and
|
608
|
-
will be removed in Rails 7.2.
|
609
|
-
|
610
|
-
*Adam Hess*
|
611
|
-
|
612
|
-
* Deprecate aliasing non-attributes with `alias_attribute`.
|
613
|
-
|
614
|
-
*Ian Candy*
|
615
|
-
|
616
|
-
* Fix unscope is not working in specific case
|
617
|
-
|
618
|
-
Before:
|
619
|
-
```ruby
|
620
|
-
Post.where(id: 1...3).unscope(where: :id).to_sql # "SELECT `posts`.* FROM `posts` WHERE `posts`.`id` >= 1 AND `posts`.`id` < 3"
|
621
|
-
|
622
|
-
```
|
623
|
-
|
624
|
-
After:
|
625
|
-
```ruby
|
626
|
-
Post.where(id: 1...3).unscope(where: :id).to_sql # "SELECT `posts`.* FROM `posts`"
|
627
|
-
```
|
628
|
-
|
629
|
-
Fixes #48094.
|
630
|
-
|
631
|
-
*Kazuya Hatanaka*
|
632
|
-
|
633
|
-
* Change `has_secure_token` default to `on: :initialize`
|
634
|
-
|
635
|
-
Change the new default value from `on: :create` to `on: :initialize`
|
636
|
-
|
637
|
-
Can be controlled by the `config.active_record.generate_secure_token_on`
|
638
|
-
configuration:
|
639
|
-
|
640
|
-
```ruby
|
641
|
-
config.active_record.generate_secure_token_on = :create
|
642
|
-
```
|
643
|
-
|
644
|
-
*Sean Doyle*
|
645
|
-
|
646
|
-
* Fix `change_column` not setting `precision: 6` on `datetime` columns when
|
647
|
-
using 7.0+ Migrations and SQLite.
|
648
|
-
|
649
|
-
*Hartley McGuire*
|
650
|
-
|
651
|
-
* Support composite identifiers in `to_key`
|
652
|
-
|
653
|
-
`to_key` avoids wrapping `#id` value into an `Array` if `#id` already an array
|
654
|
-
|
655
|
-
*Nikita Vasilevsky*
|
656
|
-
|
657
|
-
* Add validation option for `enum`
|
658
|
-
|
659
|
-
```ruby
|
660
|
-
class Contract < ApplicationRecord
|
661
|
-
enum :status, %w[in_progress completed], validate: true
|
662
|
-
end
|
663
|
-
Contract.new(status: "unknown").valid? # => false
|
664
|
-
Contract.new(status: nil).valid? # => false
|
665
|
-
Contract.new(status: "completed").valid? # => true
|
666
|
-
|
667
|
-
class Contract < ApplicationRecord
|
668
|
-
enum :status, %w[in_progress completed], validate: { allow_nil: true }
|
669
|
-
end
|
670
|
-
Contract.new(status: "unknown").valid? # => false
|
671
|
-
Contract.new(status: nil).valid? # => true
|
672
|
-
Contract.new(status: "completed").valid? # => true
|
673
|
-
```
|
674
|
-
|
675
|
-
*Edem Topuzov*, *Ryuta Kamizono*
|
676
|
-
|
677
|
-
* Allow batching methods to use already loaded relation if available
|
678
|
-
|
679
|
-
Calling batch methods on already loaded relations will use the records previously loaded instead of retrieving
|
680
|
-
them from the database again.
|
681
|
-
|
682
|
-
*Adam Hess*
|
683
|
-
|
684
|
-
* Deprecate `read_attribute(:id)` returning the primary key if the primary key is not `:id`.
|
685
|
-
|
686
|
-
Starting in Rails 7.2, `read_attribute(:id)` will return the value of the id column, regardless of the model's
|
687
|
-
primary key. To retrieve the value of the primary key, use `#id` instead. `read_attribute(:id)` for composite
|
688
|
-
primary key models will now return the value of the id column.
|
689
|
-
|
690
|
-
*Adrianna Chang*
|
691
|
-
|
692
|
-
* Fix `change_table` setting datetime precision for 6.1 Migrations
|
693
|
-
|
694
|
-
*Hartley McGuire*
|
695
|
-
|
696
|
-
* Fix change_column setting datetime precision for 6.1 Migrations
|
697
|
-
|
698
|
-
*Hartley McGuire*
|
699
|
-
|
700
|
-
* Add `ActiveRecord::Base#id_value` alias to access the raw value of a record's id column.
|
701
|
-
|
702
|
-
This alias is only provided for models that declare an `:id` column.
|
703
|
-
|
704
|
-
*Adrianna Chang*
|
705
|
-
|
706
|
-
* Fix previous change tracking for `ActiveRecord::Store` when using a column with JSON structured database type
|
707
|
-
|
708
|
-
Before, the methods to access the changes made during the last save `#saved_change_to_key?`, `#saved_change_to_key`, and `#key_before_last_save` did not work if the store was defined as a `store_accessor` on a column with a JSON structured database type
|
709
|
-
|
710
|
-
*Robert DiMartino*
|
711
|
-
|
712
|
-
* Fully support `NULLS [NOT] DISTINCT` for PostgreSQL 15+ indexes.
|
713
|
-
|
714
|
-
Previous work was done to allow the index to be created in a migration, but it was not
|
715
|
-
supported in schema.rb. Additionally, the matching for `NULLS [NOT] DISTINCT` was not
|
716
|
-
in the correct order, which could have resulted in inconsistent schema detection.
|
717
|
-
|
718
|
-
*Gregory Jones*
|
719
|
-
|
720
|
-
* Allow escaping of literal colon characters in `sanitize_sql_*` methods when named bind variables are used
|
721
|
-
|
722
|
-
*Justin Bull*
|
723
|
-
|
724
|
-
* Fix `#previously_new_record?` to return true for destroyed records.
|
725
|
-
|
726
|
-
Before, if a record was created and then destroyed, `#previously_new_record?` would return true.
|
727
|
-
Now, any UPDATE or DELETE to a record is considered a change, and will result in `#previously_new_record?`
|
728
|
-
returning false.
|
729
|
-
|
730
|
-
*Adrianna Chang*
|
731
|
-
|
732
|
-
* Specify callback in `has_secure_token`
|
733
|
-
|
734
|
-
```ruby
|
735
|
-
class User < ApplicationRecord
|
736
|
-
has_secure_token on: :initialize
|
737
|
-
end
|
738
|
-
|
739
|
-
User.new.token # => "abc123...."
|
740
|
-
```
|
741
|
-
|
742
|
-
*Sean Doyle*
|
743
|
-
|
744
|
-
* Fix incrementation of in memory counter caches when associations overlap
|
745
|
-
|
746
|
-
When two associations had a similarly named counter cache column, Active Record
|
747
|
-
could sometime increment the wrong one.
|
748
|
-
|
749
|
-
*Jacopo Beschi*, *Jean Boussier*
|
750
|
-
|
751
|
-
* Don't show secrets for Active Record's `Cipher::Aes256Gcm#inspect`.
|
752
|
-
|
753
|
-
Before:
|
754
|
-
|
755
|
-
```ruby
|
756
|
-
ActiveRecord::Encryption::Cipher::Aes256Gcm.new(secret).inspect
|
757
|
-
"#<ActiveRecord::Encryption::Cipher::Aes256Gcm:0x0000000104888038 ... @secret=\"\\xAF\\bFh]LV}q\\nl\\xB2U\\xB3 ... >"
|
758
|
-
```
|
759
|
-
|
760
|
-
After:
|
761
|
-
|
762
|
-
```ruby
|
763
|
-
ActiveRecord::Encryption::Cipher::Aes256Gcm(secret).inspect
|
764
|
-
"#<ActiveRecord::Encryption::Cipher::Aes256Gcm:0x0000000104888038>"
|
765
|
-
```
|
766
|
-
|
767
|
-
*Petrik de Heus*
|
768
|
-
|
769
|
-
* Bring back the historical behavior of committing transaction on non-local return.
|
770
|
-
|
771
|
-
```ruby
|
772
|
-
Model.transaction do
|
773
|
-
model.save
|
774
|
-
return
|
775
|
-
other_model.save # not executed
|
776
|
-
end
|
777
|
-
```
|
778
|
-
|
779
|
-
Historically only raised errors would trigger a rollback, but in Ruby `2.3`, the `timeout` library
|
780
|
-
started using `throw` to interrupt execution which had the adverse effect of committing open transactions.
|
781
|
-
|
782
|
-
To solve this, in Active Record 6.1 the behavior was changed to instead rollback the transaction as it was safer
|
783
|
-
than to potentially commit an incomplete transaction.
|
784
|
-
|
785
|
-
Using `return`, `break` or `throw` inside a `transaction` block was essentially deprecated from Rails 6.1 onwards.
|
786
|
-
|
787
|
-
However with the release of `timeout 0.4.0`, `Timeout.timeout` now raises an error again, and Active Record is able
|
788
|
-
to return to its original, less surprising, behavior.
|
789
|
-
|
790
|
-
This historical behavior can now be opt-ed in via:
|
791
|
-
|
792
|
-
```
|
793
|
-
Rails.application.config.active_record.commit_transaction_on_non_local_return = true
|
794
|
-
```
|
795
|
-
|
796
|
-
And is the default for new applications created in Rails 7.1.
|
797
|
-
|
798
|
-
*Jean Boussier*
|
799
|
-
|
800
|
-
* Deprecate `name` argument on `#remove_connection`.
|
801
|
-
|
802
|
-
The `name` argument is deprecated on `#remove_connection` without replacement. `#remove_connection` should be called directly on the class that established the connection.
|
803
|
-
|
804
|
-
*Eileen M. Uchitelle*
|
805
|
-
|
806
|
-
* Fix has_one through singular building with inverse.
|
807
|
-
|
808
|
-
Allows building of records from an association with a has_one through a
|
809
|
-
singular association with inverse. For belongs_to through associations,
|
810
|
-
linking the foreign key to the primary key model isn't needed.
|
811
|
-
For has_one, we cannot build records due to the association not being mutable.
|
812
|
-
|
813
|
-
*Gannon McGibbon*
|
814
|
-
|
815
|
-
* Disable database prepared statements when query logs are enabled
|
816
|
-
|
817
|
-
Prepared Statements and Query Logs are incompatible features due to query logs making every query unique.
|
818
|
-
|
819
|
-
*zzak, Jean Boussier*
|
820
|
-
|
821
|
-
* Support decrypting data encrypted non-deterministically with a SHA1 hash digest.
|
822
|
-
|
823
|
-
This adds a new Active Record encryption option to support decrypting data encrypted
|
824
|
-
non-deterministically with a SHA1 hash digest:
|
825
|
-
|
826
|
-
```
|
827
|
-
Rails.application.config.active_record.encryption.support_sha1_for_non_deterministic_encryption = true
|
828
|
-
```
|
829
|
-
|
830
|
-
The new option addresses a problem when upgrading from 7.0 to 7.1. Due to a bug in how Active Record
|
831
|
-
Encryption was getting initialized, the key provider used for non-deterministic encryption were using
|
832
|
-
SHA-1 as its digest class, instead of the one configured globally by Rails via
|
833
|
-
`Rails.application.config.active_support.key_generator_hash_digest_class`.
|
834
|
-
|
835
|
-
*Cadu Ribeiro and Jorge Manrubia*
|
836
|
-
|
837
|
-
* Added PostgreSQL migration commands for enum rename, add value, and rename value.
|
838
|
-
|
839
|
-
`rename_enum` and `rename_enum_value` are reversible. Due to Postgres
|
840
|
-
limitation, `add_enum_value` is not reversible since you cannot delete enum
|
841
|
-
values. As an alternative you should drop and recreate the enum entirely.
|
842
|
-
|
843
|
-
```ruby
|
844
|
-
rename_enum :article_status, to: :article_state
|
845
|
-
```
|
846
|
-
|
847
|
-
```ruby
|
848
|
-
add_enum_value :article_state, "archived" # will be at the end of existing values
|
849
|
-
add_enum_value :article_state, "in review", before: "published"
|
850
|
-
add_enum_value :article_state, "approved", after: "in review"
|
851
|
-
```
|
852
|
-
|
853
|
-
```ruby
|
854
|
-
rename_enum_value :article_state, from: "archived", to: "deleted"
|
855
|
-
```
|
856
|
-
|
857
|
-
*Ray Faddis*
|
858
|
-
|
859
|
-
* Allow composite primary key to be derived from schema
|
860
|
-
|
861
|
-
Booting an application with a schema that contains composite primary keys
|
862
|
-
will not issue warning and won't `nil`ify the `ActiveRecord::Base#primary_key` value anymore.
|
863
|
-
|
864
|
-
Given a `travel_routes` table definition and a `TravelRoute` model like:
|
865
|
-
```ruby
|
866
|
-
create_table :travel_routes, primary_key: [:origin, :destination], force: true do |t|
|
867
|
-
t.string :origin
|
868
|
-
t.string :destination
|
869
|
-
end
|
870
|
-
|
871
|
-
class TravelRoute < ActiveRecord::Base; end
|
872
|
-
```
|
873
|
-
The `TravelRoute.primary_key` value will be automatically derived to `["origin", "destination"]`
|
874
|
-
|
875
|
-
*Nikita Vasilevsky*
|
876
|
-
|
877
|
-
* Include the `connection_pool` with exceptions raised from an adapter.
|
878
|
-
|
879
|
-
The `connection_pool` provides added context such as the connection used
|
880
|
-
that led to the exception as well as which role and shard.
|
881
|
-
|
882
|
-
*Luan Vieira*
|
883
|
-
|
884
|
-
* Support multiple column ordering for `find_each`, `find_in_batches` and `in_batches`.
|
885
|
-
|
886
|
-
When find_each/find_in_batches/in_batches are performed on a table with composite primary keys, ascending or descending order can be selected for each key.
|
887
|
-
|
888
|
-
```ruby
|
889
|
-
Person.find_each(order: [:desc, :asc]) do |person|
|
890
|
-
person.party_all_night!
|
891
|
-
end
|
892
|
-
```
|
893
|
-
|
894
|
-
*Takuya Kurimoto*
|
895
|
-
|
896
|
-
* Fix where on association with has_one/has_many polymorphic relations.
|
897
|
-
|
898
|
-
Before:
|
899
|
-
```ruby
|
900
|
-
Treasure.where(price_estimates: PriceEstimate.all)
|
901
|
-
#=> SELECT (...) WHERE "treasures"."id" IN (SELECT "price_estimates"."estimate_of_id" FROM "price_estimates")
|
902
|
-
```
|
903
|
-
|
904
|
-
Later:
|
905
|
-
```ruby
|
906
|
-
Treasure.where(price_estimates: PriceEstimate.all)
|
907
|
-
#=> SELECT (...) WHERE "treasures"."id" IN (SELECT "price_estimates"."estimate_of_id" FROM "price_estimates" WHERE "price_estimates"."estimate_of_type" = 'Treasure')
|
908
|
-
```
|
909
|
-
|
910
|
-
*Lázaro Nixon*
|
911
|
-
|
912
|
-
* Assign auto populated columns on Active Record record creation.
|
913
|
-
|
914
|
-
Changes record creation logic to allow for the `auto_increment` column to be assigned
|
915
|
-
immediately after creation regardless of it's relation to the model's primary key.
|
916
|
-
|
917
|
-
The PostgreSQL adapter benefits the most from the change allowing for any number of auto-populated
|
918
|
-
columns to be assigned on the object immediately after row insertion utilizing the `RETURNING` statement.
|
919
|
-
|
920
|
-
*Nikita Vasilevsky*
|
921
|
-
|
922
|
-
* Use the first key in the `shards` hash from `connected_to` for the `default_shard`.
|
923
|
-
|
924
|
-
Some applications may not want to use `:default` as a shard name in their connection model. Unfortunately Active Record expects there to be a `:default` shard because it must assume a shard to get the right connection from the pool manager. Rather than force applications to manually set this, `connects_to` can infer the default shard name from the hash of shards and will now assume that the first shard is your default.
|
925
|
-
|
926
|
-
For example if your model looked like this:
|
927
|
-
|
928
|
-
```ruby
|
929
|
-
class ShardRecord < ApplicationRecord
|
930
|
-
self.abstract_class = true
|
931
|
-
|
932
|
-
connects_to shards: {
|
933
|
-
shard_one: { writing: :shard_one },
|
934
|
-
shard_two: { writing: :shard_two }
|
935
|
-
}
|
936
|
-
```
|
937
|
-
|
938
|
-
Then the `default_shard` for this class would be set to `shard_one`.
|
939
|
-
|
940
|
-
Fixes: #45390
|
941
|
-
|
942
|
-
*Eileen M. Uchitelle*
|
943
|
-
|
944
|
-
* Fix mutation detection for serialized attributes backed by binary columns.
|
945
|
-
|
946
|
-
*Jean Boussier*
|
947
|
-
|
948
|
-
* Add `ActiveRecord.disconnect_all!` method to immediately close all connections from all pools.
|
949
|
-
|
950
|
-
*Jean Boussier*
|
951
|
-
|
952
|
-
* Discard connections which may have been left in a transaction.
|
953
|
-
|
954
|
-
There are cases where, due to an error, `within_new_transaction` may unexpectedly leave a connection in an open transaction. In these cases the connection may be reused, and the following may occur:
|
955
|
-
- Writes appear to fail when they actually succeed.
|
956
|
-
- Writes appear to succeed when they actually fail.
|
957
|
-
- Reads return stale or uncommitted data.
|
958
|
-
|
959
|
-
Previously, the following case was detected:
|
960
|
-
- An error is encountered during the transaction, then another error is encountered while attempting to roll it back.
|
961
|
-
|
962
|
-
Now, the following additional cases are detected:
|
963
|
-
- An error is encountered just after successfully beginning a transaction.
|
964
|
-
- An error is encountered while committing a transaction, then another error is encountered while attempting to roll it back.
|
965
|
-
- An error is encountered while rolling back a transaction.
|
966
|
-
|
967
|
-
*Nick Dower*
|
968
|
-
|
969
|
-
* Active Record query cache now evicts least recently used entries
|
970
|
-
|
971
|
-
By default it only keeps the `100` most recently used queries.
|
972
|
-
|
973
|
-
The cache size can be configured via `database.yml`
|
974
|
-
|
975
|
-
```yaml
|
976
|
-
development:
|
977
|
-
adapter: mysql2
|
978
|
-
query_cache: 200
|
979
|
-
```
|
980
|
-
|
981
|
-
It can also be entirely disabled:
|
982
|
-
|
983
|
-
```yaml
|
984
|
-
development:
|
985
|
-
adapter: mysql2
|
986
|
-
query_cache: false
|
987
|
-
```
|
988
|
-
|
989
|
-
*Jean Boussier*
|
990
|
-
|
991
|
-
* Deprecate `check_pending!` in favor of `check_all_pending!`.
|
992
|
-
|
993
|
-
`check_pending!` will only check for pending migrations on the current database connection or the one passed in. This has been deprecated in favor of `check_all_pending!` which will find all pending migrations for the database configurations in a given environment.
|
994
|
-
|
995
|
-
*Eileen M. Uchitelle*
|
996
|
-
|
997
|
-
* Make `increment_counter`/`decrement_counter` accept an amount argument
|
998
|
-
|
999
|
-
```ruby
|
1000
|
-
Post.increment_counter(:comments_count, 5, by: 3)
|
1001
|
-
```
|
1002
|
-
|
1003
|
-
*fatkodima*
|
1004
|
-
|
1005
|
-
* Add support for `Array#intersect?` to `ActiveRecord::Relation`.
|
1006
|
-
|
1007
|
-
`Array#intersect?` is only available on Ruby 3.1 or later.
|
1008
|
-
|
1009
|
-
This allows the Rubocop `Style/ArrayIntersect` cop to work with `ActiveRecord::Relation` objects.
|
1010
|
-
|
1011
|
-
*John Harry Kelly*
|
1012
|
-
|
1013
|
-
* The deferrable foreign key can be passed to `t.references`.
|
1014
|
-
|
1015
|
-
*Hiroyuki Ishii*
|
1016
|
-
|
1017
|
-
* Deprecate `deferrable: true` option of `add_foreign_key`.
|
1018
|
-
|
1019
|
-
`deferrable: true` is deprecated in favor of `deferrable: :immediate`, and
|
1020
|
-
will be removed in Rails 7.2.
|
1021
|
-
|
1022
|
-
Because `deferrable: true` and `deferrable: :deferred` are hard to understand.
|
1023
|
-
Both true and :deferred are truthy values.
|
1024
|
-
This behavior is the same as the deferrable option of the add_unique_key method, added in #46192.
|
1025
|
-
|
1026
|
-
*Hiroyuki Ishii*
|
1027
|
-
|
1028
|
-
* `AbstractAdapter#execute` and `#exec_query` now clear the query cache
|
1029
|
-
|
1030
|
-
If you need to perform a read only SQL query without clearing the query
|
1031
|
-
cache, use `AbstractAdapter#select_all`.
|
1032
|
-
|
1033
|
-
*Jean Boussier*
|
1034
|
-
|
1035
|
-
* Make `.joins` / `.left_outer_joins` work with CTEs.
|
1036
|
-
|
1037
|
-
For example:
|
1038
|
-
|
1039
|
-
```ruby
|
1040
|
-
Post
|
1041
|
-
.with(commented_posts: Comment.select(:post_id).distinct)
|
1042
|
-
.joins(:commented_posts)
|
1043
|
-
#=> WITH (...) SELECT ... INNER JOIN commented_posts on posts.id = commented_posts.post_id
|
1044
|
-
```
|
1045
|
-
|
1046
|
-
*Vladimir Dementyev*
|
1047
|
-
|
1048
|
-
* Add a load hook for `ActiveRecord::ConnectionAdapters::Mysql2Adapter`
|
1049
|
-
(named `active_record_mysql2adapter`) to allow for overriding aspects of the
|
1050
|
-
`ActiveRecord::ConnectionAdapters::Mysql2Adapter` class. This makes `Mysql2Adapter`
|
1051
|
-
consistent with `PostgreSQLAdapter` and `SQLite3Adapter` that already have load hooks.
|
1052
|
-
|
1053
|
-
*fatkodima*
|
1054
|
-
|
1055
|
-
* Introduce adapter for Trilogy database client
|
1056
|
-
|
1057
|
-
Trilogy is a MySQL-compatible database client. Rails applications can use Trilogy
|
1058
|
-
by configuring their `config/database.yml`:
|
1059
|
-
|
1060
|
-
```yaml
|
1061
|
-
development:
|
1062
|
-
adapter: trilogy
|
1063
|
-
database: blog_development
|
1064
|
-
pool: 5
|
1065
|
-
```
|
1066
|
-
|
1067
|
-
Or by using the `DATABASE_URL` environment variable:
|
1068
|
-
|
1069
|
-
```ruby
|
1070
|
-
ENV['DATABASE_URL'] # => "trilogy://localhost/blog_development?pool=5"
|
1071
|
-
```
|
1072
|
-
|
1073
|
-
*Adrianna Chang*
|
1074
|
-
|
1075
|
-
* `after_commit` callbacks defined on models now execute in the correct order.
|
1076
|
-
|
1077
|
-
```ruby
|
1078
|
-
class User < ActiveRecord::Base
|
1079
|
-
after_commit { puts("this gets called first") }
|
1080
|
-
after_commit { puts("this gets called second") }
|
1081
|
-
end
|
1082
|
-
```
|
1083
|
-
|
1084
|
-
Previously, the callbacks executed in the reverse order. To opt in to the new behaviour:
|
1085
|
-
|
1086
|
-
```ruby
|
1087
|
-
config.active_record.run_after_transaction_callbacks_in_order_defined = true
|
1088
|
-
```
|
1089
|
-
|
1090
|
-
This is the default for new apps.
|
1091
|
-
|
1092
|
-
*Alex Ghiculescu*
|
1093
|
-
|
1094
|
-
* Infer `foreign_key` when `inverse_of` is present on `has_one` and `has_many` associations.
|
1095
|
-
|
1096
|
-
```ruby
|
1097
|
-
has_many :citations, foreign_key: "book1_id", inverse_of: :book
|
1098
|
-
```
|
1099
|
-
|
1100
|
-
can be simplified to
|
1101
|
-
|
1102
|
-
```ruby
|
1103
|
-
has_many :citations, inverse_of: :book
|
1104
|
-
```
|
1105
|
-
|
1106
|
-
and the foreign_key will be read from the corresponding `belongs_to` association.
|
1107
|
-
|
1108
|
-
*Daniel Whitney*
|
1109
|
-
|
1110
|
-
* Limit max length of auto generated index names
|
1111
|
-
|
1112
|
-
Auto generated index names are now limited to 62 bytes, which fits within
|
1113
|
-
the default index name length limits for MySQL, Postgres and SQLite.
|
1114
|
-
|
1115
|
-
Any index name over the limit will fallback to the new short format.
|
1116
|
-
|
1117
|
-
Before (too long):
|
1118
|
-
```
|
1119
|
-
index_testings_on_foo_and_bar_and_first_name_and_last_name_and_administrator
|
1120
|
-
```
|
1121
|
-
|
1122
|
-
After (short format):
|
1123
|
-
```
|
1124
|
-
idx_on_foo_bar_first_name_last_name_administrator_5939248142
|
1125
|
-
```
|
1126
|
-
|
1127
|
-
The short format includes a hash to ensure the name is unique database-wide.
|
1128
|
-
|
1129
|
-
*Mike Coutermarsh*
|
1130
|
-
|
1131
|
-
* Introduce a more stable and optimized Marshal serializer for Active Record models.
|
1132
|
-
|
1133
|
-
Can be enabled with `config.active_record.marshalling_format_version = 7.1`.
|
1134
|
-
|
1135
|
-
*Jean Boussier*
|
1136
|
-
|
1137
|
-
* Allow specifying where clauses with column-tuple syntax.
|
1138
|
-
|
1139
|
-
Querying through `#where` now accepts a new tuple-syntax which accepts, as
|
1140
|
-
a key, an array of columns and, as a value, an array of corresponding tuples.
|
1141
|
-
The key specifies a list of columns, while the value is an array of
|
1142
|
-
ordered-tuples that conform to the column list.
|
1143
|
-
|
1144
|
-
For instance:
|
1145
|
-
|
1146
|
-
```ruby
|
1147
|
-
# Cpk::Book => Cpk::Book(author_id: integer, number: integer, title: string, revision: integer)
|
1148
|
-
# Cpk::Book.primary_key => ["author_id", "number"]
|
1149
|
-
|
1150
|
-
book = Cpk::Book.create!(author_id: 1, number: 1)
|
1151
|
-
Cpk::Book.where(Cpk::Book.primary_key => [[1, 2]]) # => [book]
|
1152
|
-
|
1153
|
-
# Topic => Topic(id: integer, title: string, author_name: string...)
|
1154
|
-
|
1155
|
-
Topic.where([:title, :author_name] => [["The Alchemist", "Paulo Coelho"], ["Harry Potter", "J.K Rowling"]])
|
1156
|
-
```
|
1157
|
-
|
1158
|
-
*Paarth Madan*
|
1159
|
-
|
1160
|
-
* Allow warning codes to be ignore when reporting SQL warnings.
|
1161
|
-
|
1162
|
-
Active Record config that can ignore warning codes
|
1163
|
-
|
1164
|
-
```ruby
|
1165
|
-
# Configure allowlist of warnings that should always be ignored
|
1166
|
-
config.active_record.db_warnings_ignore = [
|
1167
|
-
"1062", # MySQL Error 1062: Duplicate entry
|
1168
|
-
]
|
1169
|
-
```
|
1170
|
-
|
1171
|
-
This is supported for the MySQL and PostgreSQL adapters.
|
1172
|
-
|
1173
|
-
*Nick Borromeo*
|
1174
|
-
|
1175
|
-
* Introduce `:active_record_fixtures` lazy load hook.
|
1176
|
-
|
1177
|
-
Hooks defined with this name will be run whenever `TestFixtures` is included
|
1178
|
-
in a class.
|
1179
|
-
|
1180
|
-
```ruby
|
1181
|
-
ActiveSupport.on_load(:active_record_fixtures) do
|
1182
|
-
self.fixture_paths << "test/fixtures"
|
1183
|
-
end
|
1184
|
-
|
1185
|
-
klass = Class.new
|
1186
|
-
klass.include(ActiveRecord::TestFixtures)
|
1187
|
-
|
1188
|
-
klass.fixture_paths # => ["test/fixtures"]
|
1189
|
-
```
|
1190
|
-
|
1191
|
-
*Andrew Novoselac*
|
1192
|
-
|
1193
|
-
* Introduce `TestFixtures#fixture_paths`.
|
1194
|
-
|
1195
|
-
Multiple fixture paths can now be specified using the `#fixture_paths` accessor.
|
1196
|
-
Apps will continue to have `test/fixtures` as their one fixture path by default,
|
1197
|
-
but additional fixture paths can be specified.
|
1198
|
-
|
1199
|
-
```ruby
|
1200
|
-
ActiveSupport::TestCase.fixture_paths << "component1/test/fixtures"
|
1201
|
-
ActiveSupport::TestCase.fixture_paths << "component2/test/fixtures"
|
1202
|
-
```
|
1203
|
-
|
1204
|
-
`TestFixtures#fixture_path` is now deprecated.
|
1205
|
-
|
1206
|
-
*Andrew Novoselac*
|
1207
|
-
|
1208
|
-
* Adds support for deferrable exclude constraints in PostgreSQL.
|
1209
|
-
|
1210
|
-
By default, exclude constraints in PostgreSQL are checked after each statement.
|
1211
|
-
This works for most use cases, but becomes a major limitation when replacing
|
1212
|
-
records with overlapping ranges by using multiple statements.
|
1213
|
-
|
1214
|
-
```ruby
|
1215
|
-
exclusion_constraint :users, "daterange(valid_from, valid_to) WITH &&", deferrable: :immediate
|
1216
|
-
```
|
1217
|
-
|
1218
|
-
Passing `deferrable: :immediate` checks constraint after each statement,
|
1219
|
-
but allows manually deferring the check using `SET CONSTRAINTS ALL DEFERRED`
|
1220
|
-
within a transaction. This will cause the excludes to be checked after the transaction.
|
1221
|
-
|
1222
|
-
It's also possible to change the default behavior from an immediate check
|
1223
|
-
(after the statement), to a deferred check (after the transaction):
|
1224
|
-
|
1225
|
-
```ruby
|
1226
|
-
exclusion_constraint :users, "daterange(valid_from, valid_to) WITH &&", deferrable: :deferred
|
1227
|
-
```
|
1228
|
-
|
1229
|
-
*Hiroyuki Ishii*
|
1230
|
-
|
1231
|
-
* Respect `foreign_type` option to `delegated_type` for `{role}_class` method.
|
1232
|
-
|
1233
|
-
Usage of `delegated_type` with non-conventional `{role}_type` column names can now be specified with `foreign_type` option.
|
1234
|
-
This option is the same as `foreign_type` as forwarded to the underlying `belongs_to` association that `delegated_type` wraps.
|
1235
|
-
|
1236
|
-
*Jason Karns*
|
1237
|
-
|
1238
|
-
* Add support for unique constraints (PostgreSQL-only).
|
1239
|
-
|
1240
|
-
```ruby
|
1241
|
-
add_unique_key :sections, [:position], deferrable: :deferred, name: "unique_section_position"
|
1242
|
-
remove_unique_key :sections, name: "unique_section_position"
|
1243
|
-
```
|
1244
|
-
|
1245
|
-
See PostgreSQL's [Unique Constraints](https://www.postgresql.org/docs/current/ddl-constraints.html#DDL-CONSTRAINTS-UNIQUE-CONSTRAINTS) documentation for more on unique constraints.
|
1246
|
-
|
1247
|
-
By default, unique constraints in PostgreSQL are checked after each statement.
|
1248
|
-
This works for most use cases, but becomes a major limitation when replacing
|
1249
|
-
records with unique column by using multiple statements.
|
1250
|
-
|
1251
|
-
An example of swapping unique columns between records.
|
1252
|
-
|
1253
|
-
```ruby
|
1254
|
-
# position is unique column
|
1255
|
-
old_item = Item.create!(position: 1)
|
1256
|
-
new_item = Item.create!(position: 2)
|
1257
|
-
|
1258
|
-
Item.transaction do
|
1259
|
-
old_item.update!(position: 2)
|
1260
|
-
new_item.update!(position: 1)
|
1261
|
-
end
|
1262
|
-
```
|
1263
|
-
|
1264
|
-
Using the default behavior, the transaction would fail when executing the
|
1265
|
-
first `UPDATE` statement.
|
1266
|
-
|
1267
|
-
By passing the `:deferrable` option to the `add_unique_key` statement in
|
1268
|
-
migrations, it's possible to defer this check.
|
1269
|
-
|
1270
|
-
```ruby
|
1271
|
-
add_unique_key :items, [:position], deferrable: :immediate
|
1272
|
-
```
|
1273
|
-
|
1274
|
-
Passing `deferrable: :immediate` does not change the behaviour of the previous example,
|
1275
|
-
but allows manually deferring the check using `SET CONSTRAINTS ALL DEFERRED` within a transaction.
|
1276
|
-
This will cause the unique constraints to be checked after the transaction.
|
1277
|
-
|
1278
|
-
It's also possible to adjust the default behavior from an immediate
|
1279
|
-
check (after the statement), to a deferred check (after the transaction):
|
1280
|
-
|
1281
|
-
```ruby
|
1282
|
-
add_unique_key :items, [:position], deferrable: :deferred
|
1283
|
-
```
|
1284
|
-
|
1285
|
-
If you want to change an existing unique index to deferrable, you can use :using_index
|
1286
|
-
to create deferrable unique constraints.
|
1287
|
-
|
1288
|
-
```ruby
|
1289
|
-
add_unique_key :items, deferrable: :deferred, using_index: "index_items_on_position"
|
1290
|
-
```
|
1291
|
-
|
1292
|
-
*Hiroyuki Ishii*
|
1293
|
-
|
1294
|
-
* Remove deprecated `Tasks::DatabaseTasks.schema_file_type`.
|
1295
|
-
|
1296
|
-
*Rafael Mendonça França*
|
1297
|
-
|
1298
|
-
* Remove deprecated `config.active_record.partial_writes`.
|
1299
|
-
|
1300
|
-
*Rafael Mendonça França*
|
1301
|
-
|
1302
|
-
* Remove deprecated `ActiveRecord::Base` config accessors.
|
1303
|
-
|
1304
|
-
*Rafael Mendonça França*
|
1305
|
-
|
1306
|
-
* Remove the `:include_replicas` argument from `configs_for`. Use `:include_hidden` argument instead.
|
1307
|
-
|
1308
|
-
*Eileen M. Uchitelle*
|
1309
|
-
|
1310
|
-
* Allow applications to lookup a config via a custom hash key.
|
1311
|
-
|
1312
|
-
If you have registered a custom config or want to find configs where the hash matches a specific key, now you can pass `config_key` to `configs_for`. For example if you have a `db_config` with the key `vitess` you can look up a database configuration hash by matching that key.
|
1313
|
-
|
1314
|
-
```ruby
|
1315
|
-
ActiveRecord::Base.configurations.configs_for(env_name: "development", name: "primary", config_key: :vitess)
|
1316
|
-
ActiveRecord::Base.configurations.configs_for(env_name: "development", config_key: :vitess)
|
1317
|
-
```
|
1318
|
-
|
1319
|
-
*Eileen M. Uchitelle*
|
1320
|
-
|
1321
|
-
* Allow applications to register a custom database configuration handler.
|
1322
|
-
|
1323
|
-
Adds a mechanism for registering a custom handler for cases where you want database configurations to respond to custom methods. This is useful for non-Rails database adapters or tools like Vitess that you may want to configure differently from a standard `HashConfig` or `UrlConfig`.
|
1324
|
-
|
1325
|
-
Given the following database YAML we want the `animals` db to create a `CustomConfig` object instead while the `primary` database will be a `UrlConfig`:
|
1326
|
-
|
1327
|
-
```yaml
|
1328
|
-
development:
|
1329
|
-
primary:
|
1330
|
-
url: postgres://localhost/primary
|
1331
|
-
animals:
|
1332
|
-
url: postgres://localhost/animals
|
1333
|
-
custom_config:
|
1334
|
-
sharded: 1
|
1335
|
-
```
|
1336
|
-
|
1337
|
-
To register a custom handler first make a class that has your custom methods:
|
1338
|
-
|
1339
|
-
```ruby
|
1340
|
-
class CustomConfig < ActiveRecord::DatabaseConfigurations::UrlConfig
|
1341
|
-
def sharded?
|
1342
|
-
custom_config.fetch("sharded", false)
|
1343
|
-
end
|
1344
|
-
|
1345
|
-
private
|
1346
|
-
def custom_config
|
1347
|
-
configuration_hash.fetch(:custom_config)
|
1348
|
-
end
|
1349
|
-
end
|
1350
|
-
```
|
1351
|
-
|
1352
|
-
Then register the config in an initializer:
|
1353
|
-
|
1354
|
-
```ruby
|
1355
|
-
ActiveRecord::DatabaseConfigurations.register_db_config_handler do |env_name, name, url, config|
|
1356
|
-
next unless config.key?(:custom_config)
|
1357
|
-
CustomConfig.new(env_name, name, url, config)
|
1358
|
-
end
|
1359
|
-
```
|
1360
|
-
|
1361
|
-
When the application is booted, configuration hashes with the `:custom_config` key will be `CustomConfig` objects and respond to `sharded?`. Applications must handle the condition in which Active Record should use their custom handler.
|
1362
|
-
|
1363
|
-
*Eileen M. Uchitelle and John Crepezzi*
|
1364
|
-
|
1365
|
-
* `ActiveRecord::Base.serialize` no longer uses YAML by default.
|
1366
|
-
|
1367
|
-
YAML isn't particularly performant and can lead to security issues
|
1368
|
-
if not used carefully.
|
1369
|
-
|
1370
|
-
Unfortunately there isn't really any good serializers in Ruby's stdlib
|
1371
|
-
to replace it.
|
1372
|
-
|
1373
|
-
The obvious choice would be JSON, which is a fine format for this use case,
|
1374
|
-
however the JSON serializer in Ruby's stdlib isn't strict enough, as it fallback
|
1375
|
-
to casting unknown types to strings, which could lead to corrupted data.
|
1376
|
-
|
1377
|
-
Some third party JSON libraries like `Oj` have a suitable strict mode.
|
1378
|
-
|
1379
|
-
So it's preferable that users choose a serializer based on their own constraints.
|
1380
|
-
|
1381
|
-
The original default can be restored by setting `config.active_record.default_column_serializer = YAML`.
|
1382
|
-
|
1383
|
-
*Jean Boussier*
|
1384
|
-
|
1385
|
-
* `ActiveRecord::Base.serialize` signature changed.
|
1386
|
-
|
1387
|
-
Rather than a single positional argument that accepts two possible
|
1388
|
-
types of values, `serialize` now accepts two distinct keyword arguments.
|
1389
|
-
|
1390
|
-
Before:
|
1391
|
-
|
1392
|
-
```ruby
|
1393
|
-
serialize :content, JSON
|
1394
|
-
serialize :backtrace, Array
|
1395
|
-
```
|
1396
|
-
|
1397
|
-
After:
|
1398
|
-
|
1399
|
-
```ruby
|
1400
|
-
serialize :content, coder: JSON
|
1401
|
-
serialize :backtrace, type: Array
|
1402
|
-
```
|
1403
|
-
|
1404
|
-
*Jean Boussier*
|
1405
|
-
|
1406
|
-
* YAML columns use `YAML.safe_dump` if available.
|
1407
|
-
|
1408
|
-
As of `psych 5.1.0`, `YAML.safe_dump` can now apply the same permitted
|
1409
|
-
types restrictions than `YAML.safe_load`.
|
1410
|
-
|
1411
|
-
It's preferable to ensure the payload only use allowed types when we first
|
1412
|
-
try to serialize it, otherwise you may end up with invalid records in the
|
1413
|
-
database.
|
1414
|
-
|
1415
|
-
*Jean Boussier*
|
1416
|
-
|
1417
|
-
* `ActiveRecord::QueryLogs` better handle broken encoding.
|
1418
|
-
|
1419
|
-
It's not uncommon when building queries with BLOB fields to contain
|
1420
|
-
binary data. Unless the call carefully encode the string in ASCII-8BIT
|
1421
|
-
it generally end up being encoded in `UTF-8`, and `QueryLogs` would
|
1422
|
-
end up failing on it.
|
1423
|
-
|
1424
|
-
`ActiveRecord::QueryLogs` no longer depend on the query to be properly encoded.
|
1425
|
-
|
1426
|
-
*Jean Boussier*
|
1427
|
-
|
1428
|
-
* Fix a bug where `ActiveRecord::Generators::ModelGenerator` would not respect create_table_migration template overrides.
|
1429
|
-
|
1430
|
-
```
|
1431
|
-
rails g model create_books title:string content:text
|
1432
|
-
```
|
1433
|
-
will now read from the create_table_migration.rb.tt template in the following locations in order:
|
1434
|
-
```
|
1435
|
-
lib/templates/active_record/model/create_table_migration.rb
|
1436
|
-
lib/templates/active_record/migration/create_table_migration.rb
|
1437
|
-
```
|
1438
|
-
|
1439
|
-
*Spencer Neste*
|
1440
|
-
|
1441
|
-
* `ActiveRecord::Relation#explain` now accepts options.
|
1442
|
-
|
1443
|
-
For databases and adapters which support them (currently PostgreSQL
|
1444
|
-
and MySQL), options can be passed to `explain` to provide more
|
1445
|
-
detailed query plan analysis:
|
1446
|
-
|
1447
|
-
```ruby
|
1448
|
-
Customer.where(id: 1).joins(:orders).explain(:analyze, :verbose)
|
1449
|
-
```
|
1450
|
-
|
1451
|
-
*Reid Lynch*
|
1452
|
-
|
1453
|
-
* Multiple `Arel::Nodes::SqlLiteral` nodes can now be added together to
|
1454
|
-
form `Arel::Nodes::Fragments` nodes. This allows joining several pieces
|
1455
|
-
of SQL.
|
1456
|
-
|
1457
|
-
*Matthew Draper*, *Ole Friis*
|
1458
|
-
|
1459
|
-
* `ActiveRecord::Base#signed_id` raises if called on a new record.
|
1460
|
-
|
1461
|
-
Previously it would return an ID that was not usable, since it was based on `id = nil`.
|
1462
|
-
|
1463
|
-
*Alex Ghiculescu*
|
1464
|
-
|
1465
|
-
* Allow SQL warnings to be reported.
|
1466
|
-
|
1467
|
-
Active Record configs can be set to enable SQL warning reporting.
|
1468
|
-
|
1469
|
-
```ruby
|
1470
|
-
# Configure action to take when SQL query produces warning
|
1471
|
-
config.active_record.db_warnings_action = :raise
|
1472
|
-
|
1473
|
-
# Configure allowlist of warnings that should always be ignored
|
1474
|
-
config.active_record.db_warnings_ignore = [
|
1475
|
-
/Invalid utf8mb4 character string/,
|
1476
|
-
"An exact warning message",
|
1477
|
-
]
|
1478
|
-
```
|
1479
|
-
|
1480
|
-
This is supported for the MySQL and PostgreSQL adapters.
|
1481
|
-
|
1482
|
-
*Adrianna Chang*, *Paarth Madan*
|
1483
|
-
|
1484
|
-
* Add `#regroup` query method as a short-hand for `.unscope(:group).group(fields)`
|
1485
|
-
|
1486
|
-
Example:
|
1487
|
-
|
1488
|
-
```ruby
|
1489
|
-
Post.group(:title).regroup(:author)
|
1490
|
-
# SELECT `posts`.`*` FROM `posts` GROUP BY `posts`.`author`
|
1491
|
-
```
|
1492
|
-
|
1493
|
-
*Danielius Visockas*
|
1494
|
-
|
1495
|
-
* PostgreSQL adapter method `enable_extension` now allows parameter to be `[schema_name.]<extension_name>`
|
1496
|
-
if the extension must be installed on another schema.
|
1497
|
-
|
1498
|
-
Example: `enable_extension('heroku_ext.hstore')`
|
1499
|
-
|
1500
|
-
*Leonardo Luarte*
|
1501
|
-
|
1502
|
-
* Add `:include` option to `add_index`.
|
1503
|
-
|
1504
|
-
Add support for including non-key columns in indexes for PostgreSQL
|
1505
|
-
with the `INCLUDE` parameter.
|
1506
|
-
|
1507
|
-
```ruby
|
1508
|
-
add_index(:users, :email, include: [:id, :created_at])
|
1509
|
-
```
|
1510
|
-
|
1511
|
-
will result in:
|
1512
|
-
|
1513
|
-
```sql
|
1514
|
-
CREATE INDEX index_users_on_email USING btree (email) INCLUDE (id, created_at)
|
1515
|
-
```
|
1516
|
-
|
1517
|
-
*Steve Abrams*
|
1518
|
-
|
1519
|
-
* `ActiveRecord::Relation`’s `#any?`, `#none?`, and `#one?` methods take an optional pattern
|
1520
|
-
argument, more closely matching their `Enumerable` equivalents.
|
1521
|
-
|
1522
|
-
*George Claghorn*
|
1523
|
-
|
1524
|
-
* Add `ActiveRecord::Base.normalizes` for declaring attribute normalizations.
|
1525
|
-
|
1526
|
-
An attribute normalization is applied when the attribute is assigned or
|
1527
|
-
updated, and the normalized value will be persisted to the database. The
|
1528
|
-
normalization is also applied to the corresponding keyword argument of query
|
1529
|
-
methods, allowing records to be queried using unnormalized values.
|
1530
|
-
|
1531
|
-
For example:
|
1532
|
-
|
1533
|
-
```ruby
|
1534
|
-
class User < ActiveRecord::Base
|
1535
|
-
normalizes :email, with: -> email { email.strip.downcase }
|
1536
|
-
normalizes :phone, with: -> phone { phone.delete("^0-9").delete_prefix("1") }
|
1537
|
-
end
|
1538
|
-
|
1539
|
-
user = User.create(email: " CRUISE-CONTROL@EXAMPLE.COM\n")
|
1540
|
-
user.email # => "cruise-control@example.com"
|
1541
|
-
|
1542
|
-
user = User.find_by(email: "\tCRUISE-CONTROL@EXAMPLE.COM ")
|
1543
|
-
user.email # => "cruise-control@example.com"
|
1544
|
-
user.email_before_type_cast # => "cruise-control@example.com"
|
1545
|
-
|
1546
|
-
User.where(email: "\tCRUISE-CONTROL@EXAMPLE.COM ").count # => 1
|
1547
|
-
User.where(["email = ?", "\tCRUISE-CONTROL@EXAMPLE.COM "]).count # => 0
|
1548
|
-
|
1549
|
-
User.exists?(email: "\tCRUISE-CONTROL@EXAMPLE.COM ") # => true
|
1550
|
-
User.exists?(["email = ?", "\tCRUISE-CONTROL@EXAMPLE.COM "]) # => false
|
1551
|
-
|
1552
|
-
User.normalize_value_for(:phone, "+1 (555) 867-5309") # => "5558675309"
|
1553
|
-
```
|
1554
|
-
|
1555
|
-
*Jonathan Hefner*
|
1556
|
-
|
1557
|
-
* Hide changes to before_committed! callback behaviour behind flag.
|
1558
|
-
|
1559
|
-
In #46525, behavior around before_committed! callbacks was changed so that callbacks
|
1560
|
-
would run on every enrolled record in a transaction, not just the first copy of a record.
|
1561
|
-
This change in behavior is now controlled by a configuration option,
|
1562
|
-
`config.active_record.before_committed_on_all_records`. It will be enabled by default on Rails 7.1.
|
1563
|
-
|
1564
|
-
*Adrianna Chang*
|
1565
|
-
|
1566
|
-
* The `namespaced_controller` Query Log tag now matches the `controller` format
|
1567
|
-
|
1568
|
-
For example, a request processed by `NameSpaced::UsersController` will now log as:
|
1569
|
-
|
1570
|
-
```
|
1571
|
-
:controller # "users"
|
1572
|
-
:namespaced_controller # "name_spaced/users"
|
1573
|
-
```
|
1574
|
-
|
1575
|
-
*Alex Ghiculescu*
|
1576
|
-
|
1577
|
-
* Return only unique ids from ActiveRecord::Calculations#ids
|
1578
|
-
|
1579
|
-
Updated ActiveRecord::Calculations#ids to only return the unique ids of the base model
|
1580
|
-
when using eager_load, preload and includes.
|
1581
|
-
|
1582
|
-
```ruby
|
1583
|
-
Post.find_by(id: 1).comments.count
|
1584
|
-
# => 5
|
1585
|
-
Post.includes(:comments).where(id: 1).pluck(:id)
|
1586
|
-
# => [1, 1, 1, 1, 1]
|
1587
|
-
Post.includes(:comments).where(id: 1).ids
|
1588
|
-
# => [1]
|
1589
|
-
```
|
1590
|
-
|
1591
|
-
*Joshua Young*
|
1592
|
-
|
1593
|
-
* Stop using `LOWER()` for case-insensitive queries on `citext` columns
|
1594
|
-
|
1595
|
-
Previously, `LOWER()` was added for e.g. uniqueness validations with
|
1596
|
-
`case_sensitive: false`.
|
1597
|
-
It wasn't mentioned in the documentation that the index without `LOWER()`
|
1598
|
-
wouldn't be used in this case.
|
1599
|
-
|
1600
|
-
*Phil Pirozhkov*
|
1601
|
-
|
1602
|
-
* Extract `#sync_timezone_changes` method in AbstractMysqlAdapter to enable subclasses
|
1603
|
-
to sync database timezone changes without overriding `#raw_execute`.
|
1604
|
-
|
1605
|
-
*Adrianna Chang*, *Paarth Madan*
|
1606
|
-
|
1607
|
-
* Do not write additional new lines when dumping sql migration versions
|
1608
|
-
|
1609
|
-
This change updates the `insert_versions_sql` function so that the database insert string containing the current database migration versions does not end with two additional new lines.
|
1610
|
-
|
1611
|
-
*Misha Schwartz*
|
1612
|
-
|
1613
|
-
* Fix `composed_of` value freezing and duplication.
|
1614
|
-
|
1615
|
-
Previously composite values exhibited two confusing behaviors:
|
1616
|
-
|
1617
|
-
- When reading a compositve value it'd _NOT_ be frozen, allowing it to get out of sync with its underlying database
|
1618
|
-
columns.
|
1619
|
-
- When writing a compositve value the argument would be frozen, potentially confusing the caller.
|
1620
|
-
|
1621
|
-
Currently, composite values instantiated based on database columns are frozen (addressing the first issue) and
|
1622
|
-
assigned compositve values are duplicated and the duplicate is frozen (addressing the second issue).
|
1623
|
-
|
1624
|
-
*Greg Navis*
|
1625
|
-
|
1626
|
-
* Fix redundant updates to the column insensitivity cache
|
1627
|
-
|
1628
|
-
Fixed redundant queries checking column capability for insensitive
|
1629
|
-
comparison.
|
1630
|
-
|
1631
|
-
*Phil Pirozhkov*
|
1632
|
-
|
1633
|
-
* Allow disabling methods generated by `ActiveRecord.enum`.
|
1634
|
-
|
1635
|
-
*Alfred Dominic*
|
1636
|
-
|
1637
|
-
* Avoid validating `belongs_to` association if it has not changed.
|
1638
|
-
|
1639
|
-
Previously, when updating a record, Active Record will perform an extra query to check for the presence of
|
1640
|
-
`belongs_to` associations (if the presence is configured to be mandatory), even if that attribute hasn't changed.
|
1641
|
-
|
1642
|
-
Currently, only `belongs_to`-related columns are checked for presence. It is possible to have orphaned records with
|
1643
|
-
this approach. To avoid this problem, you need to use a foreign key.
|
1644
|
-
|
1645
|
-
This behavior can be controlled by configuration:
|
1646
|
-
|
1647
|
-
```ruby
|
1648
|
-
config.active_record.belongs_to_required_validates_foreign_key = false
|
1649
|
-
```
|
1650
|
-
|
1651
|
-
and will be disabled by default with `config.load_defaults 7.1`.
|
1652
|
-
|
1653
279
|
*fatkodima*
|
1654
280
|
|
1655
|
-
* `
|
1656
|
-
on the owner model (where `association` is the name of the association). This
|
1657
|
-
method unloads the cached associate record, if any, and causes the next access
|
1658
|
-
to query it from the database.
|
1659
|
-
|
1660
|
-
*George Claghorn*
|
1661
|
-
|
1662
|
-
* Allow per attribute setting of YAML permitted classes (safe load) and unsafe load.
|
1663
|
-
|
1664
|
-
*Carlos Palhares*
|
1665
|
-
|
1666
|
-
* Add a build persistence method
|
1667
|
-
|
1668
|
-
Provides a wrapper for `new`, to provide feature parity with `create`s
|
1669
|
-
ability to create multiple records from an array of hashes, using the
|
1670
|
-
same notation as the `build` method on associations.
|
1671
|
-
|
1672
|
-
*Sean Denny*
|
1673
|
-
|
1674
|
-
* Raise on assignment to readonly attributes
|
1675
|
-
|
1676
|
-
```ruby
|
1677
|
-
class Post < ActiveRecord::Base
|
1678
|
-
attr_readonly :content
|
1679
|
-
end
|
1680
|
-
Post.create!(content: "cannot be updated")
|
1681
|
-
post.content # "cannot be updated"
|
1682
|
-
post.content = "something else" # => ActiveRecord::ReadonlyAttributeError
|
1683
|
-
```
|
1684
|
-
|
1685
|
-
Previously, assignment would succeed but silently not write to the database.
|
1686
|
-
|
1687
|
-
This behavior can be controlled by configuration:
|
1688
|
-
|
1689
|
-
```ruby
|
1690
|
-
config.active_record.raise_on_assign_to_attr_readonly = true
|
1691
|
-
```
|
1692
|
-
|
1693
|
-
and will be enabled by default with `config.load_defaults 7.1`.
|
1694
|
-
|
1695
|
-
*Alex Ghiculescu*, *Hartley McGuire*
|
1696
|
-
|
1697
|
-
* Allow unscoping of preload and eager_load associations
|
1698
|
-
|
1699
|
-
Added the ability to unscope preload and eager_load associations just like
|
1700
|
-
includes, joins, etc. See ActiveRecord::QueryMethods::VALID_UNSCOPING_VALUES
|
1701
|
-
for the full list of supported unscopable scopes.
|
1702
|
-
|
1703
|
-
```ruby
|
1704
|
-
query.unscope(:eager_load, :preload).group(:id).select(:id)
|
1705
|
-
```
|
1706
|
-
|
1707
|
-
*David Morehouse*
|
1708
|
-
|
1709
|
-
* Add automatic filtering of encrypted attributes on inspect
|
1710
|
-
|
1711
|
-
This feature is enabled by default but can be disabled with
|
1712
|
-
|
1713
|
-
```ruby
|
1714
|
-
config.active_record.encryption.add_to_filter_parameters = false
|
1715
|
-
```
|
1716
|
-
|
1717
|
-
*Hartley McGuire*
|
1718
|
-
|
1719
|
-
* Clear locking column on #dup
|
1720
|
-
|
1721
|
-
This change fixes not to duplicate locking_column like id and timestamps.
|
1722
|
-
|
1723
|
-
```
|
1724
|
-
car = Car.create!
|
1725
|
-
car.touch
|
1726
|
-
car.lock_version #=> 1
|
1727
|
-
car.dup.lock_version #=> 0
|
1728
|
-
```
|
1729
|
-
|
1730
|
-
*Shouichi Kamiya*, *Seonggi Yang*, *Ryohei UEDA*
|
1731
|
-
|
1732
|
-
* Invalidate transaction as early as possible
|
1733
|
-
|
1734
|
-
After rescuing a `TransactionRollbackError` exception Rails invalidates transactions earlier in the flow
|
1735
|
-
allowing the framework to skip issuing the `ROLLBACK` statement in more cases.
|
1736
|
-
Only affects adapters that have `savepoint_errors_invalidate_transactions?` configured as `true`,
|
1737
|
-
which at this point is only applicable to the `mysql2` adapter.
|
1738
|
-
|
1739
|
-
*Nikita Vasilevsky*
|
1740
|
-
|
1741
|
-
* Allow configuring columns list to be used in SQL queries issued by an `ActiveRecord::Base` object
|
1742
|
-
|
1743
|
-
It is now possible to configure columns list that will be used to build an SQL query clauses when
|
1744
|
-
updating, deleting or reloading an `ActiveRecord::Base` object
|
1745
|
-
|
1746
|
-
```ruby
|
1747
|
-
class Developer < ActiveRecord::Base
|
1748
|
-
query_constraints :company_id, :id
|
1749
|
-
end
|
1750
|
-
developer = Developer.first.update(name: "Bob")
|
1751
|
-
# => UPDATE "developers" SET "name" = 'Bob' WHERE "developers"."company_id" = 1 AND "developers"."id" = 1
|
1752
|
-
```
|
1753
|
-
|
1754
|
-
*Nikita Vasilevsky*
|
1755
|
-
|
1756
|
-
* Adds `validate` to foreign keys and check constraints in schema.rb
|
1757
|
-
|
1758
|
-
Previously, `schema.rb` would not record if `validate: false` had been used when adding a foreign key or check
|
1759
|
-
constraint, so restoring a database from the schema could result in foreign keys or check constraints being
|
1760
|
-
incorrectly validated.
|
1761
|
-
|
1762
|
-
*Tommy Graves*
|
1763
|
-
|
1764
|
-
* Adapter `#execute` methods now accept an `allow_retry` option. When set to `true`, the SQL statement will be
|
1765
|
-
retried, up to the database's configured `connection_retries` value, upon encountering connection-related errors.
|
1766
|
-
|
1767
|
-
*Adrianna Chang*
|
1768
|
-
|
1769
|
-
* Only trigger `after_commit :destroy` callbacks when a database row is deleted.
|
1770
|
-
|
1771
|
-
This prevents `after_commit :destroy` callbacks from being triggered again
|
1772
|
-
when `destroy` is called multiple times on the same record.
|
1773
|
-
|
1774
|
-
*Ben Sheldon*
|
1775
|
-
|
1776
|
-
* Fix `ciphertext_for` for yet-to-be-encrypted values.
|
1777
|
-
|
1778
|
-
Previously, `ciphertext_for` returned the cleartext of values that had not
|
1779
|
-
yet been encrypted, such as with an unpersisted record:
|
1780
|
-
|
1781
|
-
```ruby
|
1782
|
-
Post.encrypts :body
|
1783
|
-
|
1784
|
-
post = Post.create!(body: "Hello")
|
1785
|
-
post.ciphertext_for(:body)
|
1786
|
-
# => "{\"p\":\"abc..."
|
1787
|
-
|
1788
|
-
post.body = "World"
|
1789
|
-
post.ciphertext_for(:body)
|
1790
|
-
# => "World"
|
1791
|
-
```
|
1792
|
-
|
1793
|
-
Now, `ciphertext_for` will always return the ciphertext of encrypted
|
1794
|
-
attributes:
|
1795
|
-
|
1796
|
-
```ruby
|
1797
|
-
Post.encrypts :body
|
1798
|
-
|
1799
|
-
post = Post.create!(body: "Hello")
|
1800
|
-
post.ciphertext_for(:body)
|
1801
|
-
# => "{\"p\":\"abc..."
|
1802
|
-
|
1803
|
-
post.body = "World"
|
1804
|
-
post.ciphertext_for(:body)
|
1805
|
-
# => "{\"p\":\"xyz..."
|
1806
|
-
```
|
1807
|
-
|
1808
|
-
*Jonathan Hefner*
|
1809
|
-
|
1810
|
-
* Fix a bug where using groups and counts with long table names would return incorrect results.
|
1811
|
-
|
1812
|
-
*Shota Toguchi*, *Yusaku Ono*
|
1813
|
-
|
1814
|
-
* Fix encryption of column default values.
|
1815
|
-
|
1816
|
-
Previously, encrypted attributes that used column default values appeared to
|
1817
|
-
be encrypted on create, but were not:
|
1818
|
-
|
1819
|
-
```ruby
|
1820
|
-
Book.encrypts :name
|
1821
|
-
|
1822
|
-
book = Book.create!
|
1823
|
-
book.name
|
1824
|
-
# => "<untitled>"
|
1825
|
-
book.name_before_type_cast
|
1826
|
-
# => "{\"p\":\"abc..."
|
1827
|
-
book.reload.name_before_type_cast
|
1828
|
-
# => "<untitled>"
|
1829
|
-
```
|
1830
|
-
|
1831
|
-
Now, attributes with column default values are encrypted:
|
1832
|
-
|
1833
|
-
```ruby
|
1834
|
-
Book.encrypts :name
|
1835
|
-
|
1836
|
-
book = Book.create!
|
1837
|
-
book.name
|
1838
|
-
# => "<untitled>"
|
1839
|
-
book.name_before_type_cast
|
1840
|
-
# => "{\"p\":\"abc..."
|
1841
|
-
book.reload.name_before_type_cast
|
1842
|
-
# => "{\"p\":\"abc..."
|
1843
|
-
```
|
1844
|
-
|
1845
|
-
*Jonathan Hefner*
|
1846
|
-
|
1847
|
-
* Deprecate delegation from `Base` to `connection_handler`.
|
1848
|
-
|
1849
|
-
Calling `Base.clear_all_connections!`, `Base.clear_active_connections!`, `Base.clear_reloadable_connections!` and `Base.flush_idle_connections!` is deprecated. Please call these methods on the connection handler directly. In future Rails versions, the delegation from `Base` to the `connection_handler` will be removed.
|
1850
|
-
|
1851
|
-
*Eileen M. Uchitelle*
|
1852
|
-
|
1853
|
-
* Allow ActiveRecord::QueryMethods#reselect to receive hash values, similar to ActiveRecord::QueryMethods#select
|
1854
|
-
|
1855
|
-
*Sampat Badhe*
|
1856
|
-
|
1857
|
-
* Validate options when managing columns and tables in migrations.
|
1858
|
-
|
1859
|
-
If an invalid option is passed to a migration method like `create_table` and `add_column`, an error will be raised
|
1860
|
-
instead of the option being silently ignored. Validation of the options will only be applied for new migrations
|
1861
|
-
that are created.
|
1862
|
-
|
1863
|
-
*Guo Xiang Tan*, *George Wambold*
|
1864
|
-
|
1865
|
-
* Update query log tags to use the [SQLCommenter](https://open-telemetry.github.io/opentelemetry-sqlcommenter/) format by default. See [#46179](https://github.com/rails/rails/issues/46179)
|
1866
|
-
|
1867
|
-
To opt out of SQLCommenter-formatted query log tags, set `config.active_record.query_log_tags_format = :legacy`. By default, this is set to `:sqlcommenter`.
|
1868
|
-
|
1869
|
-
*Modulitos* and *Iheanyi*
|
1870
|
-
|
1871
|
-
* Allow any ERB in the database.yml when creating rake tasks.
|
1872
|
-
|
1873
|
-
Any ERB can be used in `database.yml` even if it accesses environment
|
1874
|
-
configurations.
|
1875
|
-
|
1876
|
-
Deprecates `config.active_record.suppress_multiple_database_warning`.
|
1877
|
-
|
1878
|
-
*Eike Send*
|
1879
|
-
|
1880
|
-
* Add table to error for duplicate column definitions.
|
281
|
+
* Add support for `:if_not_exists` and `:force` options to `create_schema`.
|
1881
282
|
|
1882
|
-
|
1883
|
-
shows which table it concerns.
|
283
|
+
*fatkodima*
|
1884
284
|
|
1885
|
-
|
285
|
+
* Fix `index_errors` having incorrect index in association validation errors.
|
1886
286
|
|
1887
|
-
*
|
287
|
+
*lulalala*
|
1888
288
|
|
1889
|
-
|
1890
|
-
default precision as regular datetime columns, resulting in the following
|
1891
|
-
being erroneously equivalent:
|
289
|
+
* Add `index_errors: :nested_attributes_order` mode.
|
1892
290
|
|
1893
|
-
|
1894
|
-
t.virtual :name, type: datetime, precision: nil, as: "expression"
|
291
|
+
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.
|
1895
292
|
|
1896
|
-
|
1897
|
-
datetime column default precisions match.
|
293
|
+
*lulalala*
|
1898
294
|
|
1899
|
-
|
295
|
+
* Add `Rails.application.config.active_record.postgresql_adapter_decode_dates` to opt out of decoding dates automatically with the postgresql adapter. Defaults to true.
|
1900
296
|
|
1901
|
-
*
|
297
|
+
*Joé Dupuis*
|
1902
298
|
|
1903
|
-
|
1904
|
-
that `#with_raw_connection` offers.
|
299
|
+
* Association option `query_constraints` is deprecated in favor of `foreign_key`.
|
1905
300
|
|
1906
|
-
*
|
301
|
+
*Nikita Vasilevsky*
|
1907
302
|
|
1908
|
-
* Add `
|
303
|
+
* Add `ENV["SKIP_TEST_DATABASE_TRUNCATE"]` flag to speed up multi-process test runs on large DBs when all tests run within default transaction.
|
1909
304
|
|
1910
|
-
|
305
|
+
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.
|
1911
306
|
|
1912
|
-
*
|
307
|
+
*DHH*
|
1913
308
|
|
1914
|
-
|
1915
|
-
reconnects database connections to take into account a timeout limit. We won't retry
|
1916
|
-
a query if a given amount of time has elapsed since the query was first attempted. This
|
1917
|
-
value defaults to nil, meaning that all retryable queries are retried regardless of time elapsed,
|
1918
|
-
but this can be changed via the `retry_deadline` option in the database config.
|
309
|
+
* Added support for recursive common table expressions.
|
1919
310
|
|
1920
|
-
|
311
|
+
```ruby
|
312
|
+
Post.with_recursive(
|
313
|
+
post_and_replies: [
|
314
|
+
Post.where(id: 42),
|
315
|
+
Post.joins('JOIN post_and_replies ON posts.in_reply_to_id = post_and_replies.id'),
|
316
|
+
]
|
317
|
+
)
|
318
|
+
```
|
1921
319
|
|
1922
|
-
|
320
|
+
Generates the following SQL:
|
1923
321
|
|
1924
|
-
|
322
|
+
```sql
|
323
|
+
WITH RECURSIVE "post_and_replies" AS (
|
324
|
+
(SELECT "posts".* FROM "posts" WHERE "posts"."id" = 42)
|
325
|
+
UNION ALL
|
326
|
+
(SELECT "posts".* FROM "posts" JOIN post_and_replies ON posts.in_reply_to_id = post_and_replies.id)
|
327
|
+
)
|
328
|
+
SELECT "posts".* FROM "posts"
|
329
|
+
```
|
1925
330
|
|
1926
|
-
*
|
331
|
+
*ClearlyClaire*
|
1927
332
|
|
1928
|
-
|
1929
|
-
option to VERIFY_CA or VERIFY_IDENTITY. This option was previously ignored
|
1930
|
-
for MySQL database tasks like creating a database and dumping the structure.
|
333
|
+
* `validate_constraint` can be called in a `change_table` block.
|
1931
334
|
|
1932
|
-
|
335
|
+
ex:
|
336
|
+
```ruby
|
337
|
+
change_table :products do |t|
|
338
|
+
t.check_constraint "price > discounted_price", name: "price_check", validate: false
|
339
|
+
t.validate_check_constraint "price_check"
|
340
|
+
end
|
341
|
+
```
|
1933
342
|
|
1934
|
-
*
|
343
|
+
*Cody Cutrer*
|
1935
344
|
|
1936
|
-
|
345
|
+
* `PostgreSQLAdapter` now decodes columns of type date to `Date` instead of string.
|
1937
346
|
|
1938
|
-
|
347
|
+
Ex:
|
348
|
+
```ruby
|
349
|
+
ActiveRecord::Base.connection
|
350
|
+
.select_value("select '2024-01-01'::date").class #=> Date
|
351
|
+
```
|
1939
352
|
|
1940
|
-
*
|
353
|
+
*Joé Dupuis*
|
1941
354
|
|
1942
|
-
|
1943
|
-
string template is deprecated. To avoid this warning, you should explicitly
|
1944
|
-
convert the duration to a more specific database type. For example, if you
|
1945
|
-
want to use a duration as an integer number of seconds:
|
1946
|
-
```
|
1947
|
-
Record.where("duration = ?", 1.hour.to_i)
|
1948
|
-
```
|
1949
|
-
If you want to use a duration as an ISO 8601 string:
|
1950
|
-
```
|
1951
|
-
Record.where("duration = ?", 1.hour.iso8601)
|
1952
|
-
```
|
355
|
+
* Strict loading using `:n_plus_one_only` does not eagerly load child associations.
|
1953
356
|
|
1954
|
-
|
357
|
+
With this change, child associations are no longer eagerly loaded, to
|
358
|
+
match intended behavior and to prevent non-deterministic order issues caused
|
359
|
+
by calling methods like `first` or `last`. As `first` and `last` don't cause
|
360
|
+
an N+1 by themselves, calling child associations will no longer raise.
|
361
|
+
Fixes #49473.
|
1955
362
|
|
1956
|
-
|
363
|
+
Before:
|
1957
364
|
|
1958
365
|
```ruby
|
1959
|
-
|
1960
|
-
|
366
|
+
person = Person.find(1)
|
367
|
+
person.strict_loading!(mode: :n_plus_one_only)
|
368
|
+
person.posts.first
|
369
|
+
# SELECT * FROM posts WHERE person_id = 1; -- non-deterministic order
|
370
|
+
person.posts.first.firm # raises ActiveRecord::StrictLoadingViolationError
|
1961
371
|
```
|
1962
372
|
|
1963
|
-
|
1964
|
-
|
1965
|
-
* Move `ActiveRecord::SchemaMigration` to an independent object.
|
373
|
+
After:
|
1966
374
|
|
1967
|
-
|
375
|
+
```ruby
|
376
|
+
person = Person.find(1)
|
377
|
+
person.strict_loading!(mode: :n_plus_one_only)
|
378
|
+
person.posts.first # this is 1+1, not N+1
|
379
|
+
# SELECT * FROM posts WHERE person_id = 1 ORDER BY id LIMIT 1;
|
380
|
+
person.posts.first.firm # no longer raises
|
381
|
+
```
|
1968
382
|
|
1969
|
-
*
|
383
|
+
*Reid Lynch*
|
1970
384
|
|
1971
|
-
*
|
385
|
+
* Allow `Sqlite3Adapter` to use `sqlite3` gem version `2.x`.
|
1972
386
|
|
1973
|
-
|
387
|
+
*Mike Dalessio*
|
1974
388
|
|
1975
|
-
|
389
|
+
* Allow `ActiveRecord::Base#pluck` to accept hash values.
|
1976
390
|
|
1977
|
-
|
391
|
+
```ruby
|
392
|
+
# Before
|
393
|
+
Post.joins(:comments).pluck("posts.id", "comments.id", "comments.body")
|
1978
394
|
|
1979
|
-
|
395
|
+
# After
|
396
|
+
Post.joins(:comments).pluck(posts: [:id], comments: [:id, :body])
|
397
|
+
```
|
1980
398
|
|
1981
|
-
*
|
399
|
+
*fatkodima*
|
1982
400
|
|
401
|
+
* Raise an `ActiveRecord::ActiveRecordError` error when the MySQL database returns an invalid version string.
|
1983
402
|
|
1984
|
-
*
|
403
|
+
*Kevin McPhillips*
|
1985
404
|
|
1986
|
-
|
405
|
+
* `ActiveRecord::Base.transaction` now yields an `ActiveRecord::Transaction` object.
|
1987
406
|
|
1988
|
-
|
407
|
+
This allows to register callbacks on it.
|
1989
408
|
|
1990
409
|
```ruby
|
1991
|
-
|
1992
|
-
|
1993
|
-
|
1994
|
-
|
1995
|
-
|
1996
|
-
|
1997
|
-
# FROM \"posts\" INNER JOIN \"comments\" ON \"comments\".\"post_id\" = \"posts\".\"id\""
|
410
|
+
Article.transaction do |transaction|
|
411
|
+
article.update(published: true)
|
412
|
+
transaction.after_commit do
|
413
|
+
PublishNotificationMailer.with(article: article).deliver_later
|
414
|
+
end
|
415
|
+
end
|
1998
416
|
```
|
1999
|
-
*Oleksandr Holubenko*, *Josef Šimánek*, *Jean Boussier*
|
2000
417
|
|
2001
|
-
*
|
418
|
+
*Jean Boussier*
|
419
|
+
|
420
|
+
* Add `ActiveRecord::Base.current_transaction`.
|
2002
421
|
|
2003
|
-
|
2004
|
-
attributes such that the extra attributes from target are added.
|
422
|
+
Returns the current transaction, to allow registering callbacks on it.
|
2005
423
|
|
2006
424
|
```ruby
|
2007
|
-
|
425
|
+
Article.current_transaction.after_commit do
|
426
|
+
PublishNotificationMailer.with(article: article).deliver_later
|
2008
427
|
end
|
428
|
+
```
|
429
|
+
|
430
|
+
*Jean Boussier*
|
431
|
+
|
432
|
+
* Add `ActiveRecord.after_all_transactions_commit` callback.
|
2009
433
|
|
2010
|
-
|
2011
|
-
|
2012
|
-
after_initialize :set_admin
|
434
|
+
Useful for code that may run either inside or outside a transaction and needs
|
435
|
+
to perform work after the state changes have been properly persisted.
|
2013
436
|
|
2014
|
-
|
2015
|
-
|
437
|
+
```ruby
|
438
|
+
def publish_article(article)
|
439
|
+
article.update(published: true)
|
440
|
+
ActiveRecord.after_all_transactions_commit do
|
441
|
+
PublishNotificationMailer.with(article: article).deliver_later
|
2016
442
|
end
|
2017
443
|
end
|
2018
|
-
|
2019
|
-
person = Person.find_by(email: "email@ourcompany.com")
|
2020
|
-
person.respond_to? :is_admin
|
2021
|
-
# => false
|
2022
|
-
person.becomes(WebUser).is_admin?
|
2023
|
-
# => true
|
2024
444
|
```
|
2025
445
|
|
2026
|
-
|
446
|
+
In the above example, the block is either executed immediately if called outside
|
447
|
+
of a transaction, or called after the open transaction is committed.
|
2027
448
|
|
2028
|
-
|
2029
|
-
behavior of `Enumerable#in_order_of`.
|
449
|
+
If the transaction is rolled back, the block isn't called.
|
2030
450
|
|
2031
|
-
|
2032
|
-
with `nil` titles, the same as `Post.all.to_a.in_order_of(:title, [nil, "foo"])`.
|
451
|
+
*Jean Boussier*
|
2033
452
|
|
2034
|
-
|
453
|
+
* Add the ability to ignore counter cache columns until they are backfilled.
|
2035
454
|
|
2036
|
-
|
455
|
+
Starting to use counter caches on existing large tables can be troublesome, because the column
|
456
|
+
values must be backfilled separately of the column addition (to not lock the table for too long)
|
457
|
+
and before the use of `:counter_cache` (otherwise methods like `size`/`any?`/etc, which use
|
458
|
+
counter caches internally, can produce incorrect results). People usually use database triggers
|
459
|
+
or callbacks on child associations while backfilling before introducing a counter cache
|
460
|
+
configuration to the association.
|
461
|
+
|
462
|
+
Now, to safely backfill the column, while keeping the column updated with child records added/removed, use:
|
2037
463
|
|
2038
464
|
```ruby
|
2039
|
-
|
465
|
+
class Comment < ApplicationRecord
|
466
|
+
belongs_to :post, counter_cache: { active: false }
|
467
|
+
end
|
2040
468
|
```
|
2041
469
|
|
2042
|
-
|
470
|
+
While the counter cache is not "active", the methods like `size`/`any?`/etc will not use it,
|
471
|
+
but get the results directly from the database. After the counter cache column is backfilled, simply
|
472
|
+
remove the `{ active: false }` part from the counter cache definition, and it will now be used by the
|
473
|
+
mentioned methods.
|
2043
474
|
|
2044
|
-
|
2045
|
-
|
2046
|
-
|
475
|
+
*fatkodima*
|
476
|
+
|
477
|
+
* Retry known idempotent SELECT queries on connection-related exceptions.
|
2047
478
|
|
2048
|
-
|
479
|
+
SELECT queries we construct by walking the Arel tree and / or with known model attributes
|
480
|
+
are idempotent and can safely be retried in the case of a connection error. Previously,
|
481
|
+
adapters such as `TrilogyAdapter` would raise `ActiveRecord::ConnectionFailed: Trilogy::EOFError`
|
482
|
+
when encountering a connection error mid-request.
|
483
|
+
|
484
|
+
*Adrianna Chang*
|
2049
485
|
|
2050
|
-
*
|
486
|
+
* Allow association's `foreign_key` to be composite.
|
2051
487
|
|
2052
|
-
|
2053
|
-
|
488
|
+
`query_constraints` option was the only way to configure a composite foreign key by passing an `Array`.
|
489
|
+
Now it's possible to pass an Array value as `foreign_key` to achieve the same behavior of an association.
|
2054
490
|
|
2055
|
-
*
|
491
|
+
*Nikita Vasilevsky*
|
2056
492
|
|
2057
|
-
*
|
493
|
+
* Allow association's `primary_key` to be composite.
|
2058
494
|
|
2059
|
-
|
2060
|
-
|
495
|
+
Association's `primary_key` can be composite when derived from associated model `primary_key` or `query_constraints`.
|
496
|
+
Now it's possible to explicitly set it as composite on the association.
|
2061
497
|
|
2062
|
-
*
|
498
|
+
*Nikita Vasilevsky*
|
2063
499
|
|
2064
|
-
* `
|
500
|
+
* Add `config.active_record.permanent_connection_checkout` setting.
|
2065
501
|
|
2066
|
-
`
|
2067
|
-
duplicate records or failing with `ActiveRecord::RecordNotUnique` depending on
|
2068
|
-
whether a proper unicity constraint was set.
|
502
|
+
Controls whether `ActiveRecord::Base.connection` raises an error, emits a deprecation warning, or neither.
|
2069
503
|
|
2070
|
-
`
|
2071
|
-
|
2072
|
-
|
2073
|
-
databases it can actually consume a primary key increment which is undesirable.
|
504
|
+
`ActiveRecord::Base.connection` checkouts a database connection from the pool and keeps it leased until the end of
|
505
|
+
the request or job. This behavior can be undesirable in environments that use many more threads or fibers than there
|
506
|
+
is available connections.
|
2074
507
|
|
2075
|
-
|
2076
|
-
|
2077
|
-
with `ActiveRecord::RecordNotUnique`. This assumes that the table has the proper
|
2078
|
-
unicity constraints, if not, `find_or_create_by` will still lead to duplicated records.
|
508
|
+
This configuration can be used to track down and eliminate code that calls `ActiveRecord::Base.connection` and
|
509
|
+
migrate it to use `ActiveRecord::Base.with_connection` instead.
|
2079
510
|
|
2080
|
-
|
511
|
+
The default behavior remains unchanged, and there is currently no plans to change the default.
|
2081
512
|
|
2082
|
-
*
|
513
|
+
*Jean Boussier*
|
2083
514
|
|
2084
|
-
|
2085
|
-
support reconnect, but also expected to be passed an initial already-
|
2086
|
-
established connection.
|
515
|
+
* Add dirties option to uncached.
|
2087
516
|
|
2088
|
-
|
2089
|
-
|
517
|
+
This adds a `dirties` option to `ActiveRecord::Base.uncached` and
|
518
|
+
`ActiveRecord::ConnectionAdapters::ConnectionPool#uncached`.
|
2090
519
|
|
2091
|
-
|
520
|
+
When set to `true` (the default), writes will clear all query caches belonging to the current thread.
|
521
|
+
When set to `false`, writes to the affected connection pool will not clear any query cache.
|
2092
522
|
|
2093
|
-
|
2094
|
-
checkout when possible.
|
523
|
+
This is needed by Solid Cache so that cache writes do not clear query caches.
|
2095
524
|
|
2096
|
-
|
2097
|
-
used directly to validate the connection, saving a network round-trip.
|
525
|
+
*Donal McBreen*
|
2098
526
|
|
2099
|
-
|
527
|
+
* Deprecate `ActiveRecord::Base.connection` in favor of `.lease_connection`.
|
2100
528
|
|
2101
|
-
|
2102
|
-
|
529
|
+
The method has been renamed as `lease_connection` to better reflect that the returned
|
530
|
+
connection will be held for the duration of the request or job.
|
2103
531
|
|
2104
|
-
|
2105
|
-
|
2106
|
-
database server and try again, so this is now the default behavior.
|
532
|
+
This deprecation is a soft deprecation, no warnings will be issued and there is no
|
533
|
+
current plan to remove the method.
|
2107
534
|
|
2108
|
-
|
2109
|
-
conservative about which queries are considered idempotent -- but if
|
2110
|
-
necessary it can be disabled by setting the `connection_retries` connection
|
2111
|
-
option to `0`.
|
535
|
+
*Jean Boussier*
|
2112
536
|
|
2113
|
-
|
537
|
+
* Deprecate `ActiveRecord::ConnectionAdapters::ConnectionPool#connection`.
|
2114
538
|
|
2115
|
-
|
539
|
+
The method has been renamed as `lease_connection` to better reflect that the returned
|
540
|
+
connection will be held for the duration of the request or job.
|
2116
541
|
|
2117
|
-
|
542
|
+
*Jean Boussier*
|
2118
543
|
|
2119
|
-
|
544
|
+
* Expose a generic fixture accessor for fixture names that may conflict with Minitest.
|
2120
545
|
|
2121
546
|
```ruby
|
2122
|
-
|
547
|
+
assert_equal "Ruby on Rails", web_sites(:rubyonrails).name
|
548
|
+
assert_equal "Ruby on Rails", fixture(:web_sites, :rubyonrails).name
|
2123
549
|
```
|
2124
550
|
|
2125
|
-
|
551
|
+
*Jean Boussier*
|
2126
552
|
|
2127
|
-
|
553
|
+
* Using `Model.query_constraints` with a single non-primary-key column used to raise as expected, but with an
|
554
|
+
incorrect error message.
|
2128
555
|
|
2129
|
-
|
556
|
+
This has been fixed to raise with a more appropriate error message.
|
2130
557
|
|
2131
|
-
*
|
558
|
+
*Joshua Young*
|
2132
559
|
|
2133
|
-
*
|
560
|
+
* Fix `has_one` association autosave setting the foreign key attribute when it is unchanged.
|
2134
561
|
|
2135
|
-
|
2136
|
-
|
2137
|
-
from ActiveJob to ActiveRecord.
|
562
|
+
This behavior is also inconsistent with autosaving `belongs_to` and can have unintended side effects like raising
|
563
|
+
an `ActiveRecord::ReadonlyAttributeError` when the foreign key attribute is marked as read-only.
|
2138
564
|
|
2139
|
-
|
2140
|
-
if the job class is unloadable or an `ActiveRecord::ConfigurationError` if
|
2141
|
-
`dependent: :destroy_async` is declared on an association but there is no job
|
2142
|
-
class configured.
|
565
|
+
*Joshua Young*
|
2143
566
|
|
2144
|
-
|
567
|
+
* Remove deprecated behavior that would rollback a transaction block when exited using `return`, `break` or `throw`.
|
2145
568
|
|
2146
|
-
*
|
569
|
+
*Rafael Mendonça França*
|
2147
570
|
|
2148
|
-
|
2149
|
-
which is wasteful and cause problem with YAML safe_load.
|
571
|
+
* Deprecate `Rails.application.config.active_record.commit_transaction_on_non_local_return`.
|
2150
572
|
|
2151
|
-
*
|
573
|
+
*Rafael Mendonça França*
|
2152
574
|
|
2153
|
-
*
|
575
|
+
* Remove deprecated support to pass `rewhere` to `ActiveRecord::Relation#merge`.
|
2154
576
|
|
2155
|
-
|
577
|
+
*Rafael Mendonça França*
|
2156
578
|
|
2157
|
-
|
579
|
+
* Remove deprecated support to pass `deferrable: true` to `add_foreign_key`.
|
2158
580
|
|
2159
|
-
|
2160
|
-
ActiveRecord::Base.time_zone_aware_types -= [:timestamptz]
|
2161
|
-
```
|
581
|
+
*Rafael Mendonça França*
|
2162
582
|
|
2163
|
-
|
583
|
+
* Remove deprecated support to quote `ActiveSupport::Duration`.
|
2164
584
|
|
2165
|
-
*
|
585
|
+
*Rafael Mendonça França*
|
2166
586
|
|
2167
|
-
|
2168
|
-
resetting a password. However, signed IDs cannot reflect record state, so
|
2169
|
-
if a token is intended to be single-use, it must be tracked in a database at
|
2170
|
-
least until it expires.
|
587
|
+
* Remove deprecated `#quote_bound_value`.
|
2171
588
|
|
2172
|
-
|
2173
|
-
using the token to fetch the record, the data from the token and the current
|
2174
|
-
data from the record will be compared. If the two do not match, the token
|
2175
|
-
will be treated as invalid, the same as if it had expired. For example:
|
589
|
+
*Rafael Mendonça França*
|
2176
590
|
|
2177
|
-
|
2178
|
-
class User < ActiveRecord::Base
|
2179
|
-
has_secure_password
|
2180
|
-
|
2181
|
-
generates_token_for :password_reset, expires_in: 15.minutes do
|
2182
|
-
# A password's BCrypt salt changes when the password is updated.
|
2183
|
-
# By embedding (part of) the salt in a token, the token will
|
2184
|
-
# expire when the password is updated.
|
2185
|
-
BCrypt::Password.new(password_digest).salt[-10..]
|
2186
|
-
end
|
2187
|
-
end
|
591
|
+
* Remove deprecated `ActiveRecord::ConnectionAdapters::ConnectionPool#connection_klass`.
|
2188
592
|
|
2189
|
-
|
2190
|
-
token = user.generate_token_for(:password_reset)
|
593
|
+
*Rafael Mendonça França*
|
2191
594
|
|
2192
|
-
|
595
|
+
* Remove deprecated support to apply `#connection_pool_list`, `#active_connections?`, `#clear_active_connections!`,
|
596
|
+
`#clear_reloadable_connections!`, `#clear_all_connections!` and `#flush_idle_connections!` to the connections pools
|
597
|
+
for the current role when the `role` argument isn't provided.
|
2193
598
|
|
2194
|
-
|
2195
|
-
User.find_by_token_for(:password_reset, token) # => nil
|
2196
|
-
```
|
599
|
+
*Rafael Mendonça França*
|
2197
600
|
|
2198
|
-
|
601
|
+
* Remove deprecated `#all_connection_pools`.
|
2199
602
|
|
2200
|
-
*
|
603
|
+
*Rafael Mendonça França*
|
2201
604
|
|
2202
|
-
|
2203
|
-
When iterating over the whole tables, this approach is not optimal as it loads unneeded ids and
|
2204
|
-
`IN` queries with lots of items are slow.
|
605
|
+
* Remove deprecated `ActiveRecord::ConnectionAdapters::SchemaCache#data_sources`.
|
2205
606
|
|
2206
|
-
|
2207
|
-
several times faster. E.g., tested on a PostgreSQL table with 10 million records: querying (`253s` vs `30s`),
|
2208
|
-
updating (`288s` vs `124s`), deleting (`268s` vs `83s`).
|
607
|
+
*Rafael Mendonça França*
|
2209
608
|
|
2210
|
-
|
2211
|
-
If you iterate over the table and the only condition is, e.g., `archived_at: nil` (and only a tiny fraction
|
2212
|
-
of the records are archived), it makes sense to opt in to this approach:
|
609
|
+
* Remove deprecated `ActiveRecord::ConnectionAdapters::SchemaCache.load_from`.
|
2213
610
|
|
2214
|
-
|
2215
|
-
Project.where(archived_at: nil).in_batches(use_ranges: true) do |relation|
|
2216
|
-
# do something
|
2217
|
-
end
|
2218
|
-
```
|
611
|
+
*Rafael Mendonça França*
|
2219
612
|
|
2220
|
-
|
613
|
+
* Remove deprecated `#all_foreign_keys_valid?` from database adapters.
|
2221
614
|
|
2222
|
-
*
|
615
|
+
*Rafael Mendonça França*
|
2223
616
|
|
2224
|
-
*
|
617
|
+
* Remove deprecated support to passing coder and class as second argument to `serialize`.
|
2225
618
|
|
2226
|
-
|
2227
|
-
Post.with(posts_with_comments: Post.where("comments_count > ?", 0))
|
2228
|
-
# => ActiveRecord::Relation
|
2229
|
-
# WITH posts_with_comments AS (SELECT * FROM posts WHERE (comments_count > 0)) SELECT * FROM posts
|
2230
|
-
```
|
619
|
+
*Rafael Mendonça França*
|
2231
620
|
|
2232
|
-
|
621
|
+
* Remove deprecated support to `ActiveRecord::Base#read_attribute(:id)` to return the custom primary key value.
|
2233
622
|
|
2234
|
-
*
|
623
|
+
*Rafael Mendonça França*
|
2235
624
|
|
2236
|
-
|
625
|
+
* Remove deprecated `TestFixtures.fixture_path`.
|
2237
626
|
|
2238
|
-
|
627
|
+
*Rafael Mendonça França*
|
2239
628
|
|
2240
|
-
|
629
|
+
* Remove deprecated behavior to support referring to a singular association by its plural name.
|
2241
630
|
|
2242
|
-
*
|
631
|
+
*Rafael Mendonça França*
|
2243
632
|
|
2244
|
-
|
633
|
+
* Deprecate `Rails.application.config.active_record.allow_deprecated_singular_associations_name`.
|
2245
634
|
|
2246
|
-
*
|
635
|
+
*Rafael Mendonça França*
|
2247
636
|
|
2248
|
-
|
2249
|
-
|
2250
|
-
add_column :shops, :open_hours, :tsrange, array: true
|
2251
|
-
# In app config
|
2252
|
-
ActiveRecord::Base.time_zone_aware_types += [:tsrange]
|
2253
|
-
# In the code times are properly converted to app time zone
|
2254
|
-
Shop.create!(open_hours: [Time.current..8.hour.from_now])
|
2255
|
-
```
|
637
|
+
* Remove deprecated support to passing `SchemaMigration` and `InternalMetadata` classes as arguments to
|
638
|
+
`ActiveRecord::MigrationContext`.
|
2256
639
|
|
2257
|
-
*
|
640
|
+
*Rafael Mendonça França*
|
2258
641
|
|
2259
|
-
*
|
642
|
+
* Remove deprecated `ActiveRecord::Migration.check_pending!` method.
|
2260
643
|
|
2261
|
-
|
2262
|
-
to the connection adapter. Consumers can implement custom strategy objects
|
2263
|
-
to change how their migrations run.
|
644
|
+
*Rafael Mendonça França*
|
2264
645
|
|
2265
|
-
|
646
|
+
* Remove deprecated `ActiveRecord::LogSubscriber.runtime` method.
|
2266
647
|
|
2267
|
-
*
|
648
|
+
*Rafael Mendonça França*
|
2268
649
|
|
2269
|
-
|
2270
|
-
foreign key constraints usage even if the underlying database supports them.
|
650
|
+
* Remove deprecated `ActiveRecord::LogSubscriber.runtime=` method.
|
2271
651
|
|
2272
|
-
|
2273
|
-
```yaml
|
2274
|
-
development:
|
2275
|
-
<<: *default
|
2276
|
-
database: storage/development.sqlite3
|
2277
|
-
foreign_keys: false
|
2278
|
-
```
|
652
|
+
*Rafael Mendonça França*
|
2279
653
|
|
2280
|
-
|
654
|
+
* Remove deprecated `ActiveRecord::LogSubscriber.reset_runtime` method.
|
2281
655
|
|
2282
|
-
*
|
656
|
+
*Rafael Mendonça França*
|
2283
657
|
|
2284
|
-
|
2285
|
-
It is possible to opt into the new more performant behavior with `config.active_record.allow_deprecated_singular_associations_name = false`
|
658
|
+
* Remove deprecated support to define `explain` in the connection adapter with 2 arguments.
|
2286
659
|
|
2287
|
-
*
|
660
|
+
*Rafael Mendonça França*
|
2288
661
|
|
2289
|
-
*
|
2290
|
-
record within a transaction.
|
662
|
+
* Remove deprecated `ActiveRecord::ActiveJobRequiredError`.
|
2291
663
|
|
2292
|
-
|
2293
|
-
transaction, Rails runs `after_commit` or `after_rollback` callbacks for
|
2294
|
-
only one of them. `config.active_record.run_commit_callbacks_on_first_saved_instances_in_transaction`
|
2295
|
-
was added to specify how Rails chooses which instance receives the
|
2296
|
-
callbacks. The framework defaults were changed to use the new logic.
|
664
|
+
*Rafael Mendonça França*
|
2297
665
|
|
2298
|
-
|
2299
|
-
is `true`, transactional callbacks are run on the first instance to save,
|
2300
|
-
even though its instance state may be stale.
|
666
|
+
* Remove deprecated `ActiveRecord::Base.clear_active_connections!`.
|
2301
667
|
|
2302
|
-
|
2303
|
-
7.1, transactional callbacks are run on the instances with the freshest
|
2304
|
-
instance state. Those instances are chosen as follows:
|
668
|
+
*Rafael Mendonça França*
|
2305
669
|
|
2306
|
-
|
2307
|
-
given record within the transaction.
|
2308
|
-
- There are two exceptions:
|
2309
|
-
- If the record is created within the transaction, then updated by
|
2310
|
-
another instance, `after_create_commit` callbacks will be run on the
|
2311
|
-
second instance. This is instead of the `after_update_commit`
|
2312
|
-
callbacks that would naively be run based on that instance’s state.
|
2313
|
-
- If the record is destroyed within the transaction, then
|
2314
|
-
`after_destroy_commit` callbacks will be fired on the last destroyed
|
2315
|
-
instance, even if a stale instance subsequently performed an update
|
2316
|
-
(which will have affected 0 rows).
|
670
|
+
* Remove deprecated `ActiveRecord::Base.clear_reloadable_connections!`.
|
2317
671
|
|
2318
|
-
*
|
672
|
+
*Rafael Mendonça França*
|
2319
673
|
|
2320
|
-
*
|
674
|
+
* Remove deprecated `ActiveRecord::Base.clear_all_connections!`.
|
2321
675
|
|
2322
|
-
|
676
|
+
*Rafael Mendonça França*
|
2323
677
|
|
2324
|
-
|
2325
|
-
It first tries to consider double-quoted strings as identifier names, but if they don't exist
|
2326
|
-
it then considers them as string literals. Because of this, typos can silently go unnoticed.
|
2327
|
-
For example, it is possible to create an index for a non existing column.
|
2328
|
-
See [SQLite documentation](https://www.sqlite.org/quirks.html#double_quoted_string_literals_are_accepted) for more details.
|
678
|
+
* Remove deprecated `ActiveRecord::Base.flush_idle_connections!`.
|
2329
679
|
|
2330
|
-
|
680
|
+
*Rafael Mendonça França*
|
2331
681
|
|
2332
|
-
|
2333
|
-
# config/application.rb
|
2334
|
-
config.active_record.sqlite3_adapter_strict_strings_by_default = false
|
2335
|
-
```
|
682
|
+
* Remove deprecated `name` argument from `ActiveRecord::Base.remove_connection`.
|
2336
683
|
|
2337
|
-
|
684
|
+
*Rafael Mendonça França*
|
2338
685
|
|
2339
|
-
|
686
|
+
* Remove deprecated support to call `alias_attribute` with non-existent attribute names.
|
2340
687
|
|
2341
|
-
*
|
688
|
+
*Rafael Mendonça França*
|
2342
689
|
|
2343
|
-
|
2344
|
-
ivar. This led to a confusing situation where despite having the correct data the relation
|
2345
|
-
still reported a stale cache_version.
|
690
|
+
* Remove deprecated `Rails.application.config.active_record.suppress_multiple_database_warning`.
|
2346
691
|
|
2347
|
-
|
692
|
+
*Rafael Mendonça França*
|
2348
693
|
|
2349
|
-
|
2350
|
-
developers = Developer.all
|
2351
|
-
developers.cache_version
|
694
|
+
* Add `ActiveRecord::Encryption::MessagePackMessageSerializer`.
|
2352
695
|
|
2353
|
-
|
696
|
+
Serialize data to the MessagePack format, for efficient storage in binary columns.
|
2354
697
|
|
2355
|
-
|
2356
|
-
|
2357
|
-
developers.cache_version # Returns the current correct cache_version
|
2358
|
-
```
|
698
|
+
The binary encoding requires around 30% less space than the base64 encoding
|
699
|
+
used by the default serializer.
|
2359
700
|
|
2360
|
-
|
701
|
+
*Donal McBreen*
|
2361
702
|
|
2362
|
-
|
703
|
+
* Add support for encrypting binary columns.
|
2363
704
|
|
2364
|
-
|
705
|
+
Ensure encryption and decryption pass `Type::Binary::Data` around for binary data.
|
2365
706
|
|
2366
|
-
|
2367
|
-
|
2368
|
-
remove_exclusion_constraint :invoices, name: "invoices_date_overlap"
|
2369
|
-
```
|
707
|
+
Previously encrypting binary columns with the `ActiveRecord::Encryption::MessageSerializer`
|
708
|
+
incidentally worked for MySQL and SQLite, but not PostgreSQL.
|
2370
709
|
|
2371
|
-
|
710
|
+
*Donal McBreen*
|
2372
711
|
|
2373
|
-
|
712
|
+
* Deprecated `ENV["SCHEMA_CACHE"]` in favor of `schema_cache_path` in the database configuration.
|
2374
713
|
|
2375
|
-
*
|
714
|
+
*Rafael Mendonça França*
|
2376
715
|
|
2377
|
-
|
2378
|
-
treat it as truthy and make your column nullable. This could be surprising, so now
|
2379
|
-
the input must be either `true` or `false`.
|
716
|
+
* Add `ActiveRecord::Base.with_connection` as a shortcut for leasing a connection for a short duration.
|
2380
717
|
|
2381
|
-
|
2382
|
-
|
2383
|
-
change_column_null :table, :column, false # good
|
2384
|
-
change_column_null :table, :column, from: true, to: false # raises (previously this made the column nullable)
|
2385
|
-
```
|
718
|
+
The leased connection is yielded, and for the duration of the block, any call to `ActiveRecord::Base.connection`
|
719
|
+
will yield that same connection.
|
2386
720
|
|
2387
|
-
|
721
|
+
This is useful to perform a few database operations without causing a connection to be leased for the
|
722
|
+
entire duration of the request or job.
|
2388
723
|
|
2389
|
-
*
|
724
|
+
*Jean Boussier*
|
2390
725
|
|
2391
|
-
|
726
|
+
* Deprecate `config.active_record.warn_on_records_fetched_greater_than` now that `sql.active_record`
|
727
|
+
notification includes `:row_count` field.
|
2392
728
|
|
2393
|
-
*
|
729
|
+
*Jason Nochlin*
|
2394
730
|
|
2395
|
-
*
|
731
|
+
* The fix ensures that the association is joined using the appropriate join type
|
732
|
+
(either inner join or left outer join) based on the existing joins in the scope.
|
2396
733
|
|
2397
|
-
|
734
|
+
This prevents unintentional overrides of existing join types and ensures consistency in the generated SQL queries.
|
2398
735
|
|
2399
|
-
|
736
|
+
Example:
|
2400
737
|
|
2401
|
-
*edsharp*
|
2402
738
|
|
2403
|
-
* Add validity for PostgreSQL indexes.
|
2404
739
|
|
2405
740
|
```ruby
|
2406
|
-
|
2407
|
-
|
741
|
+
# `associated` will use `LEFT JOIN` instead of using `JOIN`
|
742
|
+
Post.left_joins(:author).where.associated(:author)
|
2408
743
|
```
|
2409
744
|
|
2410
|
-
*
|
745
|
+
*Saleh Alhaddad*
|
2411
746
|
|
2412
|
-
* Fix
|
747
|
+
* Fix an issue where `ActiveRecord::Encryption` configurations are not ready before the loading
|
748
|
+
of Active Record models, when an application is eager loaded. As a result, encrypted attributes
|
749
|
+
could be misconfigured in some cases.
|
2413
750
|
|
2414
|
-
*
|
751
|
+
*Maxime Réty*
|
2415
752
|
|
2416
|
-
*
|
753
|
+
* Deprecate defining an `enum` with keyword arguments.
|
2417
754
|
|
2418
|
-
|
2419
|
-
|
2420
|
-
|
2421
|
-
|
755
|
+
```ruby
|
756
|
+
class Function > ApplicationRecord
|
757
|
+
# BAD
|
758
|
+
enum color: [:red, :blue],
|
759
|
+
type: [:instance, :class]
|
2422
760
|
|
2423
|
-
|
761
|
+
# GOOD
|
762
|
+
enum :color, [:red, :blue]
|
763
|
+
enum :type, [:instance, :class]
|
764
|
+
end
|
765
|
+
```
|
2424
766
|
|
2425
|
-
*
|
767
|
+
*Hartley McGuire*
|
2426
768
|
|
2427
|
-
|
769
|
+
* Add `config.active_record.validate_migration_timestamps` option for validating migration timestamps.
|
2428
770
|
|
2429
|
-
|
771
|
+
When set, validates that the timestamp prefix for a migration is no more than a day ahead of
|
772
|
+
the timestamp associated with the current time. This is designed to prevent migrations prefixes
|
773
|
+
from being hand-edited to future timestamps, which impacts migration generation and other
|
774
|
+
migration commands.
|
2430
775
|
|
2431
|
-
*
|
776
|
+
*Adrianna Chang*
|
2432
777
|
|
2433
|
-
|
778
|
+
* Properly synchronize `Mysql2Adapter#active?` and `TrilogyAdapter#active?`.
|
2434
779
|
|
2435
|
-
|
780
|
+
As well as `disconnect!` and `verify!`.
|
2436
781
|
|
2437
|
-
|
2438
|
-
|
2439
|
-
|
782
|
+
This generally isn't a big problem as connections must not be shared between
|
783
|
+
threads, but is required when running transactional tests or system tests
|
784
|
+
and could lead to a SEGV.
|
2440
785
|
|
2441
|
-
*
|
786
|
+
*Jean Boussier*
|
787
|
+
|
788
|
+
* Support `:source_location` tag option for query log tags.
|
2442
789
|
|
2443
|
-
|
790
|
+
```ruby
|
791
|
+
config.active_record.query_log_tags << :source_location
|
792
|
+
```
|
2444
793
|
|
2445
|
-
|
2446
|
-
|
2447
|
-
|
794
|
+
Calculating the caller location is a costly operation and should be used primarily in development
|
795
|
+
(note, there is also a `config.active_record.verbose_query_logs` that serves the same purpose)
|
796
|
+
or occasionally on production for debugging purposes.
|
2448
797
|
|
2449
|
-
|
2450
|
-
`minimum` and `maximum`
|
798
|
+
*fatkodima*
|
2451
799
|
|
2452
|
-
|
800
|
+
* Add an option to `ActiveRecord::Encryption::Encryptor` to disable compression.
|
2453
801
|
|
2454
|
-
|
802
|
+
Allow compression to be disabled by setting `compress: false`
|
2455
803
|
|
2456
804
|
```ruby
|
2457
|
-
|
2458
|
-
|
2459
|
-
|
2460
|
-
|
2461
|
-
Book.insert_all [{ title: "Remote", author_id: 1 }], returning: :title
|
805
|
+
class User
|
806
|
+
encrypts :name, encryptor: ActiveRecord::Encryption::Encryptor.new(compress: false)
|
807
|
+
end
|
2462
808
|
```
|
2463
809
|
|
2464
|
-
*
|
810
|
+
*Donal McBreen*
|
2465
811
|
|
2466
|
-
*
|
812
|
+
* Deprecate passing strings to `ActiveRecord::Tasks::DatabaseTasks.cache_dump_filename`.
|
2467
813
|
|
2468
|
-
|
2469
|
-
It will encrypt those values at creation time. Before, it would raise an
|
2470
|
-
error unless `config.active_record.encryption.support_unencrypted_data` was true.
|
814
|
+
A `ActiveRecord::DatabaseConfigurations::DatabaseConfig` object should be passed instead.
|
2471
815
|
|
2472
|
-
*
|
816
|
+
*Rafael Mendonça França*
|
2473
817
|
|
2474
|
-
*
|
818
|
+
* Add `row_count` field to `sql.active_record` notification.
|
2475
819
|
|
2476
|
-
|
2477
|
-
but you can now change it to anything you like. If the method returns true,
|
2478
|
-
`Resolver#read` gets called meaning the request could be served by the
|
2479
|
-
replica database.
|
820
|
+
This field returns the amount of rows returned by the query that emitted the notification.
|
2480
821
|
|
2481
|
-
|
822
|
+
This metric is useful in cases where one wants to detect queries with big result sets.
|
2482
823
|
|
2483
|
-
*
|
824
|
+
*Marvin Bitterlich*
|
2484
825
|
|
2485
|
-
|
826
|
+
* Consistently raise an `ArgumentError` when passing an invalid argument to a nested attributes association writer.
|
2486
827
|
|
2487
|
-
|
828
|
+
Previously, this would only raise on collection associations and produce a generic error on singular associations.
|
2488
829
|
|
2489
|
-
|
2490
|
-
way to dump a schema to both SQL and Ruby formats. You can now do this with
|
2491
|
-
an environment variable. For example:
|
830
|
+
Now, it will raise on both collection and singular associations.
|
2492
831
|
|
2493
|
-
|
2494
|
-
|
2495
|
-
|
832
|
+
*Joshua Young*
|
833
|
+
|
834
|
+
* Fix single quote escapes on default generated MySQL columns.
|
2496
835
|
|
2497
|
-
|
836
|
+
MySQL 5.7.5+ supports generated columns, which can be used to create a column that is computed from an expression.
|
2498
837
|
|
2499
|
-
|
838
|
+
Previously, the schema dump would output a string with double escapes for generated columns with single quotes in the default expression.
|
2500
839
|
|
2501
|
-
|
2502
|
-
if using `db:schema:load`. Further more the function name would be
|
2503
|
-
added as string content when saving new records.
|
840
|
+
This would result in issues when importing the schema on a fresh instance of a MySQL database.
|
2504
841
|
|
2505
|
-
|
842
|
+
Now, the string will not be escaped and will be valid Ruby upon importing of the schema.
|
2506
843
|
|
2507
|
-
*
|
844
|
+
*Yash Kapadia*
|
2508
845
|
|
2509
|
-
|
2510
|
-
|
2511
|
-
association option. By default, the current behavior will remain the same:
|
2512
|
-
when a parent record is destroyed, all dependent records will be destroyed
|
2513
|
-
in a single background job. If the number of dependent records is greater
|
2514
|
-
than this configuration, the records will be destroyed in multiple
|
2515
|
-
background jobs.
|
846
|
+
* Fix Migrations with versions older than 7.1 validating options given to
|
847
|
+
`add_reference` and `t.references`.
|
2516
848
|
|
2517
|
-
*
|
849
|
+
*Hartley McGuire*
|
2518
850
|
|
2519
|
-
*
|
851
|
+
* Add `<role>_types` class method to `ActiveRecord::DelegatedType` so that the delegated types can be introspected.
|
2520
852
|
|
2521
|
-
*
|
853
|
+
*JP Rosevear*
|
2522
854
|
|
2523
|
-
*
|
855
|
+
* Make `schema_dump`, `query_cache`, `replica` and `database_tasks` configurable via `DATABASE_URL`.
|
2524
856
|
|
2525
|
-
This
|
2526
|
-
comments in your structure dump, you can use:
|
857
|
+
This wouldn't always work previously because boolean values would be interpreted as strings.
|
2527
858
|
|
2528
|
-
|
2529
|
-
|
2530
|
-
```
|
859
|
+
e.g. `DATABASE_URL=postgres://localhost/foo?schema_dump=false` now properly disable dumping the schema
|
860
|
+
cache.
|
2531
861
|
|
2532
|
-
*
|
862
|
+
*Mike Coutermarsh*, *Jean Boussier*
|
2533
863
|
|
2534
|
-
*
|
864
|
+
* Introduce `ActiveRecord::Transactions::ClassMethods#set_callback`.
|
2535
865
|
|
2536
|
-
|
2537
|
-
|
2538
|
-
test suites.
|
866
|
+
It is identical to `ActiveSupport::Callbacks::ClassMethods#set_callback`
|
867
|
+
but with support for `after_commit` and `after_rollback` callback options.
|
2539
868
|
|
2540
|
-
|
2541
|
-
so they incur much less memory and CPU overhead.
|
869
|
+
*Joshua Young*
|
2542
870
|
|
2543
|
-
|
871
|
+
* Make `ActiveRecord::Encryption::Encryptor` agnostic of the serialization format used for encrypted data.
|
2544
872
|
|
2545
|
-
|
873
|
+
Previously, the encryptor instance only allowed an encrypted value serialized as a `String` to be passed to the message serializer.
|
2546
874
|
|
2547
|
-
`
|
2548
|
-
applications to specify the job that will be used to destroy associated
|
2549
|
-
records in the background for `has_many` associations with the
|
2550
|
-
`dependent: :destroy_async` option. Previously, that was ignored, which
|
2551
|
-
meant the default `ActiveRecord::DestroyAssociationAsyncJob` always
|
2552
|
-
destroyed records in the background.
|
875
|
+
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`.
|
2553
876
|
|
2554
|
-
|
877
|
+
The default `ActiveRecord::Encryption::MessageSerializer` already ensures that only `String` objects are passed for deserialization.
|
2555
878
|
|
2556
|
-
*
|
879
|
+
*Maxime Réty*
|
2557
880
|
|
2558
|
-
|
881
|
+
* Fix `encrypted_attribute?` to take into account context properties passed to `encrypts`.
|
882
|
+
|
883
|
+
*Maxime Réty*
|
2559
884
|
|
2560
|
-
*
|
885
|
+
* The object returned by `explain` now responds to `pluck`, `first`,
|
886
|
+
`last`, `average`, `count`, `maximum`, `minimum`, and `sum`. Those
|
887
|
+
new methods run `EXPLAIN` on the corresponding queries:
|
2561
888
|
|
2562
|
-
|
889
|
+
```ruby
|
890
|
+
User.all.explain.count
|
891
|
+
# EXPLAIN SELECT COUNT(*) FROM `users`
|
892
|
+
# ...
|
2563
893
|
|
2564
|
-
|
894
|
+
User.all.explain.maximum(:id)
|
895
|
+
# EXPLAIN SELECT MAX(`users`.`id`) FROM `users`
|
896
|
+
# ...
|
897
|
+
```
|
2565
898
|
|
2566
|
-
*
|
899
|
+
*Petrik de Heus*
|
2567
900
|
|
2568
|
-
*
|
901
|
+
* Fixes an issue where `validates_associated` `:on` option wasn't respected
|
902
|
+
when validating associated records.
|
2569
903
|
|
2570
|
-
*
|
904
|
+
*Austen Madden*, *Alex Ghiculescu*, *Rafał Brize*
|
2571
905
|
|
2572
|
-
*
|
906
|
+
* Allow overriding SQLite defaults from `database.yml`.
|
2573
907
|
|
2574
|
-
|
2575
|
-
|
908
|
+
Any PRAGMA configuration set under the `pragmas` key in the configuration
|
909
|
+
file takes precedence over Rails' defaults, and additional PRAGMAs can be
|
910
|
+
set as well.
|
2576
911
|
|
2577
|
-
|
2578
|
-
|
912
|
+
```yaml
|
913
|
+
database: storage/development.sqlite3
|
914
|
+
timeout: 5000
|
915
|
+
pragmas:
|
916
|
+
journal_mode: off
|
917
|
+
temp_store: memory
|
918
|
+
```
|
2579
919
|
|
2580
|
-
*
|
920
|
+
*Stephen Margheim*
|
2581
921
|
|
2582
|
-
*
|
922
|
+
* Remove warning message when running SQLite in production, but leave it unconfigured.
|
2583
923
|
|
2584
|
-
|
924
|
+
There are valid use cases for running SQLite in production. However, it must be done
|
925
|
+
with care, so instead of a warning most users won't see anyway, it's preferable to
|
926
|
+
leave the configuration commented out to force them to think about having the database
|
927
|
+
on a persistent volume etc.
|
2585
928
|
|
2586
|
-
*
|
929
|
+
*Jacopo Beschi*, *Jean Boussier*
|
2587
930
|
|
2588
|
-
*
|
931
|
+
* Add support for generated columns to the SQLite3 adapter.
|
2589
932
|
|
2590
|
-
|
2591
|
-
|
2592
|
-
disallows rollbacks of savepoints following a deadlock.
|
933
|
+
Generated columns (both stored and dynamic) are supported since version 3.31.0 of SQLite.
|
934
|
+
This adds support for those to the SQLite3 adapter.
|
2593
935
|
|
2594
|
-
|
2595
|
-
|
936
|
+
```ruby
|
937
|
+
create_table :users do |t|
|
938
|
+
t.string :name
|
939
|
+
t.virtual :name_upper, type: :string, as: 'UPPER(name)'
|
940
|
+
t.virtual :name_lower, type: :string, as: 'LOWER(name)', stored: true
|
941
|
+
end
|
942
|
+
```
|
2596
943
|
|
2597
|
-
|
944
|
+
*Stephen Margheim*
|
2598
945
|
|
2599
|
-
|
946
|
+
* TrilogyAdapter: ignore `host` if `socket` parameter is set.
|
2600
947
|
|
2601
|
-
|
948
|
+
This allows to configure a connection on a UNIX socket via `DATABASE_URL`:
|
2602
949
|
|
2603
|
-
|
2604
|
-
|
2605
|
-
|
950
|
+
```
|
951
|
+
DATABASE_URL=trilogy://does-not-matter/my_db_production?socket=/var/run/mysql.sock
|
952
|
+
```
|
2606
953
|
|
2607
|
-
*
|
954
|
+
*Jean Boussier*
|
2608
955
|
|
2609
|
-
*
|
956
|
+
* Make `assert_queries_count`, `assert_no_queries`, `assert_queries_match`, and
|
957
|
+
`assert_no_queries_match` assertions public.
|
2610
958
|
|
2611
|
-
|
959
|
+
To assert the expected number of queries are made, Rails internally uses `assert_queries_count` and
|
960
|
+
`assert_no_queries`. To assert that specific SQL queries are made, `assert_queries_match` and
|
961
|
+
`assert_no_queries_match` are used. These assertions can now be used in applications as well.
|
2612
962
|
|
2613
963
|
```ruby
|
2614
|
-
class
|
2615
|
-
|
964
|
+
class ArticleTest < ActiveSupport::TestCase
|
965
|
+
test "queries are made" do
|
966
|
+
assert_queries_count(1) { Article.first }
|
967
|
+
end
|
2616
968
|
|
2617
|
-
|
2618
|
-
|
969
|
+
test "creates a foreign key" do
|
970
|
+
assert_queries_match(/ADD FOREIGN KEY/i, include_schema: true) do
|
971
|
+
@connection.add_foreign_key(:comments, :posts)
|
972
|
+
end
|
2619
973
|
end
|
2620
974
|
end
|
2621
|
-
|
2622
|
-
topic = Topic.create(title: "Test Title")
|
2623
|
-
# #=> #<Topic title: "Test Title">
|
2624
|
-
topic.update_attribute!(:title, "Another Title")
|
2625
|
-
# #=> #<Topic title: "Another Title">
|
2626
|
-
topic.update_attribute!(:title, "abort")
|
2627
|
-
# raises ActiveRecord::RecordNotSaved
|
2628
975
|
```
|
2629
976
|
|
2630
|
-
*
|
977
|
+
*Petrik de Heus*, *fatkodima*
|
2631
978
|
|
2632
|
-
*
|
979
|
+
* Fix `has_secure_token` calls the setter method on initialize.
|
2633
980
|
|
2634
|
-
|
2635
|
-
# Before
|
2636
|
-
pp Foo.all # Loads the whole table.
|
981
|
+
*Abeid Ahmed*
|
2637
982
|
|
2638
|
-
|
2639
|
-
|
983
|
+
* When using a `DATABASE_URL`, allow for a configuration to map the protocol in the URL to a specific database
|
984
|
+
adapter. This allows decoupling the adapter the application chooses to use from the database connection details
|
985
|
+
set in the deployment environment.
|
986
|
+
|
987
|
+
```ruby
|
988
|
+
# ENV['DATABASE_URL'] = "mysql://localhost/example_database"
|
989
|
+
config.active_record.protocol_adapters.mysql = "trilogy"
|
990
|
+
# will connect to MySQL using the trilogy adapter
|
2640
991
|
```
|
2641
992
|
|
2642
|
-
*
|
993
|
+
*Jean Boussier*, *Kevin McPhillips*
|
994
|
+
|
995
|
+
* In cases where MySQL returns `warning_count` greater than zero, but returns no warnings when
|
996
|
+
the `SHOW WARNINGS` query is executed, `ActiveRecord.db_warnings_action` proc will still be
|
997
|
+
called with a generic warning message rather than silently ignoring the warning(s).
|
2643
998
|
|
2644
|
-
*
|
999
|
+
*Kevin McPhillips*
|
1000
|
+
|
1001
|
+
* `DatabaseConfigurations#configs_for` accepts a symbol in the `name` parameter.
|
1002
|
+
|
1003
|
+
*Andrew Novoselac*
|
2645
1004
|
|
2646
|
-
|
1005
|
+
* Fix `where(field: values)` queries when `field` is a serialized attribute
|
1006
|
+
(for example, when `field` uses `ActiveRecord::Base.serialize` or is a JSON
|
1007
|
+
column).
|
2647
1008
|
|
2648
|
-
*
|
1009
|
+
*João Alves*
|
2649
1010
|
|
2650
|
-
*
|
1011
|
+
* Make the output of `ActiveRecord::Core#inspect` configurable.
|
2651
1012
|
|
2652
|
-
|
1013
|
+
By default, calling `inspect` on a record will yield a formatted string including just the `id`.
|
2653
1014
|
|
2654
1015
|
```ruby
|
2655
|
-
|
1016
|
+
Post.first.inspect #=> "#<Post id: 1>"
|
2656
1017
|
```
|
2657
1018
|
|
2658
|
-
|
1019
|
+
The attributes to be included in the output of `inspect` can be configured with
|
1020
|
+
`ActiveRecord::Core#attributes_for_inspect`.
|
2659
1021
|
|
2660
|
-
|
1022
|
+
```ruby
|
1023
|
+
Post.attributes_for_inspect = [:id, :title]
|
1024
|
+
Post.first.inspect #=> "#<Post id: 1, title: "Hello, World!">"
|
1025
|
+
```
|
2661
1026
|
|
2662
|
-
|
1027
|
+
With `attributes_for_inspect` set to `:all`, `inspect` will list all the record's attributes.
|
2663
1028
|
|
2664
|
-
|
1029
|
+
```ruby
|
1030
|
+
Post.attributes_for_inspect = :all
|
1031
|
+
Post.first.inspect #=> "#<Post id: 1, title: "Hello, World!", published_at: "2023-10-23 14:28:11 +0000">"
|
1032
|
+
```
|
2665
1033
|
|
2666
|
-
|
1034
|
+
In `development` and `test` mode, `attributes_for_inspect` will be set to `:all` by default.
|
2667
1035
|
|
2668
|
-
|
1036
|
+
You can also call `full_inspect` to get an inspection with all the attributes.
|
2669
1037
|
|
2670
|
-
|
2671
|
-
bigint instead of integer for the SQLite Adapter.
|
1038
|
+
The attributes in `attribute_for_inspect` will also be used for `pretty_print`.
|
2672
1039
|
|
2673
|
-
*
|
1040
|
+
*Andrew Novoselac*
|
2674
1041
|
|
2675
|
-
*
|
1042
|
+
* Don't mark attributes as changed when reassigned to `Float::INFINITY` or
|
1043
|
+
`-Float::INFINITY`.
|
2676
1044
|
|
2677
|
-
|
2678
|
-
Post.in_order_of(:id, []).to_a
|
2679
|
-
```
|
1045
|
+
*Maicol Bentancor*
|
2680
1046
|
|
2681
|
-
|
2682
|
-
value is still ordered.
|
1047
|
+
* Support the `RETURNING` clause for MariaDB.
|
2683
1048
|
|
2684
|
-
*
|
1049
|
+
*fatkodima*, *Nikolay Kondratyev*
|
2685
1050
|
|
2686
|
-
*
|
1051
|
+
* The SQLite3 adapter now implements the `supports_deferrable_constraints?` contract.
|
2687
1052
|
|
2688
|
-
|
2689
|
-
is a valid identifier.
|
1053
|
+
Allows foreign keys to be deferred by adding the `:deferrable` key to the `foreign_key` options.
|
2690
1054
|
|
2691
1055
|
```ruby
|
2692
|
-
|
2693
|
-
|
2694
|
-
end
|
2695
|
-
Test.group(:id).count
|
2696
|
-
# syntax error at or near "1" (ActiveRecord::StatementInvalid)
|
2697
|
-
# LINE 1: SELECT COUNT(*) AS count_all, "1abc"."id" AS 1abc_id FROM "1...
|
1056
|
+
add_reference :person, :alias, foreign_key: { deferrable: :deferred }
|
1057
|
+
add_reference :alias, :person, foreign_key: { deferrable: :deferred }
|
2698
1058
|
```
|
2699
1059
|
|
2700
|
-
*
|
2701
|
-
|
2702
|
-
* Add `authenticate_by` when using `has_secure_password`.
|
1060
|
+
*Stephen Margheim*
|
2703
1061
|
|
2704
|
-
|
2705
|
-
returns early when a user with a matching email is not found:
|
1062
|
+
* Add the `set_constraints` helper to PostgreSQL connections.
|
2706
1063
|
|
2707
1064
|
```ruby
|
2708
|
-
|
1065
|
+
Post.create!(user_id: -1) # => ActiveRecord::InvalidForeignKey
|
1066
|
+
|
1067
|
+
Post.transaction do
|
1068
|
+
Post.connection.set_constraints(:deferred)
|
1069
|
+
p = Post.create!(user_id: -1)
|
1070
|
+
u = User.create!
|
1071
|
+
p.user = u
|
1072
|
+
p.save!
|
1073
|
+
end
|
2709
1074
|
```
|
2710
1075
|
|
2711
|
-
|
2712
|
-
|
2713
|
-
|
2714
|
-
|
2715
|
-
|
2716
|
-
|
2717
|
-
|
1076
|
+
*Cody Cutrer*
|
1077
|
+
|
1078
|
+
* Include `ActiveModel::API` in `ActiveRecord::Base`.
|
1079
|
+
|
1080
|
+
*Sean Doyle*
|
1081
|
+
|
1082
|
+
* Ensure `#signed_id` outputs `url_safe` strings.
|
2718
1083
|
|
2719
|
-
|
2720
|
-
|
1084
|
+
*Jason Meller*
|
1085
|
+
|
1086
|
+
* Add `nulls_last` and working `desc.nulls_first` for MySQL.
|
1087
|
+
|
1088
|
+
*Tristan Fellows*
|
1089
|
+
|
1090
|
+
* Allow for more complex hash arguments for `order` which mimics `where` in `ActiveRecord::Relation`.
|
2721
1091
|
|
2722
1092
|
```ruby
|
2723
|
-
|
1093
|
+
Topic.includes(:posts).order(posts: { created_at: :desc })
|
2724
1094
|
```
|
2725
1095
|
|
2726
|
-
*
|
2727
|
-
|
1096
|
+
*Myles Boone*
|
2728
1097
|
|
2729
|
-
Please check [7-
|
1098
|
+
Please check [7-1-stable](https://github.com/rails/rails/blob/7-1-stable/activerecord/CHANGELOG.md) for previous changes.
|