activerecord 7.2.1.1 → 8.0.0.rc1

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