activerecord 7.0.8 → 7.2.0

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 (277) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +530 -2004
  3. data/MIT-LICENSE +1 -1
  4. data/README.rdoc +29 -29
  5. data/examples/performance.rb +2 -2
  6. data/lib/active_record/aggregations.rb +16 -13
  7. data/lib/active_record/association_relation.rb +2 -2
  8. data/lib/active_record/associations/alias_tracker.rb +25 -19
  9. data/lib/active_record/associations/association.rb +35 -12
  10. data/lib/active_record/associations/association_scope.rb +16 -9
  11. data/lib/active_record/associations/belongs_to_association.rb +23 -8
  12. data/lib/active_record/associations/belongs_to_polymorphic_association.rb +3 -2
  13. data/lib/active_record/associations/builder/association.rb +3 -3
  14. data/lib/active_record/associations/builder/belongs_to.rb +22 -8
  15. data/lib/active_record/associations/builder/has_and_belongs_to_many.rb +3 -7
  16. data/lib/active_record/associations/builder/has_many.rb +3 -4
  17. data/lib/active_record/associations/builder/has_one.rb +3 -4
  18. data/lib/active_record/associations/builder/singular_association.rb +4 -0
  19. data/lib/active_record/associations/collection_association.rb +26 -14
  20. data/lib/active_record/associations/collection_proxy.rb +29 -11
  21. data/lib/active_record/associations/errors.rb +265 -0
  22. data/lib/active_record/associations/foreign_association.rb +10 -3
  23. data/lib/active_record/associations/has_many_association.rb +21 -14
  24. data/lib/active_record/associations/has_many_through_association.rb +10 -6
  25. data/lib/active_record/associations/has_one_association.rb +10 -3
  26. data/lib/active_record/associations/join_dependency/join_association.rb +27 -25
  27. data/lib/active_record/associations/join_dependency.rb +5 -5
  28. data/lib/active_record/associations/nested_error.rb +47 -0
  29. data/lib/active_record/associations/preloader/association.rb +33 -8
  30. data/lib/active_record/associations/preloader/branch.rb +7 -1
  31. data/lib/active_record/associations/preloader/through_association.rb +1 -3
  32. data/lib/active_record/associations/preloader.rb +13 -10
  33. data/lib/active_record/associations/singular_association.rb +7 -1
  34. data/lib/active_record/associations/through_association.rb +22 -11
  35. data/lib/active_record/associations.rb +328 -471
  36. data/lib/active_record/attribute_assignment.rb +1 -13
  37. data/lib/active_record/attribute_methods/before_type_cast.rb +17 -0
  38. data/lib/active_record/attribute_methods/composite_primary_key.rb +84 -0
  39. data/lib/active_record/attribute_methods/dirty.rb +53 -35
  40. data/lib/active_record/attribute_methods/primary_key.rb +45 -25
  41. data/lib/active_record/attribute_methods/query.rb +28 -16
  42. data/lib/active_record/attribute_methods/read.rb +8 -7
  43. data/lib/active_record/attribute_methods/serialization.rb +131 -32
  44. data/lib/active_record/attribute_methods/time_zone_conversion.rb +7 -6
  45. data/lib/active_record/attribute_methods/write.rb +6 -6
  46. data/lib/active_record/attribute_methods.rb +148 -33
  47. data/lib/active_record/attributes.rb +58 -45
  48. data/lib/active_record/autosave_association.rb +69 -37
  49. data/lib/active_record/base.rb +9 -5
  50. data/lib/active_record/callbacks.rb +10 -24
  51. data/lib/active_record/coders/column_serializer.rb +61 -0
  52. data/lib/active_record/coders/json.rb +1 -1
  53. data/lib/active_record/coders/yaml_column.rb +70 -42
  54. data/lib/active_record/connection_adapters/abstract/connection_handler.rb +123 -131
  55. data/lib/active_record/connection_adapters/abstract/connection_pool/queue.rb +2 -0
  56. data/lib/active_record/connection_adapters/abstract/connection_pool/reaper.rb +4 -1
  57. data/lib/active_record/connection_adapters/abstract/connection_pool.rb +317 -88
  58. data/lib/active_record/connection_adapters/abstract/database_limits.rb +5 -0
  59. data/lib/active_record/connection_adapters/abstract/database_statements.rb +160 -45
  60. data/lib/active_record/connection_adapters/abstract/query_cache.rb +188 -63
  61. data/lib/active_record/connection_adapters/abstract/quoting.rb +72 -63
  62. data/lib/active_record/connection_adapters/abstract/savepoints.rb +4 -3
  63. data/lib/active_record/connection_adapters/abstract/schema_creation.rb +18 -4
  64. data/lib/active_record/connection_adapters/abstract/schema_definitions.rb +137 -11
  65. data/lib/active_record/connection_adapters/abstract/schema_statements.rb +306 -128
  66. data/lib/active_record/connection_adapters/abstract/transaction.rb +367 -75
  67. data/lib/active_record/connection_adapters/abstract_adapter.rb +510 -111
  68. data/lib/active_record/connection_adapters/abstract_mysql_adapter.rb +274 -125
  69. data/lib/active_record/connection_adapters/column.rb +9 -0
  70. data/lib/active_record/connection_adapters/mysql/column.rb +1 -0
  71. data/lib/active_record/connection_adapters/mysql/database_statements.rb +26 -139
  72. data/lib/active_record/connection_adapters/mysql/quoting.rb +53 -54
  73. data/lib/active_record/connection_adapters/mysql/schema_creation.rb +9 -0
  74. data/lib/active_record/connection_adapters/mysql/schema_definitions.rb +6 -0
  75. data/lib/active_record/connection_adapters/mysql/schema_dumper.rb +1 -1
  76. data/lib/active_record/connection_adapters/mysql/schema_statements.rb +25 -13
  77. data/lib/active_record/connection_adapters/mysql2/database_statements.rb +152 -0
  78. data/lib/active_record/connection_adapters/mysql2_adapter.rb +101 -68
  79. data/lib/active_record/connection_adapters/pool_config.rb +20 -10
  80. data/lib/active_record/connection_adapters/pool_manager.rb +19 -9
  81. data/lib/active_record/connection_adapters/postgresql/column.rb +14 -3
  82. data/lib/active_record/connection_adapters/postgresql/database_statements.rb +100 -43
  83. data/lib/active_record/connection_adapters/postgresql/oid/cidr.rb +6 -0
  84. data/lib/active_record/connection_adapters/postgresql/oid/interval.rb +1 -1
  85. data/lib/active_record/connection_adapters/postgresql/oid/money.rb +3 -2
  86. data/lib/active_record/connection_adapters/postgresql/oid/range.rb +11 -2
  87. data/lib/active_record/connection_adapters/postgresql/oid/timestamp_with_time_zone.rb +1 -1
  88. data/lib/active_record/connection_adapters/postgresql/oid/uuid.rb +14 -4
  89. data/lib/active_record/connection_adapters/postgresql/quoting.rb +65 -61
  90. data/lib/active_record/connection_adapters/postgresql/referential_integrity.rb +3 -9
  91. data/lib/active_record/connection_adapters/postgresql/schema_creation.rb +76 -6
  92. data/lib/active_record/connection_adapters/postgresql/schema_definitions.rb +151 -2
  93. data/lib/active_record/connection_adapters/postgresql/schema_dumper.rb +53 -0
  94. data/lib/active_record/connection_adapters/postgresql/schema_statements.rb +368 -63
  95. data/lib/active_record/connection_adapters/postgresql_adapter.rb +364 -198
  96. data/lib/active_record/connection_adapters/schema_cache.rb +302 -79
  97. data/lib/active_record/connection_adapters/sqlite3/column.rb +62 -0
  98. data/lib/active_record/connection_adapters/sqlite3/database_statements.rb +60 -43
  99. data/lib/active_record/connection_adapters/sqlite3/quoting.rb +45 -46
  100. data/lib/active_record/connection_adapters/sqlite3/schema_creation.rb +22 -0
  101. data/lib/active_record/connection_adapters/sqlite3/schema_definitions.rb +14 -0
  102. data/lib/active_record/connection_adapters/sqlite3/schema_dumper.rb +16 -0
  103. data/lib/active_record/connection_adapters/sqlite3/schema_statements.rb +50 -8
  104. data/lib/active_record/connection_adapters/sqlite3_adapter.rb +290 -110
  105. data/lib/active_record/connection_adapters/statement_pool.rb +7 -0
  106. data/lib/active_record/connection_adapters/trilogy/database_statements.rb +99 -0
  107. data/lib/active_record/connection_adapters/trilogy_adapter.rb +229 -0
  108. data/lib/active_record/connection_adapters.rb +124 -1
  109. data/lib/active_record/connection_handling.rb +96 -104
  110. data/lib/active_record/core.rb +217 -174
  111. data/lib/active_record/counter_cache.rb +68 -34
  112. data/lib/active_record/database_configurations/connection_url_resolver.rb +7 -2
  113. data/lib/active_record/database_configurations/database_config.rb +26 -5
  114. data/lib/active_record/database_configurations/hash_config.rb +52 -34
  115. data/lib/active_record/database_configurations/url_config.rb +37 -12
  116. data/lib/active_record/database_configurations.rb +87 -34
  117. data/lib/active_record/delegated_type.rb +39 -10
  118. data/lib/active_record/deprecator.rb +7 -0
  119. data/lib/active_record/destroy_association_async_job.rb +3 -1
  120. data/lib/active_record/dynamic_matchers.rb +2 -2
  121. data/lib/active_record/encryption/auto_filtered_parameters.rb +66 -0
  122. data/lib/active_record/encryption/cipher/aes256_gcm.rb +4 -1
  123. data/lib/active_record/encryption/config.rb +25 -1
  124. data/lib/active_record/encryption/configurable.rb +12 -19
  125. data/lib/active_record/encryption/context.rb +10 -3
  126. data/lib/active_record/encryption/contexts.rb +5 -1
  127. data/lib/active_record/encryption/derived_secret_key_provider.rb +8 -2
  128. data/lib/active_record/encryption/encryptable_record.rb +44 -20
  129. data/lib/active_record/encryption/encrypted_attribute_type.rb +45 -10
  130. data/lib/active_record/encryption/encryptor.rb +17 -2
  131. data/lib/active_record/encryption/extended_deterministic_queries.rb +66 -69
  132. data/lib/active_record/encryption/extended_deterministic_uniqueness_validator.rb +3 -3
  133. data/lib/active_record/encryption/key_generator.rb +12 -1
  134. data/lib/active_record/encryption/message_pack_message_serializer.rb +76 -0
  135. data/lib/active_record/encryption/message_serializer.rb +6 -0
  136. data/lib/active_record/encryption/null_encryptor.rb +4 -0
  137. data/lib/active_record/encryption/properties.rb +3 -3
  138. data/lib/active_record/encryption/read_only_null_encryptor.rb +4 -0
  139. data/lib/active_record/encryption/scheme.rb +22 -21
  140. data/lib/active_record/encryption.rb +1 -0
  141. data/lib/active_record/enum.rb +122 -29
  142. data/lib/active_record/errors.rb +151 -31
  143. data/lib/active_record/explain.rb +21 -12
  144. data/lib/active_record/fixture_set/model_metadata.rb +14 -4
  145. data/lib/active_record/fixture_set/render_context.rb +2 -0
  146. data/lib/active_record/fixture_set/table_row.rb +29 -8
  147. data/lib/active_record/fixtures.rb +167 -97
  148. data/lib/active_record/future_result.rb +47 -8
  149. data/lib/active_record/gem_version.rb +3 -3
  150. data/lib/active_record/inheritance.rb +34 -18
  151. data/lib/active_record/insert_all.rb +72 -22
  152. data/lib/active_record/integration.rb +11 -8
  153. data/lib/active_record/internal_metadata.rb +124 -20
  154. data/lib/active_record/locking/optimistic.rb +8 -7
  155. data/lib/active_record/locking/pessimistic.rb +5 -2
  156. data/lib/active_record/log_subscriber.rb +18 -22
  157. data/lib/active_record/marshalling.rb +56 -0
  158. data/lib/active_record/message_pack.rb +124 -0
  159. data/lib/active_record/middleware/database_selector/resolver.rb +4 -0
  160. data/lib/active_record/middleware/database_selector.rb +6 -8
  161. data/lib/active_record/middleware/shard_selector.rb +3 -1
  162. data/lib/active_record/migration/command_recorder.rb +106 -8
  163. data/lib/active_record/migration/compatibility.rb +147 -5
  164. data/lib/active_record/migration/default_strategy.rb +22 -0
  165. data/lib/active_record/migration/execution_strategy.rb +19 -0
  166. data/lib/active_record/migration/pending_migration_connection.rb +21 -0
  167. data/lib/active_record/migration.rb +234 -117
  168. data/lib/active_record/model_schema.rb +88 -103
  169. data/lib/active_record/nested_attributes.rb +35 -9
  170. data/lib/active_record/normalization.rb +163 -0
  171. data/lib/active_record/persistence.rb +168 -339
  172. data/lib/active_record/promise.rb +84 -0
  173. data/lib/active_record/query_cache.rb +19 -25
  174. data/lib/active_record/query_logs.rb +92 -52
  175. data/lib/active_record/query_logs_formatter.rb +41 -0
  176. data/lib/active_record/querying.rb +33 -8
  177. data/lib/active_record/railtie.rb +135 -86
  178. data/lib/active_record/railties/controller_runtime.rb +22 -7
  179. data/lib/active_record/railties/databases.rake +145 -154
  180. data/lib/active_record/railties/job_runtime.rb +23 -0
  181. data/lib/active_record/readonly_attributes.rb +32 -5
  182. data/lib/active_record/reflection.rb +259 -68
  183. data/lib/active_record/relation/batches/batch_enumerator.rb +20 -5
  184. data/lib/active_record/relation/batches.rb +196 -61
  185. data/lib/active_record/relation/calculations.rb +249 -92
  186. data/lib/active_record/relation/delegation.rb +30 -19
  187. data/lib/active_record/relation/finder_methods.rb +93 -18
  188. data/lib/active_record/relation/merger.rb +6 -6
  189. data/lib/active_record/relation/predicate_builder/array_handler.rb +2 -2
  190. data/lib/active_record/relation/predicate_builder/association_query_value.rb +18 -3
  191. data/lib/active_record/relation/predicate_builder/polymorphic_array_value.rb +10 -7
  192. data/lib/active_record/relation/predicate_builder/relation_handler.rb +5 -1
  193. data/lib/active_record/relation/predicate_builder.rb +28 -16
  194. data/lib/active_record/relation/query_attribute.rb +2 -1
  195. data/lib/active_record/relation/query_methods.rb +548 -94
  196. data/lib/active_record/relation/record_fetch_warning.rb +3 -0
  197. data/lib/active_record/relation/spawn_methods.rb +5 -4
  198. data/lib/active_record/relation/where_clause.rb +7 -19
  199. data/lib/active_record/relation.rb +580 -90
  200. data/lib/active_record/result.rb +49 -48
  201. data/lib/active_record/runtime_registry.rb +63 -1
  202. data/lib/active_record/sanitization.rb +70 -25
  203. data/lib/active_record/schema.rb +8 -7
  204. data/lib/active_record/schema_dumper.rb +63 -14
  205. data/lib/active_record/schema_migration.rb +75 -24
  206. data/lib/active_record/scoping/default.rb +15 -5
  207. data/lib/active_record/scoping/named.rb +2 -2
  208. data/lib/active_record/scoping.rb +2 -1
  209. data/lib/active_record/secure_password.rb +60 -0
  210. data/lib/active_record/secure_token.rb +21 -3
  211. data/lib/active_record/signed_id.rb +27 -6
  212. data/lib/active_record/statement_cache.rb +7 -7
  213. data/lib/active_record/store.rb +8 -8
  214. data/lib/active_record/suppressor.rb +3 -1
  215. data/lib/active_record/table_metadata.rb +1 -1
  216. data/lib/active_record/tasks/database_tasks.rb +180 -119
  217. data/lib/active_record/tasks/mysql_database_tasks.rb +15 -6
  218. data/lib/active_record/tasks/postgresql_database_tasks.rb +16 -13
  219. data/lib/active_record/tasks/sqlite_database_tasks.rb +16 -7
  220. data/lib/active_record/test_fixtures.rb +170 -155
  221. data/lib/active_record/testing/query_assertions.rb +121 -0
  222. data/lib/active_record/timestamp.rb +31 -17
  223. data/lib/active_record/token_for.rb +123 -0
  224. data/lib/active_record/touch_later.rb +12 -7
  225. data/lib/active_record/transaction.rb +132 -0
  226. data/lib/active_record/transactions.rb +106 -24
  227. data/lib/active_record/translation.rb +0 -2
  228. data/lib/active_record/type/adapter_specific_registry.rb +1 -8
  229. data/lib/active_record/type/internal/timezone.rb +7 -2
  230. data/lib/active_record/type/serialized.rb +1 -3
  231. data/lib/active_record/type/time.rb +4 -0
  232. data/lib/active_record/type_caster/connection.rb +4 -4
  233. data/lib/active_record/validations/absence.rb +1 -1
  234. data/lib/active_record/validations/associated.rb +9 -3
  235. data/lib/active_record/validations/numericality.rb +5 -4
  236. data/lib/active_record/validations/presence.rb +5 -28
  237. data/lib/active_record/validations/uniqueness.rb +60 -11
  238. data/lib/active_record/validations.rb +12 -5
  239. data/lib/active_record/version.rb +1 -1
  240. data/lib/active_record.rb +247 -33
  241. data/lib/arel/alias_predication.rb +1 -1
  242. data/lib/arel/collectors/bind.rb +2 -0
  243. data/lib/arel/collectors/composite.rb +7 -0
  244. data/lib/arel/collectors/sql_string.rb +1 -1
  245. data/lib/arel/collectors/substitute_binds.rb +1 -1
  246. data/lib/arel/errors.rb +10 -0
  247. data/lib/arel/factory_methods.rb +4 -0
  248. data/lib/arel/nodes/binary.rb +6 -7
  249. data/lib/arel/nodes/bound_sql_literal.rb +65 -0
  250. data/lib/arel/nodes/cte.rb +36 -0
  251. data/lib/arel/nodes/fragments.rb +35 -0
  252. data/lib/arel/nodes/homogeneous_in.rb +1 -9
  253. data/lib/arel/nodes/leading_join.rb +8 -0
  254. data/lib/arel/nodes/{and.rb → nary.rb} +5 -2
  255. data/lib/arel/nodes/node.rb +115 -5
  256. data/lib/arel/nodes/sql_literal.rb +13 -0
  257. data/lib/arel/nodes/table_alias.rb +4 -0
  258. data/lib/arel/nodes.rb +6 -2
  259. data/lib/arel/predications.rb +3 -1
  260. data/lib/arel/select_manager.rb +1 -1
  261. data/lib/arel/table.rb +9 -5
  262. data/lib/arel/tree_manager.rb +8 -3
  263. data/lib/arel/update_manager.rb +2 -1
  264. data/lib/arel/visitors/dot.rb +1 -0
  265. data/lib/arel/visitors/mysql.rb +17 -5
  266. data/lib/arel/visitors/postgresql.rb +1 -12
  267. data/lib/arel/visitors/to_sql.rb +112 -34
  268. data/lib/arel/visitors/visitor.rb +2 -2
  269. data/lib/arel.rb +21 -3
  270. data/lib/rails/generators/active_record/application_record/USAGE +8 -0
  271. data/lib/rails/generators/active_record/migration/templates/create_table_migration.rb.tt +4 -1
  272. data/lib/rails/generators/active_record/migration.rb +3 -1
  273. data/lib/rails/generators/active_record/model/USAGE +113 -0
  274. data/lib/rails/generators/active_record/model/model_generator.rb +15 -6
  275. metadata +56 -14
  276. data/lib/active_record/connection_adapters/legacy_pool_manager.rb +0 -35
  277. data/lib/active_record/null_relation.rb +0 -63
data/CHANGELOG.md CHANGED
@@ -1,2376 +1,902 @@
1
- ## Rails 7.0.8 (September 09, 2023) ##
1
+ ## Rails 7.2.0 (August 09, 2024) ##
2
2
 
3
- * Fix `change_column` not setting `precision: 6` on `datetime` columns when
4
- using 7.0+ Migrations and SQLite.
3
+ * Handle commas in Sqlite3 default function definitions.
5
4
 
6
- *Hartley McGuire*
7
-
8
- * Fix unscope is not working in specific case
9
-
10
- Before:
11
- ```ruby
12
- Post.where(id: 1...3).unscope(where: :id).to_sql # "SELECT `posts`.* FROM `posts` WHERE `posts`.`id` >= 1 AND `posts`.`id` < 3"
13
-
14
- ```
15
-
16
- After:
17
- ```ruby
18
- Post.where(id: 1...3).unscope(where: :id).to_sql # "SELECT `posts`.* FROM `posts`"
19
- ```
20
-
21
- Fixes #48094.
22
-
23
- *Kazuya Hatanaka*
24
-
25
- * Fix associations to a STI model including a `class_name` parameter
26
-
27
- ```ruby
28
- class Product < ApplicationRecord
29
- has_many :requests, as: :requestable, class_name: "ProductRequest", dependent: :destroy
30
- end
31
-
32
- # STI tables
33
- class Request < ApplicationRecord
34
- belongs_to :requestable, polymorphic: true
35
-
36
- validate :request_type, presence: true
37
- end
38
-
39
- class ProductRequest < Request
40
- belongs_to :user
41
- end
42
- ```
43
-
44
- Accessing such association would lead to:
45
-
46
- ```
47
- table_metadata.rb:22:in `has_column?': undefined method `key?' for nil:NilClass (NoMethodError)
48
- ```
49
-
50
- *Romain Filinto*
51
-
52
- * Fix `change_table` setting datetime precision for 6.1 Migrations
53
-
54
- *Hartley McGuire*
55
-
56
- * Fix change_column setting datetime precision for 6.1 Migrations
57
-
58
- *Hartley McGuire*
59
-
60
- ## Rails 7.0.7.2 (August 22, 2023) ##
61
-
62
- * No changes.
63
-
64
-
65
- ## Rails 7.0.7.1 (August 22, 2023) ##
66
-
67
- * No changes.
68
-
69
-
70
- ## Rails 7.0.7 (August 09, 2023) ##
71
-
72
- * Restores functionality to the missing method when using enums and fixes.
73
-
74
- *paulreece*
75
-
76
- * Fix `StatementCache::Substitute` with serialized type.
77
-
78
- *ywenc*
79
-
80
- * Fix `:db_runtime` on notification payload when application have multiple databases.
81
-
82
- *Eileen M. Uchitelle*
83
-
84
- * Correctly dump check constraints for MySQL 8.0.16+.
85
-
86
- *Steve Hill*
87
-
88
- * Fix `ActiveRecord::QueryMethods#in_order_of` to include `nil`s, to match the
89
- behavior of `Enumerable#in_order_of`.
90
-
91
- For example, `Post.in_order_of(:title, [nil, "foo"])` will now include posts
92
- with `nil` titles, the same as `Post.all.to_a.in_order_of(:title, [nil, "foo"])`.
93
-
94
- *fatkodima*
95
-
96
- * Revert "Fix autosave associations with validations added on `:base` of the associated objects."
97
-
98
- This change intended to remove the :base attribute from the message,
99
- but broke many assumptions which key these errors were stored.
100
-
101
- *zzak*
102
-
103
- * Fix `#previously_new_record?` to return true for destroyed records.
104
-
105
- Before, if a record was created and then destroyed, `#previously_new_record?` would return true.
106
- Now, any UPDATE or DELETE to a record is considered a change, and will result in `#previously_new_record?`
107
- returning false.
108
-
109
- *Adrianna Chang*
110
-
111
- * Revert breaking changes to `has_one` relationship deleting the old record before the new one is validated.
112
-
113
- *zzak*
114
-
115
- * Fix support for Active Record instances being uses in queries.
116
-
117
- As of `7.0.5`, query arguments were deep duped to avoid mutations impacting
118
- the query cache, but this had the adverse effect to clearing the primary key when
119
- the query argument contained an `ActiveRecord::Base` instance.
120
-
121
- This broke the `noticed` gem.
122
-
123
- *Jean Boussier*
124
-
125
-
126
- ## Rails 7.0.6 (June 29, 2023) ##
127
-
128
- * Fix autosave associations with validations added on `:base` of the associated objects.
129
-
130
- *fatkodima*
131
-
132
- * Fix result with anonymous PostgreSQL columns of different type from json.
133
-
134
- *Oleksandr Avoiants*
135
-
136
- * Preserve timestamp when setting an `ActiveSupport::TimeWithZone` value to `timestamptz` attribute.
137
-
138
- *fatkodima*
139
-
140
- * Fix assignment into an `has_one` relationship deleting the old record before the new one is validated.
141
-
142
- *Jean Boussier*
143
-
144
- * Fix where on association with has_one/has_many polymorphic relations.
145
-
146
- Before:
147
- ```ruby
148
- Treasure.where(price_estimates: PriceEstimate.all)
149
- #=> SELECT (...) WHERE "treasures"."id" IN (SELECT "price_estimates"."estimate_of_id" FROM "price_estimates")
150
- ```
151
-
152
- Later:
153
- ```ruby
154
- Treasure.where(price_estimates: PriceEstimate.all)
155
- #=> SELECT (...) WHERE "treasures"."id" IN (SELECT "price_estimates"."estimate_of_id" FROM "price_estimates" WHERE "price_estimates"."estimate_of_type" = 'Treasure')
156
- ```
157
-
158
- *Lázaro Nixon*
159
-
160
- * Fix decrementing counter caches on optimistically locked record deletion
161
-
162
- *fatkodima*
163
-
164
- * Ensure binary-destined values have binary encoding during type cast.
165
-
166
- *Matthew Draper*
167
-
168
- * Preserve existing column default functions when altering table in SQLite.
169
-
170
- *fatkodima*
171
-
172
- * Remove table alias added when using `where.missing` or `where.associated`.
173
-
174
- *fatkodima*
175
-
176
- * Fix `Enumerable#in_order_of` to only flatten first level to preserve nesting.
177
-
178
- *Miha Rekar*
179
-
180
-
181
- ## Rails 7.0.5.1 (June 26, 2023) ##
182
-
183
- * No changes.
184
-
185
- ## Rails 7.0.5 (May 24, 2023) ##
186
-
187
- * Type cast `#attribute_changed?` `:from` and `:to` options.
188
-
189
- *Andrew Novoselac*
190
-
191
- * Fix `index_exists?` when column is an array.
192
-
193
- *Eileen M. Uchitelle*
194
-
195
- * Handle `Date` objects for PostgreSQL `timestamptz` columns.
196
-
197
- *Alex Ghiculescu*
198
-
199
- * Fix collation for changing column to non-string.
200
-
201
- *Hartley McGuire*
202
-
203
- * Map through subtype in `PostgreSQL::OID::Array`.
204
-
205
- *Jonathan Hefner*
206
-
207
- * Store correct environment in `internal_metadata` when run rails `db:prepare`.
208
-
209
- *fatkodima*
210
-
211
- * Make sure `ActiveRecord::Relation#sum` works with objects that implement `#coerce` without deprecation.
212
-
213
- *Alex Ghiculescu*
214
-
215
- * Fix retrieving foreign keys referencing tables named like keywords in PostgreSQL and MySQL.
216
-
217
- *fatkodima*
218
-
219
- * Support UUIDs in Disable Joins.
220
-
221
- *Samuel Cochran*
222
-
223
- * Fix Active Record's explain for queries starting with comments.
224
-
225
- *fatkodima*
226
-
227
- * Fix incorrectly preloading through association records when middle association has been loaded.
228
-
229
- *Joshua Young*
230
-
231
- * Fix where.missing and where.associated for parent/child associations.
232
-
233
- *fatkodima*
234
-
235
- * Fix Enumerable#in_order_of to preserve duplicates.
236
-
237
- *fatkodima*
238
-
239
- * Fix autoincrement on primary key for mysql.
240
-
241
- *Eileen M. Uchitelle*
242
-
243
- * Restore ability to redefine column in `create_table` for Rails 5.2 migrations.
244
-
245
- *fatkodima*
246
-
247
- * Fix schema cache dumping of virtual columns.
248
-
249
- *fatkodima*
250
-
251
- * Fix Active Record grouped calculations on joined tables on column present in both tables.
252
-
253
- *fatkodima*
254
-
255
- * Fix mutation detection for serialized attributes backed by binary columns.
256
-
257
- *Jean Boussier*
258
-
259
- * Fix a bug where using groups and counts with long table names would return incorrect results.
260
-
261
- *Shota Toguchi*, *Yusaku Ono*
262
-
263
- * Fix erroneous nil default precision on virtual datetime columns.
264
-
265
- Prior to this change, virtual datetime columns did not have the same
266
- default precision as regular datetime columns, resulting in the following
267
- being erroneously equivalent:
268
-
269
- t.virtual :name, type: datetime, as: "expression"
270
- t.virtual :name, type: datetime, precision: nil, as: "expression"
271
-
272
- This change fixes the default precision lookup, so virtual and regular
273
- datetime column default precisions match.
274
-
275
- *Sam Bostock*
276
-
277
- * Fix a case where the query cache can return wrong values. See #46044
278
-
279
- *Aaron Patterson*
280
-
281
-
282
- ## Rails 7.0.4.3 (March 13, 2023) ##
283
-
284
- * No changes.
285
-
286
-
287
- ## Rails 7.0.4.2 (January 24, 2023) ##
288
-
289
- * No changes.
290
-
291
-
292
- ## Rails 7.0.4.1 (January 17, 2023) ##
293
-
294
- * Make sanitize_as_sql_comment more strict
295
-
296
- Though this method was likely never meant to take user input, it was
297
- attempting sanitization. That sanitization could be bypassed with
298
- carefully crafted input.
299
-
300
- This commit makes the sanitization more robust by replacing any
301
- occurrences of "/*" or "*/" with "/ *" or "* /". It also performs a
302
- first pass to remove one surrounding comment to avoid compatibility
303
- issues for users relying on the existing removal.
304
-
305
- This also clarifies in the documentation of annotate that it should not
306
- be provided user input.
307
-
308
- [CVE-2023-22794]
309
-
310
- * Added integer width check to PostgreSQL::Quoting
311
-
312
- Given a value outside the range for a 64bit signed integer type
313
- PostgreSQL will treat the column type as numeric. Comparing
314
- integer values against numeric values can result in a slow
315
- sequential scan.
316
-
317
- This behavior is configurable via
318
- ActiveRecord::Base.raise_int_wider_than_64bit which defaults to true.
319
-
320
- [CVE-2022-44566]
321
-
322
-
323
- ## Rails 7.0.4 (September 09, 2022) ##
324
-
325
- * Symbol is allowed by default for YAML columns
326
-
327
- *Étienne Barrié*
328
-
329
- * Fix `ActiveRecord::Store` to serialize as a regular Hash
330
-
331
- Previously it would serialize as an `ActiveSupport::HashWithIndifferentAccess`
332
- which is wasteful and cause problem with YAML safe_load.
333
-
334
- *Jean Boussier*
335
-
336
- * Add `timestamptz` as a time zone aware type for PostgreSQL
337
-
338
- This is required for correctly parsing `timestamp with time zone` values in your database.
339
-
340
- If you don't want this, you can opt out by adding this initializer:
341
-
342
- ```ruby
343
- ActiveRecord::Base.time_zone_aware_types -= [:timestamptz]
344
- ```
345
-
346
- *Alex Ghiculescu*
347
-
348
- * Fix supporting timezone awareness for `tsrange` and `tstzrange` array columns.
349
-
350
- ```ruby
351
- # In database migrations
352
- add_column :shops, :open_hours, :tsrange, array: true
353
- # In app config
354
- ActiveRecord::Base.time_zone_aware_types += [:tsrange]
355
- # In the code times are properly converted to app time zone
356
- Shop.create!(open_hours: [Time.current..8.hour.from_now])
357
- ```
358
-
359
- *Wojciech Wnętrzak*
360
-
361
- * Resolve issue where a relation cache_version could be left stale.
362
-
363
- Previously, when `reset` was called on a relation object it did not reset the cache_versions
364
- ivar. This led to a confusing situation where despite having the correct data the relation
365
- still reported a stale cache_version.
366
-
367
- Usage:
368
-
369
- ```ruby
370
- developers = Developer.all
371
- developers.cache_version
372
-
373
- Developer.update_all(updated_at: Time.now.utc + 1.second)
374
-
375
- developers.cache_version # Stale cache_version
376
- developers.reset
377
- developers.cache_version # Returns the current correct cache_version
378
- ```
379
-
380
- Fixes #45341.
381
-
382
- *Austen Madden*
383
-
384
- * Fix `load_async` when called on an association proxy.
385
-
386
- Calling `load_async` directly an association would schedule
387
- a query but never use it.
388
-
389
- ```ruby
390
- comments = post.comments.load_async # schedule a query
391
- comments.to_a # perform an entirely new sync query
392
- ```
393
-
394
- Now it does use the async query, however note that it doesn't
395
- cause the association to be loaded.
396
-
397
- *Jean Boussier*
398
-
399
- * Fix eager loading for models without primary keys.
400
-
401
- *Anmol Chopra*, *Matt Lawrence*, and *Jonathan Hefner*
402
-
403
- * `rails db:schema:{dump,load}` now checks `ENV["SCHEMA_FORMAT"]` before config
404
-
405
- Since `rails db:structure:{dump,load}` was deprecated there wasn't a simple
406
- way to dump a schema to both SQL and Ruby formats. You can now do this with
407
- an environment variable. For example:
408
-
409
- ```
410
- SCHEMA_FORMAT=sql rake db:schema:dump
411
- ```
412
-
413
- *Alex Ghiculescu*
414
-
415
- * Fix Hstore deserialize regression.
416
-
417
- *edsharp*
418
-
419
-
420
- ## Rails 7.0.3.1 (July 12, 2022) ##
421
-
422
- * Change ActiveRecord::Coders::YAMLColumn default to safe_load
423
-
424
- This adds two new configuration options The configuration options are as
425
- follows:
426
-
427
- * `config.active_record.use_yaml_unsafe_load`
428
-
429
- When set to true, this configuration option tells Rails to use the old
430
- "unsafe" YAML loading strategy, maintaining the existing behavior but leaving
431
- the possible escalation vulnerability in place. Setting this option to true
432
- is *not* recommended, but can aid in upgrading.
433
-
434
- * `config.active_record.yaml_column_permitted_classes`
435
-
436
- The "safe YAML" loading method does not allow all classes to be deserialized
437
- by default. This option allows you to specify classes deemed "safe" in your
438
- application. For example, if your application uses Symbol and Time in
439
- serialized data, you can add Symbol and Time to the allowed list as follows:
440
-
441
- ```
442
- config.active_record.yaml_column_permitted_classes = [Symbol, Date, Time]
443
- ```
444
-
445
- [CVE-2022-32224]
446
-
447
-
448
- ## Rails 7.0.3 (May 09, 2022) ##
449
-
450
- * Some internal housekeeping on reloads could break custom `respond_to?`
451
- methods in class objects that referenced reloadable constants. See
452
- [#44125](https://github.com/rails/rails/issues/44125) for details.
453
-
454
- *Xavier Noria*
455
-
456
- * Fixed MariaDB default function support.
457
-
458
- Defaults would be written wrong in "db/schema.rb" and not work correctly
459
- if using `db:schema:load`. Further more the function name would be
460
- added as string content when saving new records.
461
-
462
- *kaspernj*
463
-
464
- * Fix `remove_foreign_key` with `:if_exists` option when foreign key actually exists.
465
-
466
- *fatkodima*
467
-
468
- * Remove `--no-comments` flag in structure dumps for PostgreSQL
469
-
470
- This broke some apps that used custom schema comments. If you don't want
471
- comments in your structure dump, you can use:
472
-
473
- ```ruby
474
- ActiveRecord::Tasks::DatabaseTasks.structure_dump_flags = ['--no-comments']
475
- ```
476
-
477
- *Alex Ghiculescu*
478
-
479
- * Use the model name as a prefix when filtering encrypted attributes from logs.
480
-
481
- For example, when encrypting `Person#name` it will add `person.name` as a filter
482
- parameter, instead of just `name`. This prevents unintended filtering of parameters
483
- with a matching name in other models.
484
-
485
- *Jorge Manrubia*
486
-
487
- * Fix quoting of `ActiveSupport::Duration` and `Rational` numbers in the MySQL adapter.
488
-
489
- *Kevin McPhillips*
490
-
491
- * Fix `change_column_comment` to preserve column's AUTO_INCREMENT in the MySQL adapter
492
-
493
- *fatkodima*
494
-
495
- ## Rails 7.0.2.4 (April 26, 2022) ##
496
-
497
- * No changes.
498
-
499
-
500
- ## Rails 7.0.2.3 (March 08, 2022) ##
501
-
502
- * No changes.
503
-
504
-
505
- ## Rails 7.0.2.2 (February 11, 2022) ##
506
-
507
- * No changes.
508
-
509
-
510
- ## Rails 7.0.2.1 (February 11, 2022) ##
511
-
512
- * No changes.
513
-
514
-
515
- ## Rails 7.0.2 (February 08, 2022) ##
516
-
517
- * Fix `PG.connect` keyword arguments deprecation warning on ruby 2.7.
518
-
519
- *Nikita Vasilevsky*
520
-
521
- * Fix the ability to exclude encryption params from being autofiltered.
522
-
523
- *Mark Gangl*
524
-
525
- * Dump the precision for datetime columns following the new defaults.
526
-
527
- *Rafael Mendonça França*
528
-
529
- * Make sure encrypted attributes are not being filtered twice.
530
-
531
- *Nikita Vasilevsky*
532
-
533
- * Dump the database schema containing the current Rails version.
534
-
535
- Since https://github.com/rails/rails/pull/42297, Rails now generate datetime columns
536
- with a default precision of 6. This means that users upgrading to Rails 7.0 from 6.1,
537
- when loading the database schema, would get the new precision value, which would not match
538
- the production schema.
539
-
540
- To avoid this the schema dumper will generate the new format which will include the Rails
541
- version and will look like this:
542
-
543
- ```
544
- ActiveRecord::Schema[7.0].define
545
- ```
546
-
547
- When upgrading from Rails 6.1 to Rails 7.0, you can run the `rails app:update` task that will
548
- set the current schema version to 6.1.
549
-
550
- *Rafael Mendonça França*
551
-
552
- * Fix parsing expression for PostgreSQL generated column.
553
-
554
- *fatkodima*
555
-
556
- * Fix `Mysql2::Error: Commands out of sync; you can't run this command now`
557
- when bulk-inserting fixtures that exceed `max_allowed_packet` configuration.
558
-
559
- *Nikita Vasilevsky*
560
-
561
- * Fix error when saving an association with a relation named `record`.
562
-
563
- *Dorian Marié*
564
-
565
- * Fix `MySQL::SchemaDumper` behavior about datetime precision value.
566
-
567
- *y0t4*
568
-
569
- * Improve associated with no reflection error.
570
-
571
- *Nikolai*
572
-
573
- * Fix PG.connect keyword arguments deprecation warning on ruby 2.7.
574
-
575
- Fixes #44307.
576
-
577
- *Nikita Vasilevsky*
578
-
579
- * Fix passing options to `check_constraint` from `change_table`.
580
-
581
- *Frederick Cheung*
582
-
583
-
584
- ## Rails 7.0.1 (January 06, 2022) ##
585
-
586
-
587
- * Change `QueryMethods#in_order_of` to drop records not listed in values.
588
-
589
- `in_order_of` now filters down to the values provided, to match the behavior of the `Enumerable` version.
590
-
591
- *Kevin Newton*
592
-
593
- * Allow named expression indexes to be revertible.
594
-
595
- Previously, the following code would raise an error in a reversible migration executed while rolling back, due to the index name not being used in the index removal.
596
-
597
- ```ruby
598
- add_index(:settings, "(data->'property')", using: :gin, name: :index_settings_data_property)
599
- ```
600
-
601
- Fixes #43331.
602
-
603
- *Oliver Günther*
604
-
605
- * Better error messages when association name is invalid in the argument of `ActiveRecord::QueryMethods::WhereChain#missing`.
606
-
607
- *ykpythemind*
608
-
609
- * Fix ordered migrations for single db in multi db environment.
610
-
611
- *Himanshu*
612
-
613
- * Extract `on update CURRENT_TIMESTAMP` for mysql2 adapter.
614
-
615
- *Kazuhiro Masuda*
616
-
617
- * Fix incorrect argument in PostgreSQL structure dump tasks.
618
-
619
- Updating the `--no-comment` argument added in Rails 7 to the correct `--no-comments` argument.
620
-
621
- *Alex Dent*
622
-
623
- * Fix schema dumping column default SQL values for sqlite3.
624
-
625
- *fatkodima*
626
-
627
- * Correctly parse complex check constraint expressions for PostgreSQL.
628
-
629
- *fatkodima*
630
-
631
- * Fix `timestamptz` attributes on PostgreSQL handle blank inputs.
632
-
633
- *Alex Ghiculescu*
634
-
635
- * Fix migration compatibility to create SQLite references/belongs_to column as integer when migration version is 6.0.
636
-
637
- Reference/belongs_to in migrations with version 6.0 were creating columns as
638
- bigint instead of integer for the SQLite Adapter.
639
-
640
- *Marcelo Lauxen*
641
-
642
- * Fix joining through a polymorphic association.
643
-
644
- *Alexandre Ruban*
645
-
646
- * Fix `QueryMethods#in_order_of` to handle empty order list.
647
-
648
- ```ruby
649
- Post.in_order_of(:id, []).to_a
650
- ```
651
-
652
- Also more explicitly set the column as secondary order, so that any other
653
- value is still ordered.
654
-
655
- *Jean Boussier*
656
-
657
- * Fix `rails dbconsole` for 3-tier config.
658
-
659
- *Eileen M. Uchitelle*
660
-
661
- * Fix quoting of column aliases generated by calculation methods.
662
-
663
- Since the alias is derived from the table name, we can't assume the result
664
- is a valid identifier.
665
-
666
- ```ruby
667
- class Test < ActiveRecord::Base
668
- self.table_name = '1abc'
669
- end
670
- Test.group(:id).count
671
- # syntax error at or near "1" (ActiveRecord::StatementInvalid)
672
- # LINE 1: SELECT COUNT(*) AS count_all, "1abc"."id" AS 1abc_id FROM "1...
673
- ```
674
-
675
- *Jean Boussier*
676
-
677
-
678
- ## Rails 7.0.0 (December 15, 2021) ##
679
-
680
- * Better handle SQL queries with invalid encoding.
681
-
682
- ```ruby
683
- Post.create(name: "broken \xC8 UTF-8")
684
- ```
685
-
686
- Would cause all adapters to fail in a non controlled way in the code
687
- responsible to detect write queries.
688
-
689
- The query is now properly passed to the database connection, which might or might
690
- not be able to handle it, but will either succeed or failed in a more correct way.
691
-
692
- *Jean Boussier*
693
-
694
- * Move database and shard selection config options to a generator.
695
-
696
- Rather than generating the config options in `production.rb` when applications are created, applications can now run a generator to create an initializer and uncomment / update options as needed. All multi-db configuration can be implemented in this initializer.
697
-
698
- *Eileen M. Uchitelle*
699
-
700
-
701
- ## Rails 7.0.0.rc3 (December 14, 2021) ##
702
-
703
- * No changes.
704
-
705
-
706
- ## Rails 7.0.0.rc2 (December 14, 2021) ##
707
-
708
- * No changes.
709
-
710
-
711
- ## Rails 7.0.0.rc1 (December 06, 2021) ##
712
-
713
- * Remove deprecated `ActiveRecord::DatabaseConfigurations::DatabaseConfig#spec_name`.
714
-
715
- *Rafael Mendonça França*
716
-
717
- * Remove deprecated `ActiveRecord::Connection#in_clause_length`.
718
-
719
- *Rafael Mendonça França*
720
-
721
- * Remove deprecated `ActiveRecord::Connection#allowed_index_name_length`.
722
-
723
- *Rafael Mendonça França*
724
-
725
- * Remove deprecated `ActiveRecord::Base#remove_connection`.
726
-
727
- *Rafael Mendonça França*
728
-
729
- * Load STI Models in fixtures
730
-
731
- Data from Fixtures now loads based on the specific class for models with
732
- Single Table Inheritance. This affects enums defined in subclasses, previously
733
- the value of these fields was not parsed and remained `nil`
734
-
735
- *Andres Howard*
736
-
737
- * `#authenticate` returns false when the password is blank instead of raising an error.
738
-
739
- *Muhammad Muhammad Ibrahim*
740
-
741
- * Fix `ActiveRecord::QueryMethods#in_order_of` behavior for integer enums.
742
-
743
- `ActiveRecord::QueryMethods#in_order_of` didn't work as expected for enums stored as integers in the database when passing an array of strings or symbols as the order argument. This unexpected behavior occurred because the string or symbol values were not casted to match the integers in the database.
744
-
745
- The following example now works as expected:
746
-
747
- ```ruby
748
- class Book < ApplicationRecord
749
- enum status: [:proposed, :written, :published]
750
- end
751
-
752
- Book.in_order_of(:status, %w[written published proposed])
753
- ```
754
-
755
- *Alexandre Ruban*
756
-
757
- * Ignore persisted in-memory records when merging target lists.
758
-
759
- *Kevin Sjöberg*
760
-
761
- * Add a new option `:update_only` to `upsert_all` to configure the list of columns to update in case of conflict.
762
-
763
- Before, you could only customize the update SQL sentence via `:on_duplicate`. There is now a new option `:update_only` that lets you provide a list of columns to update in case of conflict:
764
-
765
- ```ruby
766
- Commodity.upsert_all(
767
- [
768
- { id: 2, name: "Copper", price: 4.84 },
769
- { id: 4, name: "Gold", price: 1380.87 },
770
- { id: 6, name: "Aluminium", price: 0.35 }
771
- ],
772
- update_only: [:price] # Only prices will be updated
773
- )
774
- ```
775
-
776
- *Jorge Manrubia*
777
-
778
- * Remove deprecated `ActiveRecord::Result#map!` and `ActiveRecord::Result#collect!`.
779
-
780
- *Rafael Mendonça França*
781
-
782
- * Remove deprecated `ActiveRecord::Base.configurations.to_h`.
783
-
784
- *Rafael Mendonça França*
785
-
786
- * Remove deprecated `ActiveRecord::Base.configurations.default_hash`.
787
-
788
- *Rafael Mendonça França*
789
-
790
- * Remove deprecated `ActiveRecord::Base.arel_attribute`.
791
-
792
- *Rafael Mendonça França*
793
-
794
- * Remove deprecated `ActiveRecord::Base.connection_config`.
795
-
796
- *Rafael Mendonça França*
797
-
798
- * Filter attributes in SQL logs
799
-
800
- Previously, SQL queries in logs containing `ActiveRecord::Base.filter_attributes` were not filtered.
801
-
802
- Now, the filter attributes will be masked `[FILTERED]` in the logs when `prepared_statement` is enabled.
803
-
804
- ```
805
- # Before:
806
- Foo Load (0.2ms) SELECT "foos".* FROM "foos" WHERE "foos"."passw" = ? LIMIT ? [["passw", "hello"], ["LIMIT", 1]]
807
-
808
- # After:
809
- Foo Load (0.5ms) SELECT "foos".* FROM "foos" WHERE "foos"."passw" = ? LIMIT ? [["passw", "[FILTERED]"], ["LIMIT", 1]]
810
- ```
811
-
812
- *Aishwarya Subramanian*
813
-
814
- * Remove deprecated `Tasks::DatabaseTasks.spec`.
815
-
816
- *Rafael Mendonça França*
817
-
818
- * Remove deprecated `Tasks::DatabaseTasks.current_config`.
819
-
820
- *Rafael Mendonça França*
821
-
822
- * Deprecate `Tasks::DatabaseTasks.schema_file_type`.
823
-
824
- *Rafael Mendonça França*
825
-
826
- * Remove deprecated `Tasks::DatabaseTasks.dump_filename`.
827
-
828
- *Rafael Mendonça França*
829
-
830
- * Remove deprecated `Tasks::DatabaseTasks.schema_file`.
831
-
832
- *Rafael Mendonça França*
833
-
834
- * Remove deprecated `environment` and `name` arguments from `Tasks::DatabaseTasks.schema_up_to_date?`.
835
-
836
- *Rafael Mendonça França*
837
-
838
- * Merging conditions on the same column no longer maintain both conditions,
839
- and will be consistently replaced by the latter condition.
840
-
841
- ```ruby
842
- # Rails 6.1 (IN clause is replaced by merger side equality condition)
843
- Author.where(id: [david.id, mary.id]).merge(Author.where(id: bob)) # => [bob]
844
- # Rails 6.1 (both conflict conditions exists, deprecated)
845
- Author.where(id: david.id..mary.id).merge(Author.where(id: bob)) # => []
846
- # Rails 6.1 with rewhere to migrate to Rails 7.0's behavior
847
- Author.where(id: david.id..mary.id).merge(Author.where(id: bob), rewhere: true) # => [bob]
848
- # Rails 7.0 (same behavior with IN clause, mergee side condition is consistently replaced)
849
- Author.where(id: [david.id, mary.id]).merge(Author.where(id: bob)) # => [bob]
850
- Author.where(id: david.id..mary.id).merge(Author.where(id: bob)) # => [bob]
851
-
852
- *Rafael Mendonça França*
853
-
854
- * Remove deprecated support to `Model.reorder(nil).first` to search using non-deterministic order.
855
-
856
- *Rafael Mendonça França*
857
-
858
- * Remove deprecated rake tasks:
859
-
860
- * `db:schema:load_if_ruby`
861
- * `db:structure:dump`
862
- * `db:structure:load`
863
- * `db:structure:load_if_sql`
864
- * `db:structure:dump:#{name}`
865
- * `db:structure:load:#{name}`
866
- * `db:test:load_structure`
867
- * `db:test:load_structure:#{name}`
868
-
869
- *Rafael Mendonça França*
870
-
871
- * Remove deprecated `DatabaseConfig#config` method.
872
-
873
- *Rafael Mendonça França*
874
-
875
- * Rollback transactions when the block returns earlier than expected.
876
-
877
- Before this change, when a transaction block returned early, the transaction would be committed.
878
-
879
- The problem is that timeouts triggered inside the transaction block was also making the incomplete transaction
880
- to be committed, so in order to avoid this mistake, the transaction block is rolled back.
881
-
882
- *Rafael Mendonça França*
883
-
884
- * Add middleware for automatic shard swapping.
885
-
886
- Provides a basic middleware to perform automatic shard swapping. Applications will provide a resolver which will determine for an individual request which shard should be used. Example:
887
-
888
- ```ruby
889
- config.active_record.shard_resolver = ->(request) {
890
- subdomain = request.subdomain
891
- tenant = Tenant.find_by_subdomain!(subdomain)
892
- tenant.shard
893
- }
894
- ```
895
-
896
- See guides for more details.
897
-
898
- *Eileen M. Uchitelle*, *John Crepezzi*
899
-
900
- * Remove deprecated support to pass a column to `type_cast`.
901
-
902
- *Rafael Mendonça França*
903
-
904
- * Remove deprecated support to type cast to database values `ActiveRecord::Base` objects.
905
-
906
- *Rafael Mendonça França*
907
-
908
- * Remove deprecated support to quote `ActiveRecord::Base` objects.
909
-
910
- *Rafael Mendonça França*
911
-
912
- * Remove deprecacated support to resolve connection using `"primary"` as connection specification name.
913
-
914
- *Rafael Mendonça França*
915
-
916
- * Remove deprecation warning when using `:interval` column is used in PostgreSQL database.
917
-
918
- Now, interval columns will return `ActiveSupport::Duration` objects instead of strings.
919
-
920
- To keep the old behavior, you can add this line to your model:
921
-
922
- ```ruby
923
- attribute :column, :string
924
- ```
925
-
926
- *Rafael Mendonça França*
927
-
928
- * Remove deprecated support to YAML load `ActiveRecord::Base` instance in the Rails 4.2 and 4.1 formats.
929
-
930
- *Rafael Mendonça França*
931
-
932
- * Remove deprecated option `:spec_name` in the `configs_for` method.
933
-
934
- *Rafael Mendonça França*
935
-
936
- * Remove deprecated `ActiveRecord::Base.allow_unsafe_raw_sql`.
937
-
938
- *Rafael Mendonça França*
939
-
940
- * Fix regression bug that caused ignoring additional conditions for preloading has_many-through relations.
941
-
942
- Fixes #43132
943
-
944
- *Alexander Pauly*
945
-
946
- * Fix `has_many` inversing recursion on models with recursive associations.
947
-
948
- *Gannon McGibbon*
949
-
950
- * Add `accepts_nested_attributes_for` support for `delegated_type`
951
-
952
- ```ruby
953
- class Entry < ApplicationRecord
954
- delegated_type :entryable, types: %w[ Message Comment ]
955
- accepts_nested_attributes_for :entryable
956
- end
957
-
958
- entry = Entry.create(entryable_type: 'Message', entryable_attributes: { content: 'Hello world' })
959
- # => #<Entry:0x00>
960
- # id: 1
961
- # entryable_id: 1,
962
- # entryable_type: 'Message'
963
- # ...>
964
-
965
- entry.entryable
966
- # => #<Message:0x01>
967
- # id: 1
968
- # content: 'Hello world'
969
- # ...>
970
- ```
971
-
972
- Previously it would raise an error:
973
-
974
- ```ruby
975
- Entry.create(entryable_type: 'Message', entryable_attributes: { content: 'Hello world' })
976
- # ArgumentError: Cannot build association `entryable'. Are you trying to build a polymorphic one-to-one association?
977
- ```
978
-
979
- *Sjors Baltus*
980
-
981
- * Use subquery for DELETE with GROUP_BY and HAVING clauses.
982
-
983
- Prior to this change, deletes with GROUP_BY and HAVING were returning an error.
984
-
985
- After this change, GROUP_BY and HAVING are valid clauses in DELETE queries, generating the following query:
986
-
987
- ```sql
988
- DELETE FROM "posts" WHERE "posts"."id" IN (
989
- SELECT "posts"."id" FROM "posts" INNER JOIN "comments" ON "comments"."post_id" = "posts"."id" GROUP BY "posts"."id" HAVING (count(comments.id) >= 2))
990
- ) [["flagged", "t"]]
991
- ```
992
-
993
- *Ignacio Chiazzo Cardarello*
994
-
995
- * Use subquery for UPDATE with GROUP_BY and HAVING clauses.
996
-
997
- Prior to this change, updates with GROUP_BY and HAVING were being ignored, generating a SQL like this:
998
-
999
- ```sql
1000
- UPDATE "posts" SET "flagged" = ? WHERE "posts"."id" IN (
1001
- SELECT "posts"."id" FROM "posts" INNER JOIN "comments" ON "comments"."post_id" = "posts"."id"
1002
- ) [["flagged", "t"]]
1003
- ```
1004
-
1005
- After this change, GROUP_BY and HAVING clauses are used as a subquery in updates, like this:
1006
-
1007
- ```sql
1008
- UPDATE "posts" SET "flagged" = ? WHERE "posts"."id" IN (
1009
- SELECT "posts"."id" FROM "posts" INNER JOIN "comments" ON "comments"."post_id" = "posts"."id"
1010
- GROUP BY posts.id HAVING (count(comments.id) >= 2)
1011
- ) [["flagged", "t"]]
1012
- ```
1013
-
1014
- *Ignacio Chiazzo Cardarello*
1015
-
1016
- * Add support for setting the filename of the schema or structure dump in the database config.
1017
-
1018
- Applications may now set their the filename or path of the schema / structure dump file in their database configuration.
1019
-
1020
- ```yaml
1021
- production:
1022
- primary:
1023
- database: my_db
1024
- schema_dump: my_schema_dump_filename.rb
1025
- animals:
1026
- database: animals_db
1027
- schema_dump: false
1028
- ```
1029
-
1030
- The filename set in `schema_dump` will be used by the application. If set to `false` the schema will not be dumped. The database tasks are responsible for adding the database directory to the filename. If a full path is provided, the Rails tasks will use that instead of `ActiveRecord::DatabaseTasks.db_dir`.
1031
-
1032
- *Eileen M. Uchitelle*, *Ryan Kerr*
1033
-
1034
- * Add `ActiveRecord::Base.prohibit_shard_swapping` to prevent attempts to change the shard within a block.
1035
-
1036
- *John Crepezzi*, *Eileen M. Uchitelle*
1037
-
1038
- * Filter unchanged attributes with default function from insert query when `partial_inserts` is disabled.
1039
-
1040
- *Akshay Birajdar*, *Jacopo Beschi*
1041
-
1042
- * Add support for FILTER clause (SQL:2003) to Arel.
1043
-
1044
- Currently supported by PostgreSQL 9.4+ and SQLite 3.30+.
1045
-
1046
- *Andrey Novikov*
1047
-
1048
- * Automatically set timestamps on record creation during bulk insert/upsert
1049
-
1050
- Prior to this change, only updates during an upsert operation (e.g. `upsert_all`) would touch timestamps (`updated_{at,on}`). Now, record creations also touch timestamp columns (`{created,updated}_{at,on}`).
1051
-
1052
- This behaviour is controlled by the `<model>.record_timestamps` config, matching the behaviour of `create`, `update`, etc. It can also be overridden by using the `record_timestamps:` keyword argument.
1053
-
1054
- Note that this means `upsert_all` on models with `record_timestamps = false` will no longer touch `updated_{at,on}` automatically.
1055
-
1056
- *Sam Bostock*
1057
-
1058
- * Don't require `role` when passing `shard` to `connected_to`.
1059
-
1060
- `connected_to` can now be called with a `shard` only. Note that `role` is still inherited if `connected_to` calls are nested.
1061
-
1062
- *Eileen M. Uchitelle*
1063
-
1064
- * Add option to lazily load the schema cache on the connection.
1065
-
1066
- Previously, the only way to load the schema cache in Active Record was through the Railtie on boot. This option provides the ability to load the schema cache on the connection after it's been established. Loading the cache lazily on the connection can be beneficial for Rails applications that use multiple databases because it will load the cache at the time the connection is established. Currently Railties doesn't have access to the connections before boot.
1067
-
1068
- To use the cache, set `config.active_record.lazily_load_schema_cache = true` in your application configuration. In addition a `schema_cache_path` should be set in your database configuration if you don't want to use the default "db/schema_cache.yml" path.
1069
-
1070
- *Eileen M. Uchitelle*
1071
-
1072
- * Allow automatic `inverse_of` detection for associations with scopes.
1073
-
1074
- Automatic `inverse_of` detection now works for associations with scopes. For
1075
- example, the `comments` association here now automatically detects
1076
- `inverse_of: :post`, so we don't need to pass that option:
1077
-
1078
- ```ruby
1079
- class Post < ActiveRecord::Base
1080
- has_many :comments, -> { visible }
1081
- end
1082
-
1083
- class Comment < ActiveRecord::Base
1084
- belongs_to :post
1085
- end
1086
- ```
1087
-
1088
- Note that the automatic detection still won't work if the inverse
1089
- association has a scope. In this example a scope on the `post` association
1090
- would still prevent Rails from finding the inverse for the `comments`
1091
- association.
1092
-
1093
- This will be the default for new apps in Rails 7. To opt in:
1094
-
1095
- ```ruby
1096
- config.active_record.automatic_scope_inversing = true
1097
- ```
1098
-
1099
- *Daniel Colson*, *Chris Bloom*
1100
-
1101
- * Accept optional transaction args to `ActiveRecord::Locking::Pessimistic#with_lock`
1102
-
1103
- `#with_lock` now accepts transaction options like `requires_new:`,
1104
- `isolation:`, and `joinable:`
1105
-
1106
- *John Mileham*
1107
-
1108
- * Adds support for deferrable foreign key constraints in PostgreSQL.
1109
-
1110
- By default, foreign key constraints in PostgreSQL are checked after each statement. This works for most use cases,
1111
- but becomes a major limitation when creating related records before the parent record is inserted into the database.
1112
- One example of this is looking up / creating a person via one or more unique alias.
1113
-
1114
- ```ruby
1115
- Person.transaction do
1116
- alias = Alias
1117
- .create_with(user_id: SecureRandom.uuid)
1118
- .create_or_find_by(name: "DHH")
1119
-
1120
- person = Person
1121
- .create_with(name: "David Heinemeier Hansson")
1122
- .create_or_find_by(id: alias.user_id)
1123
- end
1124
- ```
1125
-
1126
- Using the default behavior, the transaction would fail when executing the first `INSERT` statement.
1127
-
1128
- By passing the `:deferrable` option to the `add_foreign_key` statement in migrations, it's possible to defer this
1129
- check.
1130
-
1131
- ```ruby
1132
- add_foreign_key :aliases, :person, deferrable: true
1133
- ```
1134
-
1135
- Passing `deferrable: true` doesn't change the default behavior, but allows manually deferring the check using
1136
- `SET CONSTRAINTS ALL DEFERRED` within a transaction. This will cause the foreign keys to be checked after the
1137
- transaction.
1138
-
1139
- It's also possible to adjust the default behavior from an immediate check (after the statement), to a deferred check
1140
- (after the transaction):
1141
-
1142
- ```ruby
1143
- add_foreign_key :aliases, :person, deferrable: :deferred
1144
- ```
1145
-
1146
- *Benedikt Deicke*
1147
-
1148
- * Allow configuring Postgres password through the socket URL.
1149
-
1150
- For example:
1151
- ```ruby
1152
- ActiveRecord::DatabaseConfigurations::UrlConfig.new(
1153
- :production, :production, 'postgres:///?user=user&password=secret&dbname=app', {}
1154
- ).configuration_hash
1155
- ```
1156
-
1157
- will now return,
1158
-
1159
- ```ruby
1160
- { :user=>"user", :password=>"secret", :dbname=>"app", :adapter=>"postgresql" }
1161
- ```
1162
-
1163
- *Abeid Ahmed*
1164
-
1165
- * PostgreSQL: support custom enum types
1166
-
1167
- In migrations, use `create_enum` to add a new enum type, and `t.enum` to add a column.
1168
-
1169
- ```ruby
1170
- def up
1171
- create_enum :mood, ["happy", "sad"]
1172
-
1173
- change_table :cats do |t|
1174
- t.enum :current_mood, enum_type: "mood", default: "happy", null: false
1175
- end
1176
- end
1177
- ```
1178
-
1179
- Enums will be presented correctly in `schema.rb`. Note that this is only supported by
1180
- the PostgreSQL adapter.
1181
-
1182
- *Alex Ghiculescu*
1183
-
1184
- * Avoid COMMENT statements in PostgreSQL structure dumps
1185
-
1186
- COMMENT statements are now omitted from the output of `db:structure:dump` when using PostgreSQL >= 11.
1187
- This allows loading the dump without a pgsql superuser account.
1188
-
1189
- Fixes #36816, #43107.
1190
-
1191
- *Janosch Müller*
1192
-
1193
- * Add support for generated columns in PostgreSQL adapter
1194
-
1195
- Generated columns are supported since version 12.0 of PostgreSQL. This adds
1196
- support of those to the PostgreSQL adapter.
1197
-
1198
- ```ruby
1199
- create_table :users do |t|
1200
- t.string :name
1201
- t.virtual :name_upcased, type: :string, as: 'upper(name)', stored: true
1202
- end
1203
- ```
1204
-
1205
- *Michał Begejowicz*
1206
-
1207
-
1208
- ## Rails 7.0.0.alpha2 (September 15, 2021) ##
1209
-
1210
- * No changes.
1211
-
1212
-
1213
- ## Rails 7.0.0.alpha1 (September 15, 2021) ##
1214
-
1215
- * Remove warning when overwriting existing scopes
1216
-
1217
- Removes the following unnecessary warning message that appeared when overwriting existing scopes
1218
-
1219
- ```
1220
- Creating scope :my_scope_name. Overwriting existing method "MyClass.my_scope_name" when overwriting existing scopes
1221
- ```
1222
-
1223
- *Weston Ganger*
1224
-
1225
- * Use full precision for `updated_at` in `insert_all`/`upsert_all`
1226
-
1227
- `CURRENT_TIMESTAMP` provides differing precision depending on the database,
1228
- and not all databases support explicitly specifying additional precision.
1229
-
1230
- Instead, we delegate to the new `connection.high_precision_current_timestamp`
1231
- for the SQL to produce a high precision timestamp on the current database.
1232
-
1233
- Fixes #42992
1234
-
1235
- *Sam Bostock*
1236
-
1237
- * Add ssl support for postgresql database tasks
1238
-
1239
- Add `PGSSLMODE`, `PGSSLCERT`, `PGSSLKEY` and `PGSSLROOTCERT` to pg_env from database config
1240
- when running postgresql database tasks.
1241
-
1242
- ```yaml
1243
- # config/database.yml
1244
-
1245
- production:
1246
- sslmode: verify-full
1247
- sslcert: client.crt
1248
- sslkey: client.key
1249
- sslrootcert: ca.crt
1250
- ```
1251
-
1252
- Environment variables
1253
-
1254
- ```
1255
- PGSSLMODE=verify-full
1256
- PGSSLCERT=client.crt
1257
- PGSSLKEY=client.key
1258
- PGSSLROOTCERT=ca.crt
1259
- ```
1260
-
1261
- Fixes #42994
1262
-
1263
- *Michael Bayucot*
1264
-
1265
- * Avoid scoping update callbacks in `ActiveRecord::Relation#update!`.
1266
-
1267
- Making it consistent with how scoping is applied only to the query in `ActiveRecord::Relation#update`
1268
- and not also to the callbacks from the update itself.
1269
-
1270
- *Dylan Thacker-Smith*
1271
-
1272
- * Fix 2 cases that inferred polymorphic class from the association's `foreign_type`
1273
- using `String#constantize` instead of the model's `polymorphic_class_for`.
1274
-
1275
- When updating a polymorphic association, the old `foreign_type` was not inferred correctly when:
1276
- 1. `touch`ing the previously associated record
1277
- 2. updating the previously associated record's `counter_cache`
1278
-
1279
- *Jimmy Bourassa*
1280
-
1281
- * Add config option for ignoring tables when dumping the schema cache.
1282
-
1283
- Applications can now be configured to ignore certain tables when dumping the schema cache.
1284
-
1285
- The configuration option can table an array of tables:
1286
-
1287
- ```ruby
1288
- config.active_record.schema_cache_ignored_tables = ["ignored_table", "another_ignored_table"]
1289
- ```
1290
-
1291
- Or a regex:
1292
-
1293
- ```ruby
1294
- config.active_record.schema_cache_ignored_tables = [/^_/]
1295
- ```
1296
-
1297
- *Eileen M. Uchitelle*
5
+ *Stephen Margheim*
1298
6
 
1299
- * Make schema cache methods return consistent results.
7
+ * Fixes `validates_associated` raising an exception when configured with a
8
+ singular association and having `index_nested_attribute_errors` enabled.
1300
9
 
1301
- Previously the schema cache methods `primary_keys`, `columns`, `columns_hash`, and `indexes`
1302
- would behave differently than one another when a table didn't exist and differently across
1303
- database adapters. This change unifies the behavior so each method behaves the same regardless
1304
- of adapter.
10
+ *Martin Spickermann*
1305
11
 
1306
- The behavior now is:
12
+ * The constant `ActiveRecord::ImmutableRelation` has been deprecated because
13
+ we want to reserve that name for a stronger sense of "immutable relation".
14
+ Please use `ActiveRecord::UnmodifiableRelation` instead.
1307
15
 
1308
- `columns`: (unchanged) raises a db error if the table does not exist.
1309
- `columns_hash`: (unchanged) raises a db error if the table does not exist.
1310
- `primary_keys`: (unchanged) returns `nil` if the table does not exist.
1311
- `indexes`: (changed for mysql2) returns `[]` if the table does not exist.
16
+ *Xavier Noria*
1312
17
 
1313
- *Eileen M. Uchitelle*
18
+ * Add condensed `#inspect` for `ConnectionPool`, `AbstractAdapter`, and
19
+ `DatabaseConfig`.
1314
20
 
1315
- * Reestablish connection to previous database after after running `db:schema:load:name`
21
+ *Hartley McGuire*
1316
22
 
1317
- After running `db:schema:load:name` the previous connection is restored.
23
+ * Fixed a memory performance issue in Active Record attribute methods definition.
1318
24
 
1319
- *Jacopo Beschi*
25
+ *Jean Boussier*
1320
26
 
1321
- * Add database config option `database_tasks`
27
+ * Define the new Active Support notification event `start_transaction.active_record`.
1322
28
 
1323
- If you would like to connect to an external database without any database
1324
- management tasks such as schema management, migrations, seeds, etc. you can set
1325
- the per database config option `database_tasks: false`
29
+ This event is fired when database transactions or savepoints start, and
30
+ complements `transaction.active_record`, which is emitted when they finish.
1326
31
 
1327
- ```yaml
1328
- # config/database.yml
1329
-
1330
- production:
1331
- primary:
1332
- database: my_database
1333
- adapter: mysql2
1334
- animals:
1335
- database: my_animals_database
1336
- adapter: mysql2
1337
- database_tasks: false
1338
- ```
32
+ The payload has the transaction (`:transaction`) and the connection (`:connection`).
1339
33
 
1340
- *Weston Ganger*
34
+ *Xavier Noria*
1341
35
 
1342
- * Fix `ActiveRecord::InternalMetadata` to not be broken by `config.active_record.record_timestamps = false`
36
+ * Fix an issue where the IDs reader method did not return expected results
37
+ for preloaded associations in models using composite primary keys.
1343
38
 
1344
- Since the model always create the timestamp columns, it has to set them, otherwise it breaks
1345
- various DB management tasks.
39
+ *Jay Ang*
1346
40
 
1347
- Fixes #42983
41
+ * The payload of `sql.active_record` Active Support notifications now has the current transaction in the `:transaction` key.
1348
42
 
1349
- * Add `ActiveRecord::QueryLogs`.
43
+ *Xavier Noria*
1350
44
 
1351
- Configurable tags can be automatically added to all SQL queries generated by Active Record.
45
+ * The payload of `transaction.active_record` Active Support notifications now has the transaction the event is related to in the `:transaction` key.
1352
46
 
1353
- ```ruby
1354
- # config/application.rb
1355
- module MyApp
1356
- class Application < Rails::Application
1357
- config.active_record.query_log_tags_enabled = true
1358
- end
1359
- end
1360
- ```
47
+ *Xavier Noria*
1361
48
 
1362
- By default the application, controller and action details are added to the query tags:
49
+ * 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.
1363
50
 
1364
- ```ruby
1365
- class BooksController < ApplicationController
1366
- def index
1367
- @books = Book.all
1368
- end
1369
- end
1370
- ```
51
+ *Xavier Noria*
1371
52
 
1372
- ```ruby
1373
- GET /books
1374
- # SELECT * FROM books /*application:MyApp;controller:books;action:index*/
1375
- ```
53
+ * Fix inference of association model on nested models with the same demodularized name.
1376
54
 
1377
- Custom tags containing static values and Procs can be defined in the application configuration:
55
+ E.g. with the following setup:
1378
56
 
1379
57
  ```ruby
1380
- config.active_record.query_log_tags = [
1381
- :application,
1382
- :controller,
1383
- :action,
1384
- {
1385
- custom_static: "foo",
1386
- custom_dynamic: -> { Time.now }
1387
- }
1388
- ]
58
+ class Nested::Post < ApplicationRecord
59
+ has_one :post, through: :other
60
+ end
1389
61
  ```
1390
62
 
1391
- *Keeran Raj Hawoldar*, *Eileen M. Uchitelle*, *Kasper Timm Hansen*
63
+ Before, `#post` would infer the model as `Nested::Post`, but now it correctly infers `Post`.
1392
64
 
1393
- * Added support for multiple databases to `rails db:setup` and `rails db:reset`.
65
+ *Joshua Young*
1394
66
 
1395
- *Ryan Hall*
67
+ * PostgreSQL `Cidr#change?` detects the address prefix change.
1396
68
 
1397
- * Add `ActiveRecord::Relation#structurally_compatible?`.
69
+ *Taketo Takashima*
1398
70
 
1399
- Adds a query method by which a user can tell if the relation that they're
1400
- about to use for `#or` or `#and` is structurally compatible with the
1401
- receiver.
71
+ * Change `BatchEnumerator#destroy_all` to return the total number of affected rows.
1402
72
 
1403
- *Kevin Newton*
73
+ Previously, it always returned `nil`.
1404
74
 
1405
- * Add `ActiveRecord::QueryMethods#in_order_of`.
75
+ *fatkodima*
1406
76
 
1407
- This allows you to specify an explicit order that you'd like records
1408
- returned in based on a SQL expression. By default, this will be accomplished
1409
- using a case statement, as in:
77
+ * Support `touch_all` in batches.
1410
78
 
1411
79
  ```ruby
1412
- Post.in_order_of(:id, [3, 5, 1])
80
+ Post.in_batches.touch_all
1413
81
  ```
1414
82
 
1415
- will generate the SQL:
83
+ *fatkodima*
1416
84
 
1417
- ```sql
1418
- SELECT "posts".* FROM "posts" ORDER BY CASE "posts"."id" WHEN 3 THEN 1 WHEN 5 THEN 2 WHEN 1 THEN 3 ELSE 4 END ASC
1419
- ```
85
+ * Add support for `:if_not_exists` and `:force` options to `create_schema`.
1420
86
 
1421
- However, because this functionality is built into MySQL in the form of the
1422
- `FIELD` function, that connection adapter will generate the following SQL
1423
- instead:
87
+ *fatkodima*
1424
88
 
1425
- ```sql
1426
- SELECT "posts".* FROM "posts" ORDER BY FIELD("posts"."id", 1, 5, 3) DESC
1427
- ```
89
+ * Fix `index_errors` having incorrect index in association validation errors.
1428
90
 
1429
- *Kevin Newton*
91
+ *lulalala*
1430
92
 
1431
- * Fix `eager_loading?` when ordering with `Symbol`.
93
+ * Add `index_errors: :nested_attributes_order` mode.
1432
94
 
1433
- `eager_loading?` is triggered correctly when using `order` with symbols.
95
+ 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.
1434
96
 
1435
- ```ruby
1436
- scope = Post.includes(:comments).order(:"comments.label")
1437
- => true
1438
- ```
97
+ *lulalala*
1439
98
 
1440
- *Jacopo Beschi*
99
+ * Add `Rails.application.config.active_record.postgresql_adapter_decode_dates` to opt out of decoding dates automatically with the postgresql adapter. Defaults to true.
1441
100
 
1442
- * Two change tracking methods are added for `belongs_to` associations.
101
+ *Joé Dupuis*
1443
102
 
1444
- The `association_changed?` method (assuming an association named `:association`) returns true
1445
- if a different associated object has been assigned and the foreign key will be updated in the
1446
- next save.
103
+ * Association option `query_constraints` is deprecated in favor of `foreign_key`.
1447
104
 
1448
- The `association_previously_changed?` method returns true if the previous save updated the
1449
- association to reference a different associated object.
105
+ *Nikita Vasilevsky*
1450
106
 
1451
- *George Claghorn*
107
+ * Add `ENV["SKIP_TEST_DATABASE_TRUNCATE"]` flag to speed up multi-process test runs on large DBs when all tests run within default transaction.
1452
108
 
1453
- * Add option to disable schema dump per-database.
109
+ 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.
1454
110
 
1455
- Dumping the schema is on by default for all databases in an application. To turn it off for a
1456
- specific database, use the `schema_dump` option:
111
+ *DHH*
1457
112
 
1458
- ```yaml
1459
- # config/database.yml
113
+ * Added support for recursive common table expressions.
1460
114
 
1461
- production:
1462
- schema_dump: false
115
+ ```ruby
116
+ Post.with_recursive(
117
+ post_and_replies: [
118
+ Post.where(id: 42),
119
+ Post.joins('JOIN post_and_replies ON posts.in_reply_to_id = post_and_replies.id'),
120
+ ]
121
+ )
1463
122
  ```
1464
123
 
1465
- *Luis Vasconcellos*, *Eileen M. Uchitelle*
1466
-
1467
- * Fix `eager_loading?` when ordering with `Hash` syntax.
1468
-
1469
- `eager_loading?` is triggered correctly when using `order` with hash syntax
1470
- on an outer table.
124
+ Generates the following SQL:
1471
125
 
1472
- ```ruby
1473
- Post.includes(:comments).order({ "comments.label": :ASC }).eager_loading?
1474
- # => true
126
+ ```sql
127
+ WITH RECURSIVE "post_and_replies" AS (
128
+ (SELECT "posts".* FROM "posts" WHERE "posts"."id" = 42)
129
+ UNION ALL
130
+ (SELECT "posts".* FROM "posts" JOIN post_and_replies ON posts.in_reply_to_id = post_and_replies.id)
131
+ )
132
+ SELECT "posts".* FROM "posts"
1475
133
  ```
1476
134
 
1477
- *Jacopo Beschi*
1478
-
1479
- * Move the forcing of clear text encoding to the `ActiveRecord::Encryption::Encryptor`.
135
+ *ClearlyClaire*
1480
136
 
1481
- Fixes #42699.
137
+ * `validate_constraint` can be called in a `change_table` block.
1482
138
 
1483
- *J Smith*
139
+ ex:
140
+ ```ruby
141
+ change_table :products do |t|
142
+ t.check_constraint "price > discounted_price", name: "price_check", validate: false
143
+ t.validate_check_constraint "price_check"
144
+ end
145
+ ```
1484
146
 
1485
- * `partial_inserts` is now disabled by default in new apps.
147
+ *Cody Cutrer*
1486
148
 
1487
- This will be the default for new apps in Rails 7. To opt in:
149
+ * `PostgreSQLAdapter` now decodes columns of type date to `Date` instead of string.
1488
150
 
151
+ Ex:
1489
152
  ```ruby
1490
- config.active_record.partial_inserts = true
153
+ ActiveRecord::Base.connection
154
+ .select_value("select '2024-01-01'::date").class #=> Date
1491
155
  ```
1492
156
 
1493
- If a migration removes the default value of a column, this option
1494
- would cause old processes to no longer be able to create new records.
1495
-
1496
- If you need to remove a column, you should first use `ignored_columns`
1497
- to stop using it.
157
+ *Joé Dupuis*
1498
158
 
1499
- *Jean Boussier*
159
+ * Strict loading using `:n_plus_one_only` does not eagerly load child associations.
1500
160
 
1501
- * Rails can now verify foreign keys after loading fixtures in tests.
161
+ With this change, child associations are no longer eagerly loaded, to
162
+ match intended behavior and to prevent non-deterministic order issues caused
163
+ by calling methods like `first` or `last`. As `first` and `last` don't cause
164
+ an N+1 by themselves, calling child associations will no longer raise.
165
+ Fixes #49473.
1502
166
 
1503
- This will be the default for new apps in Rails 7. To opt in:
167
+ Before:
1504
168
 
1505
169
  ```ruby
1506
- config.active_record.verify_foreign_keys_for_fixtures = true
170
+ person = Person.find(1)
171
+ person.strict_loading!(mode: :n_plus_one_only)
172
+ person.posts.first
173
+ # SELECT * FROM posts WHERE person_id = 1; -- non-deterministic order
174
+ person.posts.first.firm # raises ActiveRecord::StrictLoadingViolationError
1507
175
  ```
1508
176
 
1509
- Tests will not run if there is a foreign key constraint violation in your fixture data.
177
+ After:
1510
178
 
1511
- The feature is supported by SQLite and PostgreSQL, other adapters can also add support for it.
179
+ ```ruby
180
+ person = Person.find(1)
181
+ person.strict_loading!(mode: :n_plus_one_only)
182
+ person.posts.first # this is 1+1, not N+1
183
+ # SELECT * FROM posts WHERE person_id = 1 ORDER BY id LIMIT 1;
184
+ person.posts.first.firm # no longer raises
185
+ ```
1512
186
 
1513
- *Alex Ghiculescu*
187
+ *Reid Lynch*
1514
188
 
1515
- * Clear cached `has_one` association after setting `belongs_to` association to `nil`.
189
+ * Allow `Sqlite3Adapter` to use `sqlite3` gem version `2.x`.
1516
190
 
1517
- After setting a `belongs_to` relation to `nil` and updating an unrelated attribute on the owner,
1518
- the owner should still return `nil` on the `has_one` relation.
191
+ *Mike Dalessio*
1519
192
 
1520
- Fixes #42597.
193
+ * Allow `ActiveRecord::Base#pluck` to accept hash values.
1521
194
 
1522
- *Michiel de Mare*
195
+ ```ruby
196
+ # Before
197
+ Post.joins(:comments).pluck("posts.id", "comments.id", "comments.body")
1523
198
 
1524
- * OpenSSL constants are now used for Digest computations.
199
+ # After
200
+ Post.joins(:comments).pluck(posts: [:id], comments: [:id, :body])
201
+ ```
1525
202
 
1526
- *Dirkjan Bussink*
203
+ *fatkodima*
1527
204
 
1528
- * Adds support for `if_not_exists` to `add_foreign_key` and `if_exists` to `remove_foreign_key`.
205
+ * Raise an `ActiveRecord::ActiveRecordError` error when the MySQL database returns an invalid version string.
1529
206
 
1530
- Applications can set their migrations to ignore exceptions raised when adding a foreign key
1531
- that already exists or when removing a foreign key that does not exist.
207
+ *Kevin McPhillips*
1532
208
 
1533
- Example Usage:
209
+ * `ActiveRecord::Base.transaction` now yields an `ActiveRecord::Transaction` object.
1534
210
 
1535
- ```ruby
1536
- class AddAuthorsForeignKeyToArticles < ActiveRecord::Migration[7.0]
1537
- def change
1538
- add_foreign_key :articles, :authors, if_not_exists: true
1539
- end
1540
- end
1541
- ```
211
+ This allows to register callbacks on it.
1542
212
 
1543
213
  ```ruby
1544
- class RemoveAuthorsForeignKeyFromArticles < ActiveRecord::Migration[7.0]
1545
- def change
1546
- remove_foreign_key :articles, :authors, if_exists: true
214
+ Article.transaction do |transaction|
215
+ article.update(published: true)
216
+ transaction.after_commit do
217
+ PublishNotificationMailer.with(article: article).deliver_later
1547
218
  end
1548
219
  end
1549
220
  ```
1550
221
 
1551
- *Roberto Miranda*
1552
-
1553
- * Prevent polluting ENV during postgresql structure dump/load.
1554
-
1555
- Some configuration parameters were provided to pg_dump / psql via
1556
- environment variables which persisted beyond the command being run, and may
1557
- have caused subsequent commands and connections to fail. Tasks running
1558
- across multiple postgresql databases like `rails db:test:prepare` may have
1559
- been affected.
1560
-
1561
- *Samuel Cochran*
222
+ *Jean Boussier*
1562
223
 
1563
- * Set precision 6 by default for `datetime` columns.
224
+ * Add `ActiveRecord::Base.current_transaction`.
1564
225
 
1565
- By default, datetime columns will have microseconds precision instead of seconds precision.
226
+ Returns the current transaction, to allow registering callbacks on it.
1566
227
 
1567
- *Roberto Miranda*
228
+ ```ruby
229
+ Article.current_transaction.after_commit do
230
+ PublishNotificationMailer.with(article: article).deliver_later
231
+ end
232
+ ```
1568
233
 
1569
- * Allow preloading of associations with instance dependent scopes.
234
+ *Jean Boussier*
1570
235
 
1571
- *John Hawthorn*, *John Crepezzi*, *Adam Hess*, *Eileen M. Uchitelle*, *Dinah Shi*
236
+ * Add `ActiveRecord.after_all_transactions_commit` callback.
1572
237
 
1573
- * Do not try to rollback transactions that failed due to a `ActiveRecord::TransactionRollbackError`.
238
+ Useful for code that may run either inside or outside a transaction and needs
239
+ to perform work after the state changes have been properly persisted.
1574
240
 
1575
- *Jamie McCarthy*
241
+ ```ruby
242
+ def publish_article(article)
243
+ article.update(published: true)
244
+ ActiveRecord.after_all_transactions_commit do
245
+ PublishNotificationMailer.with(article: article).deliver_later
246
+ end
247
+ end
248
+ ```
1576
249
 
1577
- * Active Record Encryption will now encode values as UTF-8 when using deterministic
1578
- encryption. The encoding is part of the encrypted payload, so different encodings for
1579
- different values result in different ciphertexts. This can break unique constraints and
1580
- queries.
250
+ In the above example, the block is either executed immediately if called outside
251
+ of a transaction, or called after the open transaction is committed.
1581
252
 
1582
- The new behavior is configurable via `active_record.encryption.forced_encoding_for_deterministic_encryption`
1583
- that is `Encoding::UTF_8` by default. It can be disabled by setting it to `nil`.
253
+ If the transaction is rolled back, the block isn't called.
1584
254
 
1585
- *Jorge Manrubia*
255
+ *Jean Boussier*
1586
256
 
1587
- * The MySQL adapter now cast numbers and booleans bind parameters to string for safety reasons.
257
+ * Add the ability to ignore counter cache columns until they are backfilled.
1588
258
 
1589
- When comparing a string and a number in a query, MySQL converts the string to a number. So for
1590
- instance `"foo" = 0`, will implicitly cast `"foo"` to `0` and will evaluate to `TRUE` which can
1591
- lead to security vulnerabilities.
259
+ Starting to use counter caches on existing large tables can be troublesome, because the column
260
+ values must be backfilled separately of the column addition (to not lock the table for too long)
261
+ and before the use of `:counter_cache` (otherwise methods like `size`/`any?`/etc, which use
262
+ counter caches internally, can produce incorrect results). People usually use database triggers
263
+ or callbacks on child associations while backfilling before introducing a counter cache
264
+ configuration to the association.
1592
265
 
1593
- Active Record already protect against that vulnerability when it knows the type of the column
1594
- being compared, however until now it was still vulnerable when using bind parameters:
266
+ Now, to safely backfill the column, while keeping the column updated with child records added/removed, use:
1595
267
 
1596
268
  ```ruby
1597
- User.where("login_token = ?", 0).first
269
+ class Comment < ApplicationRecord
270
+ belongs_to :post, counter_cache: { active: false }
271
+ end
1598
272
  ```
1599
273
 
1600
- Would perform:
274
+ While the counter cache is not "active", the methods like `size`/`any?`/etc will not use it,
275
+ but get the results directly from the database. After the counter cache column is backfilled, simply
276
+ remove the `{ active: false }` part from the counter cache definition, and it will now be used by the
277
+ mentioned methods.
1601
278
 
1602
- ```sql
1603
- SELECT * FROM `users` WHERE `login_token` = 0 LIMIT 1;
1604
- ```
279
+ *fatkodima*
1605
280
 
1606
- Now it will perform:
281
+ * Retry known idempotent SELECT queries on connection-related exceptions.
1607
282
 
1608
- ```sql
1609
- SELECT * FROM `users` WHERE `login_token` = '0' LIMIT 1;
1610
- ```
283
+ SELECT queries we construct by walking the Arel tree and / or with known model attributes
284
+ are idempotent and can safely be retried in the case of a connection error. Previously,
285
+ adapters such as `TrilogyAdapter` would raise `ActiveRecord::ConnectionFailed: Trilogy::EOFError`
286
+ when encountering a connection error mid-request.
1611
287
 
1612
- *Jean Boussier*
288
+ *Adrianna Chang*
1613
289
 
1614
- * Fixture configurations (`_fixture`) are now strictly validated.
290
+ * Allow association's `foreign_key` to be composite.
1615
291
 
1616
- If an error will be raised if that entry contains unknown keys while previously it
1617
- would silently have no effects.
292
+ `query_constraints` option was the only way to configure a composite foreign key by passing an `Array`.
293
+ Now it's possible to pass an Array value as `foreign_key` to achieve the same behavior of an association.
1618
294
 
1619
- *Jean Boussier*
295
+ *Nikita Vasilevsky*
1620
296
 
1621
- * Add `ActiveRecord::Base.update!` that works like `ActiveRecord::Base.update` but raises exceptions.
297
+ * Allow association's `primary_key` to be composite.
1622
298
 
1623
- This allows for the same behavior as the instance method `#update!` at a class level.
299
+ Association's `primary_key` can be composite when derived from associated model `primary_key` or `query_constraints`.
300
+ Now it's possible to explicitly set it as composite on the association.
1624
301
 
1625
- ```ruby
1626
- Person.update!(:all, state: "confirmed")
1627
- ```
302
+ *Nikita Vasilevsky*
1628
303
 
1629
- *Dorian Marié*
304
+ * Add `config.active_record.permanent_connection_checkout` setting.
1630
305
 
1631
- * Add `ActiveRecord::Base#attributes_for_database`.
306
+ Controls whether `ActiveRecord::Base.connection` raises an error, emits a deprecation warning, or neither.
1632
307
 
1633
- Returns attributes with values for assignment to the database.
308
+ `ActiveRecord::Base.connection` checkouts a database connection from the pool and keeps it leased until the end of
309
+ the request or job. This behavior can be undesirable in environments that use many more threads or fibers than there
310
+ is available connections.
1634
311
 
1635
- *Chris Salzberg*
312
+ This configuration can be used to track down and eliminate code that calls `ActiveRecord::Base.connection` and
313
+ migrate it to use `ActiveRecord::Base.with_connection` instead.
1636
314
 
1637
- * Use an empty query to check if the PostgreSQL connection is still active.
315
+ The default behavior remains unchanged, and there is currently no plans to change the default.
1638
316
 
1639
- An empty query is faster than `SELECT 1`.
317
+ *Jean Boussier*
1640
318
 
1641
- *Heinrich Lee Yu*
319
+ * Add dirties option to uncached.
1642
320
 
1643
- * Add `ActiveRecord::Base#previously_persisted?`.
321
+ This adds a `dirties` option to `ActiveRecord::Base.uncached` and
322
+ `ActiveRecord::ConnectionAdapters::ConnectionPool#uncached`.
1644
323
 
1645
- Returns `true` if the object has been previously persisted but now it has been deleted.
324
+ When set to `true` (the default), writes will clear all query caches belonging to the current thread.
325
+ When set to `false`, writes to the affected connection pool will not clear any query cache.
1646
326
 
1647
- * Deprecate `partial_writes` in favor of `partial_inserts` and `partial_updates`.
327
+ This is needed by Solid Cache so that cache writes do not clear query caches.
1648
328
 
1649
- This allows to have a different behavior on update and create.
329
+ *Donal McBreen*
1650
330
 
1651
- *Jean Boussier*
331
+ * Deprecate `ActiveRecord::Base.connection` in favor of `.lease_connection`.
1652
332
 
1653
- * Fix compatibility with `psych >= 4`.
333
+ The method has been renamed as `lease_connection` to better reflect that the returned
334
+ connection will be held for the duration of the request or job.
1654
335
 
1655
- Starting in Psych 4.0.0 `YAML.load` behaves like `YAML.safe_load`. To preserve compatibility,
1656
- Active Record's schema cache loader and `YAMLColumn` now uses `YAML.unsafe_load` if available.
336
+ This deprecation is a soft deprecation, no warnings will be issued and there is no
337
+ current plan to remove the method.
1657
338
 
1658
339
  *Jean Boussier*
1659
340
 
1660
- * `ActiveRecord::Base.logger` is now a `class_attribute`.
341
+ * Deprecate `ActiveRecord::ConnectionAdapters::ConnectionPool#connection`.
1661
342
 
1662
- This means it can no longer be accessed directly through `@@logger`, and that setting `logger =`
1663
- on a subclass won't change the parent's logger.
343
+ The method has been renamed as `lease_connection` to better reflect that the returned
344
+ connection will be held for the duration of the request or job.
1664
345
 
1665
346
  *Jean Boussier*
1666
347
 
1667
- * Add `.asc.nulls_first` for all databases. Unfortunately MySQL still doesn't like `nulls_last`.
348
+ * Expose a generic fixture accessor for fixture names that may conflict with Minitest.
1668
349
 
1669
- *Keenan Brock*
350
+ ```ruby
351
+ assert_equal "Ruby on Rails", web_sites(:rubyonrails).name
352
+ assert_equal "Ruby on Rails", fixture(:web_sites, :rubyonrails).name
353
+ ```
1670
354
 
1671
- * Improve performance of `one?` and `many?` by limiting the generated count query to 2 results.
355
+ *Jean Boussier*
1672
356
 
1673
- *Gonzalo Riestra*
357
+ * Using `Model.query_constraints` with a single non-primary-key column used to raise as expected, but with an
358
+ incorrect error message.
1674
359
 
1675
- * Don't check type when using `if_not_exists` on `add_column`.
360
+ This has been fixed to raise with a more appropriate error message.
1676
361
 
1677
- Previously, if a migration called `add_column` with the `if_not_exists` option set to true
1678
- the `column_exists?` check would look for a column with the same name and type as the migration.
362
+ *Joshua Young*
1679
363
 
1680
- Recently it was discovered that the type passed to the migration is not always the same type
1681
- as the column after migration. For example a column set to `:mediumblob` in the migration will
1682
- be casted to `binary` when calling `column.type`. Since there is no straightforward way to cast
1683
- the type to the database type without running the migration, we opted to drop the type check from
1684
- `add_column`. This means that migrations adding a duplicate column with a different type will no
1685
- longer raise an error.
364
+ * Fix `has_one` association autosave setting the foreign key attribute when it is unchanged.
1686
365
 
1687
- *Eileen M. Uchitelle*
366
+ This behavior is also inconsistent with autosaving `belongs_to` and can have unintended side effects like raising
367
+ an `ActiveRecord::ReadonlyAttributeError` when the foreign key attribute is marked as read-only.
1688
368
 
1689
- * Log a warning message when running SQLite in production.
369
+ *Joshua Young*
1690
370
 
1691
- Using SQLite in production ENV is generally discouraged. SQLite is also the default adapter
1692
- in a new Rails application.
1693
- For the above reasons log a warning message when running SQLite in production.
371
+ * Remove deprecated behavior that would rollback a transaction block when exited using `return`, `break` or `throw`.
1694
372
 
1695
- The warning can be disabled by setting `config.active_record.sqlite3_production_warning=false`.
373
+ *Rafael Mendonça França*
1696
374
 
1697
- *Jacopo Beschi*
375
+ * Deprecate `Rails.application.config.active_record.commit_transaction_on_non_local_return`.
1698
376
 
1699
- * Add option to disable joins for `has_one` associations.
377
+ *Rafael Mendonça França*
1700
378
 
1701
- In a multiple database application, associations can't join across
1702
- databases. When set, this option instructs Rails to generate 2 or
1703
- more queries rather than generating joins for `has_one` associations.
379
+ * Remove deprecated support to pass `rewhere` to `ActiveRecord::Relation#merge`.
1704
380
 
1705
- Set the option on a has one through association:
381
+ *Rafael Mendonça França*
1706
382
 
1707
- ```ruby
1708
- class Person
1709
- has_one :dog
1710
- has_one :veterinarian, through: :dog, disable_joins: true
1711
- end
1712
- ```
383
+ * Remove deprecated support to pass `deferrable: true` to `add_foreign_key`.
1713
384
 
1714
- Then instead of generating join SQL, two queries are used for `@person.veterinarian`:
385
+ *Rafael Mendonça França*
1715
386
 
1716
- ```
1717
- SELECT "dogs"."id" FROM "dogs" WHERE "dogs"."person_id" = ? [["person_id", 1]]
1718
- SELECT "veterinarians".* FROM "veterinarians" WHERE "veterinarians"."dog_id" = ? [["dog_id", 1]]
1719
- ```
387
+ * Remove deprecated support to quote `ActiveSupport::Duration`.
1720
388
 
1721
- *Sarah Vessels*, *Eileen M. Uchitelle*
389
+ *Rafael Mendonça França*
1722
390
 
1723
- * `Arel::Visitors::Dot` now renders a complete set of properties when visiting
1724
- `Arel::Nodes::SelectCore`, `SelectStatement`, `InsertStatement`, `UpdateStatement`, and
1725
- `DeleteStatement`, which fixes #42026. Previously, some properties were omitted.
391
+ * Remove deprecated `#quote_bound_value`.
1726
392
 
1727
- *Mike Dalessio*
393
+ *Rafael Mendonça França*
1728
394
 
1729
- * `Arel::Visitors::Dot` now supports `Arel::Nodes::Bin`, `Case`, `CurrentRow`, `Distinct`,
1730
- `DistinctOn`, `Else`, `Except`, `InfixOperation`, `Intersect`, `Lock`, `NotRegexp`, `Quoted`,
1731
- `Regexp`, `UnaryOperation`, `Union`, `UnionAll`, `When`, and `With`. Previously, these node
1732
- types caused an exception to be raised by `Arel::Visitors::Dot#accept`.
395
+ * Remove deprecated `ActiveRecord::ConnectionAdapters::ConnectionPool#connection_klass`.
1733
396
 
1734
- *Mike Dalessio*
397
+ *Rafael Mendonça França*
1735
398
 
1736
- * Optimize `remove_columns` to use a single SQL statement.
399
+ * Remove deprecated support to apply `#connection_pool_list`, `#active_connections?`, `#clear_active_connections!`,
400
+ `#clear_reloadable_connections!`, `#clear_all_connections!` and `#flush_idle_connections!` to the connections pools
401
+ for the current role when the `role` argument isn't provided.
1737
402
 
1738
- ```ruby
1739
- remove_columns :my_table, :col_one, :col_two
1740
- ```
403
+ *Rafael Mendonça França*
1741
404
 
1742
- Now results in the following SQL:
405
+ * Remove deprecated `#all_connection_pools`.
1743
406
 
1744
- ```sql
1745
- ALTER TABLE "my_table" DROP COLUMN "col_one", DROP COLUMN "col_two"
1746
- ```
407
+ *Rafael Mendonça França*
1747
408
 
1748
- *Jon Dufresne*
409
+ * Remove deprecated `ActiveRecord::ConnectionAdapters::SchemaCache#data_sources`.
1749
410
 
1750
- * Ensure `has_one` autosave association callbacks get called once.
411
+ *Rafael Mendonça França*
1751
412
 
1752
- Change the `has_one` autosave callback to be non cyclic as well.
1753
- By doing this the autosave callback are made more consistent for
1754
- all 3 cases: `has_many`, `has_one`, and `belongs_to`.
413
+ * Remove deprecated `ActiveRecord::ConnectionAdapters::SchemaCache.load_from`.
1755
414
 
1756
- *Petrik de Heus*
415
+ *Rafael Mendonça França*
1757
416
 
1758
- * Add option to disable joins for associations.
417
+ * Remove deprecated `#all_foreign_keys_valid?` from database adapters.
1759
418
 
1760
- In a multiple database application, associations can't join across
1761
- databases. When set, this option instructs Rails to generate 2 or
1762
- more queries rather than generating joins for associations.
419
+ *Rafael Mendonça França*
1763
420
 
1764
- Set the option on a has many through association:
421
+ * Remove deprecated support to passing coder and class as second argument to `serialize`.
1765
422
 
1766
- ```ruby
1767
- class Dog
1768
- has_many :treats, through: :humans, disable_joins: true
1769
- has_many :humans
1770
- end
1771
- ```
423
+ *Rafael Mendonça França*
1772
424
 
1773
- Then instead of generating join SQL, two queries are used for `@dog.treats`:
425
+ * Remove deprecated support to `ActiveRecord::Base#read_attribute(:id)` to return the custom primary key value.
1774
426
 
1775
- ```
1776
- SELECT "humans"."id" FROM "humans" WHERE "humans"."dog_id" = ? [["dog_id", 1]]
1777
- SELECT "treats".* FROM "treats" WHERE "treats"."human_id" IN (?, ?, ?) [["human_id", 1], ["human_id", 2], ["human_id", 3]]
1778
- ```
427
+ *Rafael Mendonça França*
1779
428
 
1780
- *Eileen M. Uchitelle*, *Aaron Patterson*, *Lee Quarella*
429
+ * Remove deprecated `TestFixtures.fixture_path`.
1781
430
 
1782
- * Add setting for enumerating column names in SELECT statements.
431
+ *Rafael Mendonça França*
1783
432
 
1784
- Adding a column to a PostgreSQL database, for example, while the application is running can
1785
- change the result of wildcard `SELECT *` queries, which invalidates the result
1786
- of cached prepared statements and raises a `PreparedStatementCacheExpired` error.
433
+ * Remove deprecated behavior to support referring to a singular association by its plural name.
1787
434
 
1788
- When enabled, Active Record will avoid wildcards and always include column names
1789
- in `SELECT` queries, which will return consistent results and avoid prepared
1790
- statement errors.
435
+ *Rafael Mendonça França*
1791
436
 
1792
- Before:
437
+ * Deprecate `Rails.application.config.active_record.allow_deprecated_singular_associations_name`.
1793
438
 
1794
- ```ruby
1795
- Book.limit(5)
1796
- # SELECT * FROM books LIMIT 5
1797
- ```
439
+ *Rafael Mendonça França*
1798
440
 
1799
- After:
441
+ * Remove deprecated support to passing `SchemaMigration` and `InternalMetadata` classes as arguments to
442
+ `ActiveRecord::MigrationContext`.
1800
443
 
1801
- ```ruby
1802
- # config/application.rb
1803
- module MyApp
1804
- class Application < Rails::Application
1805
- config.active_record.enumerate_columns_in_select_statements = true
1806
- end
1807
- end
444
+ *Rafael Mendonça França*
1808
445
 
1809
- # or, configure per-model
1810
- class Book < ApplicationRecord
1811
- self.enumerate_columns_in_select_statements = true
1812
- end
1813
- ```
446
+ * Remove deprecated `ActiveRecord::Migration.check_pending!` method.
1814
447
 
1815
- ```ruby
1816
- Book.limit(5)
1817
- # SELECT id, author_id, name, format, status, language, etc FROM books LIMIT 5
1818
- ```
448
+ *Rafael Mendonça França*
1819
449
 
1820
- *Matt Duszynski*
450
+ * Remove deprecated `ActiveRecord::LogSubscriber.runtime` method.
1821
451
 
1822
- * Allow passing SQL as `on_duplicate` value to `#upsert_all` to make it possible to use raw SQL to update columns on conflict:
452
+ *Rafael Mendonça França*
1823
453
 
1824
- ```ruby
1825
- Book.upsert_all(
1826
- [{ id: 1, status: 1 }, { id: 2, status: 1 }],
1827
- on_duplicate: Arel.sql("status = GREATEST(books.status, EXCLUDED.status)")
1828
- )
1829
- ```
454
+ * Remove deprecated `ActiveRecord::LogSubscriber.runtime=` method.
1830
455
 
1831
- *Vladimir Dementyev*
456
+ *Rafael Mendonça França*
1832
457
 
1833
- * Allow passing SQL as `returning` statement to `#upsert_all`:
458
+ * Remove deprecated `ActiveRecord::LogSubscriber.reset_runtime` method.
1834
459
 
1835
- ```ruby
1836
- Article.insert_all(
1837
- [
1838
- { title: "Article 1", slug: "article-1", published: false },
1839
- { title: "Article 2", slug: "article-2", published: false }
1840
- ],
1841
- returning: Arel.sql("id, (xmax = '0') as inserted, name as new_name")
1842
- )
1843
- ```
460
+ *Rafael Mendonça França*
1844
461
 
1845
- *Vladimir Dementyev*
462
+ * Remove deprecated support to define `explain` in the connection adapter with 2 arguments.
1846
463
 
1847
- * Deprecate `legacy_connection_handling`.
464
+ *Rafael Mendonça França*
1848
465
 
1849
- *Eileen M. Uchitelle*
466
+ * Remove deprecated `ActiveRecord::ActiveJobRequiredError`.
1850
467
 
1851
- * Add attribute encryption support.
468
+ *Rafael Mendonça França*
1852
469
 
1853
- Encrypted attributes are declared at the model level. These
1854
- are regular Active Record attributes backed by a column with
1855
- the same name. The system will transparently encrypt these
1856
- attributes before saving them into the database and will
1857
- decrypt them when retrieving their values.
470
+ * Remove deprecated `ActiveRecord::Base.clear_active_connections!`.
1858
471
 
472
+ *Rafael Mendonça França*
1859
473
 
1860
- ```ruby
1861
- class Person < ApplicationRecord
1862
- encrypts :name
1863
- encrypts :email_address, deterministic: true
1864
- end
1865
- ```
474
+ * Remove deprecated `ActiveRecord::Base.clear_reloadable_connections!`.
1866
475
 
1867
- You can learn more in the [Active Record Encryption
1868
- guide](https://edgeguides.rubyonrails.org/active_record_encryption.html).
476
+ *Rafael Mendonça França*
1869
477
 
1870
- *Jorge Manrubia*
478
+ * Remove deprecated `ActiveRecord::Base.clear_all_connections!`.
1871
479
 
1872
- * Changed Arel predications `contains` and `overlaps` to use
1873
- `quoted_node` so that PostgreSQL arrays are quoted properly.
480
+ *Rafael Mendonça França*
1874
481
 
1875
- *Bradley Priest*
482
+ * Remove deprecated `ActiveRecord::Base.flush_idle_connections!`.
1876
483
 
1877
- * Add mode argument to record level `strict_loading!`.
484
+ *Rafael Mendonça França*
1878
485
 
1879
- This argument can be used when enabling strict loading for a single record
1880
- to specify that we only want to raise on n plus one queries.
486
+ * Remove deprecated `name` argument from `ActiveRecord::Base.remove_connection`.
1881
487
 
1882
- ```ruby
1883
- developer.strict_loading!(mode: :n_plus_one_only)
488
+ *Rafael Mendonça França*
1884
489
 
1885
- developer.projects.to_a # Does not raise
1886
- developer.projects.first.client # Raises StrictLoadingViolationError
1887
- ```
490
+ * Remove deprecated support to call `alias_attribute` with non-existent attribute names.
1888
491
 
1889
- Previously, enabling strict loading would cause any lazily loaded
1890
- association to raise an error. Using `n_plus_one_only` mode allows us to
1891
- lazily load belongs_to, has_many, and other associations that are fetched
1892
- through a single query.
492
+ *Rafael Mendonça França*
1893
493
 
1894
- *Dinah Shi*
494
+ * Remove deprecated `Rails.application.config.active_record.suppress_multiple_database_warning`.
1895
495
 
1896
- * Fix Float::INFINITY assignment to datetime column with postgresql adapter.
496
+ *Rafael Mendonça França*
1897
497
 
1898
- Before:
498
+ * Add `ActiveRecord::Encryption::MessagePackMessageSerializer`.
1899
499
 
1900
- ```ruby
1901
- # With this config
1902
- ActiveRecord::Base.time_zone_aware_attributes = true
500
+ Serialize data to the MessagePack format, for efficient storage in binary columns.
1903
501
 
1904
- # and the following schema:
1905
- create_table "postgresql_infinities" do |t|
1906
- t.datetime "datetime"
1907
- end
502
+ The binary encoding requires around 30% less space than the base64 encoding
503
+ used by the default serializer.
1908
504
 
1909
- # This test fails
1910
- record = PostgresqlInfinity.create!(datetime: Float::INFINITY)
1911
- assert_equal Float::INFINITY, record.datetime # record.datetime gets nil
1912
- ```
505
+ *Donal McBreen*
1913
506
 
1914
- After this commit, `record.datetime` gets `Float::INFINITY` as expected.
507
+ * Add support for encrypting binary columns.
1915
508
 
1916
- *Shunichi Ikegami*
509
+ Ensure encryption and decryption pass `Type::Binary::Data` around for binary data.
1917
510
 
1918
- * Type cast enum values by the original attribute type.
511
+ Previously encrypting binary columns with the `ActiveRecord::Encryption::MessageSerializer`
512
+ incidentally worked for MySQL and SQLite, but not PostgreSQL.
1919
513
 
1920
- The notable thing about this change is that unknown labels will no longer match 0 on MySQL.
514
+ *Donal McBreen*
1921
515
 
1922
- ```ruby
1923
- class Book < ActiveRecord::Base
1924
- enum :status, { proposed: 0, written: 1, published: 2 }
1925
- end
1926
- ```
516
+ * Deprecated `ENV["SCHEMA_CACHE"]` in favor of `schema_cache_path` in the database configuration.
1927
517
 
1928
- Before:
518
+ *Rafael Mendonça França*
1929
519
 
1930
- ```ruby
1931
- # SELECT `books`.* FROM `books` WHERE `books`.`status` = 'prohibited' LIMIT 1
1932
- Book.find_by(status: :prohibited)
1933
- # => #<Book id: 1, status: "proposed", ...> (for mysql2 adapter)
1934
- # => ActiveRecord::StatementInvalid: PG::InvalidTextRepresentation: ERROR: invalid input syntax for type integer: "prohibited" (for postgresql adapter)
1935
- # => nil (for sqlite3 adapter)
1936
- ```
520
+ * Add `ActiveRecord::Base.with_connection` as a shortcut for leasing a connection for a short duration.
1937
521
 
1938
- After:
522
+ The leased connection is yielded, and for the duration of the block, any call to `ActiveRecord::Base.connection`
523
+ will yield that same connection.
1939
524
 
1940
- ```ruby
1941
- # SELECT `books`.* FROM `books` WHERE `books`.`status` IS NULL LIMIT 1
1942
- Book.find_by(status: :prohibited)
1943
- # => nil (for all adapters)
1944
- ```
525
+ This is useful to perform a few database operations without causing a connection to be leased for the
526
+ entire duration of the request or job.
1945
527
 
1946
- *Ryuta Kamizono*
528
+ *Jean Boussier*
1947
529
 
1948
- * Fixtures for `has_many :through` associations now load timestamps on join tables.
530
+ * Deprecate `config.active_record.warn_on_records_fetched_greater_than` now that `sql.active_record`
531
+ notification includes `:row_count` field.
1949
532
 
1950
- Given this fixture:
533
+ *Jason Nochlin*
1951
534
 
1952
- ```yml
1953
- ### monkeys.yml
1954
- george:
1955
- name: George the Monkey
1956
- fruits: apple
535
+ * The fix ensures that the association is joined using the appropriate join type
536
+ (either inner join or left outer join) based on the existing joins in the scope.
1957
537
 
1958
- ### fruits.yml
1959
- apple:
1960
- name: apple
1961
- ```
538
+ This prevents unintentional overrides of existing join types and ensures consistency in the generated SQL queries.
1962
539
 
1963
- If the join table (`fruit_monkeys`) contains `created_at` or `updated_at` columns,
1964
- these will now be populated when loading the fixture. Previously, fixture loading
1965
- would crash if these columns were required, and leave them as null otherwise.
540
+ Example:
1966
541
 
1967
- *Alex Ghiculescu*
1968
542
 
1969
- * Allow applications to configure the thread pool for async queries.
1970
543
 
1971
- Some applications may want one thread pool per database whereas others want to use
1972
- a single global thread pool for all queries. By default, Rails will set `async_query_executor`
1973
- to `nil` which will not initialize any executor. If `load_async` is called and no executor
1974
- has been configured, the query will be executed in the foreground.
544
+ ```ruby
545
+ # `associated` will use `LEFT JOIN` instead of using `JOIN`
546
+ Post.left_joins(:author).where.associated(:author)
547
+ ```
1975
548
 
1976
- To create one thread pool for all database connections to use applications can set
1977
- `config.active_record.async_query_executor` to `:global_thread_pool` and optionally define
1978
- `config.active_record.global_executor_concurrency`. This defaults to 4. For applications that want
1979
- to have a thread pool for each database connection, `config.active_record.async_query_executor` can
1980
- be set to `:multi_thread_pool`. The configuration for each thread pool is set in the database
1981
- configuration.
549
+ *Saleh Alhaddad*
1982
550
 
1983
- *Eileen M. Uchitelle*
551
+ * Fix an issue where `ActiveRecord::Encryption` configurations are not ready before the loading
552
+ of Active Record models, when an application is eager loaded. As a result, encrypted attributes
553
+ could be misconfigured in some cases.
1984
554
 
1985
- * Allow new syntax for `enum` to avoid leading `_` from reserved options.
555
+ *Maxime Réty*
1986
556
 
1987
- Before:
557
+ * Deprecate defining an `enum` with keyword arguments.
1988
558
 
1989
559
  ```ruby
1990
- class Book < ActiveRecord::Base
1991
- enum status: [ :proposed, :written ], _prefix: true, _scopes: false
1992
- enum cover: [ :hard, :soft ], _suffix: true, _default: :hard
560
+ class Function > ApplicationRecord
561
+ # BAD
562
+ enum color: [:red, :blue],
563
+ type: [:instance, :class]
564
+
565
+ # GOOD
566
+ enum :color, [:red, :blue]
567
+ enum :type, [:instance, :class]
1993
568
  end
1994
569
  ```
1995
570
 
1996
- After:
571
+ *Hartley McGuire*
1997
572
 
1998
- ```ruby
1999
- class Book < ActiveRecord::Base
2000
- enum :status, [ :proposed, :written ], prefix: true, scopes: false
2001
- enum :cover, [ :hard, :soft ], suffix: true, default: :hard
2002
- end
2003
- ```
573
+ * Add `config.active_record.validate_migration_timestamps` option for validating migration timestamps.
2004
574
 
2005
- *Ryuta Kamizono*
575
+ When set, validates that the timestamp prefix for a migration is no more than a day ahead of
576
+ the timestamp associated with the current time. This is designed to prevent migrations prefixes
577
+ from being hand-edited to future timestamps, which impacts migration generation and other
578
+ migration commands.
2006
579
 
2007
- * Add `ActiveRecord::Relation#load_async`.
580
+ *Adrianna Chang*
2008
581
 
2009
- This method schedules the query to be performed asynchronously from a thread pool.
582
+ * Properly synchronize `Mysql2Adapter#active?` and `TrilogyAdapter#active?`.
2010
583
 
2011
- If the result is accessed before a background thread had the opportunity to perform
2012
- the query, it will be performed in the foreground.
584
+ As well as `disconnect!` and `verify!`.
2013
585
 
2014
- This is useful for queries that can be performed long enough before their result will be
2015
- needed, or for controllers which need to perform several independent queries.
586
+ This generally isn't a big problem as connections must not be shared between
587
+ threads, but is required when running transactional tests or system tests
588
+ and could lead to a SEGV.
2016
589
 
2017
- ```ruby
2018
- def index
2019
- @categories = Category.some_complex_scope.load_async
2020
- @posts = Post.some_complex_scope.load_async
2021
- end
2022
- ```
590
+ *Jean Boussier*
2023
591
 
2024
- Active Record logs will also include timing info for the duration of how long
2025
- the main thread had to wait to access the result. This timing is useful to know
2026
- whether or not it's worth to load the query asynchronously.
592
+ * Support `:source_location` tag option for query log tags.
2027
593
 
2028
- ```
2029
- DEBUG -- : Category Load (62.1ms) SELECT * FROM `categories` LIMIT 50
2030
- DEBUG -- : ASYNC Post Load (64ms) (db time 126.1ms) SELECT * FROM `posts` LIMIT 100
594
+ ```ruby
595
+ config.active_record.query_log_tags << :source_location
2031
596
  ```
2032
597
 
2033
- The duration in the first set of parens is how long the main thread was blocked
2034
- waiting for the results, and the second set of parens with "db time" is how long
2035
- the entire query took to execute.
598
+ Calculating the caller location is a costly operation and should be used primarily in development
599
+ (note, there is also a `config.active_record.verbose_query_logs` that serves the same purpose)
600
+ or occasionally on production for debugging purposes.
2036
601
 
2037
- *Jean Boussier*
602
+ *fatkodima*
2038
603
 
2039
- * Implemented `ActiveRecord::Relation#excluding` method.
604
+ * Add an option to `ActiveRecord::Encryption::Encryptor` to disable compression.
2040
605
 
2041
- This method excludes the specified record (or collection of records) from
2042
- the resulting relation:
606
+ Allow compression to be disabled by setting `compress: false`
2043
607
 
2044
608
  ```ruby
2045
- Post.excluding(post)
2046
- Post.excluding(post_one, post_two)
609
+ class User
610
+ encrypts :name, encryptor: ActiveRecord::Encryption::Encryptor.new(compress: false)
611
+ end
2047
612
  ```
2048
613
 
2049
- Also works on associations:
614
+ *Donal McBreen*
2050
615
 
2051
- ```ruby
2052
- post.comments.excluding(comment)
2053
- post.comments.excluding(comment_one, comment_two)
2054
- ```
616
+ * Deprecate passing strings to `ActiveRecord::Tasks::DatabaseTasks.cache_dump_filename`.
2055
617
 
2056
- This is short-hand for `Post.where.not(id: post.id)` (for a single record)
2057
- and `Post.where.not(id: [post_one.id, post_two.id])` (for a collection).
618
+ A `ActiveRecord::DatabaseConfigurations::DatabaseConfig` object should be passed instead.
2058
619
 
2059
- *Glen Crawford*
620
+ *Rafael Mendonça França*
2060
621
 
2061
- * Skip optimised #exist? query when #include? is called on a relation
2062
- with a having clause.
622
+ * Add `row_count` field to `sql.active_record` notification.
2063
623
 
2064
- Relations that have aliased select values AND a having clause that
2065
- references an aliased select value would generate an error when
2066
- #include? was called, due to an optimisation that would generate
2067
- call #exists? on the relation instead, which effectively alters
2068
- the select values of the query (and thus removes the aliased select
2069
- values), but leaves the having clause intact. Because the having
2070
- clause is then referencing an aliased column that is no longer
2071
- present in the simplified query, an ActiveRecord::InvalidStatement
2072
- error was raised.
624
+ This field returns the amount of rows returned by the query that emitted the notification.
2073
625
 
2074
- A sample query affected by this problem:
626
+ This metric is useful in cases where one wants to detect queries with big result sets.
2075
627
 
2076
- ```ruby
2077
- Author.select('COUNT(*) as total_posts', 'authors.*')
2078
- .joins(:posts)
2079
- .group(:id)
2080
- .having('total_posts > 2')
2081
- .include?(Author.first)
2082
- ```
628
+ *Marvin Bitterlich*
2083
629
 
2084
- This change adds an addition check to the condition that skips the
2085
- simplified #exists? query, which simply checks for the presence of
2086
- a having clause.
630
+ * Consistently raise an `ArgumentError` when passing an invalid argument to a nested attributes association writer.
2087
631
 
2088
- Fixes #41417.
632
+ Previously, this would only raise on collection associations and produce a generic error on singular associations.
2089
633
 
2090
- *Michael Smart*
634
+ Now, it will raise on both collection and singular associations.
2091
635
 
2092
- * Increment postgres prepared statement counter before making a prepared statement, so if the statement is aborted
2093
- without Rails knowledge (e.g., if app gets killed during long-running query or due to Rack::Timeout), app won't end
2094
- up in perpetual crash state for being inconsistent with PostgreSQL.
636
+ *Joshua Young*
2095
637
 
2096
- *wbharding*, *Martin Tepper*
638
+ * Fix single quote escapes on default generated MySQL columns.
2097
639
 
2098
- * Add ability to apply `scoping` to `all_queries`.
640
+ MySQL 5.7.5+ supports generated columns, which can be used to create a column that is computed from an expression.
2099
641
 
2100
- Some applications may want to use the `scoping` method but previously it only
2101
- worked on certain types of queries. This change allows the `scoping` method to apply
2102
- to all queries for a model in a block.
642
+ Previously, the schema dump would output a string with double escapes for generated columns with single quotes in the default expression.
2103
643
 
2104
- ```ruby
2105
- Post.where(blog_id: post.blog_id).scoping(all_queries: true) do
2106
- post.update(title: "a post title") # adds `posts.blog_id = 1` to the query
2107
- end
2108
- ```
644
+ This would result in issues when importing the schema on a fresh instance of a MySQL database.
2109
645
 
2110
- *Eileen M. Uchitelle*
646
+ Now, the string will not be escaped and will be valid Ruby upon importing of the schema.
2111
647
 
2112
- * `ActiveRecord::Calculations.calculate` called with `:average`
2113
- (aliased as `ActiveRecord::Calculations.average`) will now use column-based
2114
- type casting. This means that floating-point number columns will now be
2115
- aggregated as `Float` and decimal columns will be aggregated as `BigDecimal`.
648
+ *Yash Kapadia*
2116
649
 
2117
- Integers are handled as a special case returning `BigDecimal` always
2118
- (this was the case before already).
650
+ * Fix Migrations with versions older than 7.1 validating options given to
651
+ `add_reference` and `t.references`.
2119
652
 
2120
- ```ruby
2121
- # With the following schema:
2122
- create_table "measurements" do |t|
2123
- t.float "temperature"
2124
- end
653
+ *Hartley McGuire*
2125
654
 
2126
- # Before:
2127
- Measurement.average(:temperature).class
2128
- # => BigDecimal
655
+ * Add `<role>_types` class method to `ActiveRecord::DelegatedType` so that the delegated types can be introspected.
2129
656
 
2130
- # After:
2131
- Measurement.average(:temperature).class
2132
- # => Float
2133
- ```
657
+ *JP Rosevear*
658
+
659
+ * Make `schema_dump`, `query_cache`, `replica` and `database_tasks` configurable via `DATABASE_URL`.
2134
660
 
2135
- Before this change, Rails just called `to_d` on average aggregates from the
2136
- database adapter. This is not the case anymore. If you relied on that kind
2137
- of magic, you now need to register your own `ActiveRecord::Type`
2138
- (see `ActiveRecord::Attributes::ClassMethods` for documentation).
661
+ This wouldn't always work previously because boolean values would be interpreted as strings.
2139
662
 
2140
- *Josua Schmid*
663
+ e.g. `DATABASE_URL=postgres://localhost/foo?schema_dump=false` now properly disable dumping the schema
664
+ cache.
2141
665
 
2142
- * PostgreSQL: introduce `ActiveRecord::ConnectionAdapters::PostgreSQLAdapter.datetime_type`.
666
+ *Mike Coutermarsh*, *Jean Boussier*
2143
667
 
2144
- This setting controls what native type Active Record should use when you call `datetime` in
2145
- a migration or schema. It takes a symbol which must correspond to one of the configured
2146
- `NATIVE_DATABASE_TYPES`. The default is `:timestamp`, meaning `t.datetime` in a migration
2147
- will create a "timestamp without time zone" column. To use "timestamp with time zone",
2148
- change this to `:timestamptz` in an initializer.
668
+ * Introduce `ActiveRecord::Transactions::ClassMethods#set_callback`.
2149
669
 
2150
- You should run `bin/rails db:migrate` to rebuild your schema.rb if you change this.
670
+ It is identical to `ActiveSupport::Callbacks::ClassMethods#set_callback`
671
+ but with support for `after_commit` and `after_rollback` callback options.
672
+
673
+ *Joshua Young*
2151
674
 
2152
- *Alex Ghiculescu*
675
+ * Make `ActiveRecord::Encryption::Encryptor` agnostic of the serialization format used for encrypted data.
2153
676
 
2154
- * PostgreSQL: handle `timestamp with time zone` columns correctly in `schema.rb`.
677
+ Previously, the encryptor instance only allowed an encrypted value serialized as a `String` to be passed to the message serializer.
2155
678
 
2156
- Previously they dumped as `t.datetime :column_name`, now they dump as `t.timestamptz :column_name`,
2157
- and are created as `timestamptz` columns when the schema is loaded.
679
+ 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`.
2158
680
 
2159
- *Alex Ghiculescu*
681
+ The default `ActiveRecord::Encryption::MessageSerializer` already ensures that only `String` objects are passed for deserialization.
2160
682
 
2161
- * Removing trailing whitespace when matching columns in
2162
- `ActiveRecord::Sanitization.disallow_raw_sql!`.
683
+ *Maxime Réty*
2163
684
 
2164
- *Gannon McGibbon*, *Adrian Hirt*
685
+ * Fix `encrypted_attribute?` to take into account context properties passed to `encrypts`.
2165
686
 
2166
- * Expose a way for applications to set a `primary_abstract_class`.
687
+ *Maxime Réty*
2167
688
 
2168
- Multiple database applications that use a primary abstract class that is not
2169
- named `ApplicationRecord` can now set a specific class to be the `primary_abstract_class`.
689
+ * The object returned by `explain` now responds to `pluck`, `first`,
690
+ `last`, `average`, `count`, `maximum`, `minimum`, and `sum`. Those
691
+ new methods run `EXPLAIN` on the corresponding queries:
2170
692
 
2171
693
  ```ruby
2172
- class PrimaryApplicationRecord
2173
- self.primary_abstract_class
2174
- end
694
+ User.all.explain.count
695
+ # EXPLAIN SELECT COUNT(*) FROM `users`
696
+ # ...
697
+
698
+ User.all.explain.maximum(:id)
699
+ # EXPLAIN SELECT MAX(`users`.`id`) FROM `users`
700
+ # ...
2175
701
  ```
2176
702
 
2177
- When an application boots it automatically connects to the primary or first database in the
2178
- database configuration file. In a multiple database application that then call `connects_to`
2179
- needs to know that the default connection is the same as the `ApplicationRecord` connection.
2180
- However, some applications have a differently named `ApplicationRecord`. This prevents Active
2181
- Record from opening duplicate connections to the same database.
703
+ *Petrik de Heus*
2182
704
 
2183
- *Eileen M. Uchitelle*, *John Crepezzi*
705
+ * Fixes an issue where `validates_associated` `:on` option wasn't respected
706
+ when validating associated records.
2184
707
 
2185
- * Support hash config for `structure_dump_flags` and `structure_load_flags` flags.
2186
- Now that Active Record supports multiple databases configuration,
2187
- we need a way to pass specific flags for dump/load databases since
2188
- the options are not the same for different adapters.
2189
- We can use in the original way:
708
+ *Austen Madden*, *Alex Ghiculescu*, *Rafał Brize*
2190
709
 
2191
- ```ruby
2192
- ActiveRecord::Tasks::DatabaseTasks.structure_dump_flags = ['--no-defaults', '--skip-add-drop-table']
2193
- # or
2194
- ActiveRecord::Tasks::DatabaseTasks.structure_dump_flags = '--no-defaults --skip-add-drop-table'
2195
- ```
710
+ * Allow overriding SQLite defaults from `database.yml`.
2196
711
 
2197
- And also use it passing a hash, with one or more keys, where the key
2198
- is the adapter
712
+ Any PRAGMA configuration set under the `pragmas` key in the configuration
713
+ file takes precedence over Rails' defaults, and additional PRAGMAs can be
714
+ set as well.
2199
715
 
2200
- ```ruby
2201
- ActiveRecord::Tasks::DatabaseTasks.structure_dump_flags = {
2202
- mysql2: ['--no-defaults', '--skip-add-drop-table'],
2203
- postgres: '--no-tablespaces'
2204
- }
716
+ ```yaml
717
+ database: storage/development.sqlite3
718
+ timeout: 5000
719
+ pragmas:
720
+ journal_mode: off
721
+ temp_store: memory
2205
722
  ```
2206
723
 
2207
- *Gustavo Gonzalez*
724
+ *Stephen Margheim*
2208
725
 
2209
- * Connection specification now passes the "url" key as a configuration for the
2210
- adapter if the "url" protocol is "jdbc", "http", or "https". Previously only
2211
- urls with the "jdbc" prefix were passed to the Active Record Adapter, others
2212
- are assumed to be adapter specification urls.
726
+ * Remove warning message when running SQLite in production, but leave it unconfigured.
2213
727
 
2214
- Fixes #41137.
728
+ There are valid use cases for running SQLite in production. However, it must be done
729
+ with care, so instead of a warning most users won't see anyway, it's preferable to
730
+ leave the configuration commented out to force them to think about having the database
731
+ on a persistent volume etc.
2215
732
 
2216
- *Jonathan Bracy*
733
+ *Jacopo Beschi*, *Jean Boussier*
2217
734
 
2218
- * Allow to opt-out of `strict_loading` mode on a per-record base.
735
+ * Add support for generated columns to the SQLite3 adapter.
2219
736
 
2220
- This is useful when strict loading is enabled application wide or on a
2221
- model level.
737
+ Generated columns (both stored and dynamic) are supported since version 3.31.0 of SQLite.
738
+ This adds support for those to the SQLite3 adapter.
2222
739
 
2223
740
  ```ruby
2224
- class User < ApplicationRecord
2225
- has_many :bookmarks
2226
- has_many :articles, strict_loading: true
741
+ create_table :users do |t|
742
+ t.string :name
743
+ t.virtual :name_upper, type: :string, as: 'UPPER(name)'
744
+ t.virtual :name_lower, type: :string, as: 'LOWER(name)', stored: true
2227
745
  end
746
+ ```
2228
747
 
2229
- user = User.first
2230
- user.articles # => ActiveRecord::StrictLoadingViolationError
2231
- user.bookmarks # => #<ActiveRecord::Associations::CollectionProxy>
748
+ *Stephen Margheim*
2232
749
 
2233
- user.strict_loading!(true) # => true
2234
- user.bookmarks # => ActiveRecord::StrictLoadingViolationError
750
+ * TrilogyAdapter: ignore `host` if `socket` parameter is set.
2235
751
 
2236
- user.strict_loading!(false) # => false
2237
- user.bookmarks # => #<ActiveRecord::Associations::CollectionProxy>
2238
- user.articles.strict_loading!(false) # => #<ActiveRecord::Associations::CollectionProxy>
752
+ This allows to configure a connection on a UNIX socket via `DATABASE_URL`:
753
+
754
+ ```
755
+ DATABASE_URL=trilogy://does-not-matter/my_db_production?socket=/var/run/mysql.sock
2239
756
  ```
2240
757
 
2241
- *Ayrton De Craene*
758
+ *Jean Boussier*
2242
759
 
2243
- * Add `FinderMethods#sole` and `#find_sole_by` to find and assert the
2244
- presence of exactly one record.
760
+ * Make `assert_queries_count`, `assert_no_queries`, `assert_queries_match`, and
761
+ `assert_no_queries_match` assertions public.
2245
762
 
2246
- Used when you need a single row, but also want to assert that there aren't
2247
- multiple rows matching the condition; especially for when database
2248
- constraints aren't enough or are impractical.
763
+ To assert the expected number of queries are made, Rails internally uses `assert_queries_count` and
764
+ `assert_no_queries`. To assert that specific SQL queries are made, `assert_queries_match` and
765
+ `assert_no_queries_match` are used. These assertions can now be used in applications as well.
2249
766
 
2250
767
  ```ruby
2251
- Product.where(["price = %?", price]).sole
2252
- # => ActiveRecord::RecordNotFound (if no Product with given price)
2253
- # => #<Product ...> (if one Product with given price)
2254
- # => ActiveRecord::SoleRecordExceeded (if more than one Product with given price)
768
+ class ArticleTest < ActiveSupport::TestCase
769
+ test "queries are made" do
770
+ assert_queries_count(1) { Article.first }
771
+ end
2255
772
 
2256
- user.api_keys.find_sole_by(key: key)
2257
- # as above
773
+ test "creates a foreign key" do
774
+ assert_queries_match(/ADD FOREIGN KEY/i, include_schema: true) do
775
+ @connection.add_foreign_key(:comments, :posts)
776
+ end
777
+ end
778
+ end
2258
779
  ```
2259
780
 
2260
- *Asherah Connor*
781
+ *Petrik de Heus*, *fatkodima*
2261
782
 
2262
- * Makes `ActiveRecord::AttributeMethods::Query` respect the getter overrides defined in the model.
783
+ * Fix `has_secure_token` calls the setter method on initialize.
2263
784
 
2264
- Before:
2265
-
2266
- ```ruby
2267
- class User
2268
- def admin
2269
- false # Overriding the getter to always return false
2270
- end
2271
- end
785
+ *Abeid Ahmed*
2272
786
 
2273
- user = User.first
2274
- user.update(admin: true)
787
+ * When using a `DATABASE_URL`, allow for a configuration to map the protocol in the URL to a specific database
788
+ adapter. This allows decoupling the adapter the application chooses to use from the database connection details
789
+ set in the deployment environment.
2275
790
 
2276
- user.admin # false (as expected, due to the getter overwrite)
2277
- user.admin? # true (not expected, returned the DB column value)
791
+ ```ruby
792
+ # ENV['DATABASE_URL'] = "mysql://localhost/example_database"
793
+ config.active_record.protocol_adapters.mysql = "trilogy"
794
+ # will connect to MySQL using the trilogy adapter
2278
795
  ```
2279
796
 
2280
- After this commit, `user.admin?` above returns false, as expected.
797
+ *Jean Boussier*, *Kevin McPhillips*
2281
798
 
2282
- Fixes #40771.
799
+ * In cases where MySQL returns `warning_count` greater than zero, but returns no warnings when
800
+ the `SHOW WARNINGS` query is executed, `ActiveRecord.db_warnings_action` proc will still be
801
+ called with a generic warning message rather than silently ignoring the warning(s).
2283
802
 
2284
- *Felipe*
803
+ *Kevin McPhillips*
2285
804
 
2286
- * Allow delegated_type to be specified primary_key and foreign_key.
805
+ * `DatabaseConfigurations#configs_for` accepts a symbol in the `name` parameter.
2287
806
 
2288
- Since delegated_type assumes that the foreign_key ends with `_id`,
2289
- `singular_id` defined by it does not work when the foreign_key does
2290
- not end with `id`. This change fixes it by taking into account
2291
- `primary_key` and `foreign_key` in the options.
807
+ *Andrew Novoselac*
2292
808
 
2293
- *Ryota Egusa*
809
+ * Fix `where(field: values)` queries when `field` is a serialized attribute
810
+ (for example, when `field` uses `ActiveRecord::Base.serialize` or is a JSON
811
+ column).
2294
812
 
2295
- * Expose an `invert_where` method that will invert all scope conditions.
813
+ *João Alves*
2296
814
 
2297
- ```ruby
2298
- class User
2299
- scope :active, -> { where(accepted: true, locked: false) }
2300
- end
815
+ * Make the output of `ActiveRecord::Core#inspect` configurable.
2301
816
 
2302
- User.active
2303
- # ... WHERE `accepted` = 1 AND `locked` = 0
817
+ By default, calling `inspect` on a record will yield a formatted string including just the `id`.
2304
818
 
2305
- User.active.invert_where
2306
- # ... WHERE NOT (`accepted` = 1 AND `locked` = 0)
819
+ ```ruby
820
+ Post.first.inspect #=> "#<Post id: 1>"
2307
821
  ```
2308
822
 
2309
- *Kevin Deisz*
823
+ The attributes to be included in the output of `inspect` can be configured with
824
+ `ActiveRecord::Core#attributes_for_inspect`.
2310
825
 
2311
- * Restore possibility of passing `false` to :polymorphic option of `belongs_to`.
826
+ ```ruby
827
+ Post.attributes_for_inspect = [:id, :title]
828
+ Post.first.inspect #=> "#<Post id: 1, title: "Hello, World!">"
829
+ ```
2312
830
 
2313
- Previously, passing `false` would trigger the option validation logic
2314
- to throw an error saying :polymorphic would not be a valid option.
831
+ With `attributes_for_inspect` set to `:all`, `inspect` will list all the record's attributes.
2315
832
 
2316
- *glaszig*
833
+ ```ruby
834
+ Post.attributes_for_inspect = :all
835
+ Post.first.inspect #=> "#<Post id: 1, title: "Hello, World!", published_at: "2023-10-23 14:28:11 +0000">"
836
+ ```
2317
837
 
2318
- * Remove deprecated `database` kwarg from `connected_to`.
838
+ In `development` and `test` mode, `attributes_for_inspect` will be set to `:all` by default.
2319
839
 
2320
- *Eileen M. Uchitelle*, *John Crepezzi*
840
+ You can also call `full_inspect` to get an inspection with all the attributes.
2321
841
 
2322
- * Allow adding nonnamed expression indexes to be revertible.
842
+ The attributes in `attribute_for_inspect` will also be used for `pretty_print`.
2323
843
 
2324
- Previously, the following code would raise an error, when executed while rolling back,
2325
- and the index name should be specified explicitly. Now, the index name is inferred
2326
- automatically.
844
+ *Andrew Novoselac*
2327
845
 
2328
- ```ruby
2329
- add_index(:items, "to_tsvector('english', description)")
2330
- ```
846
+ * Don't mark attributes as changed when reassigned to `Float::INFINITY` or
847
+ `-Float::INFINITY`.
2331
848
 
2332
- Fixes #40732.
849
+ *Maicol Bentancor*
2333
850
 
2334
- *fatkodima*
851
+ * Support the `RETURNING` clause for MariaDB.
2335
852
 
2336
- * Only warn about negative enums if a positive form that would cause conflicts exists.
853
+ *fatkodima*, *Nikolay Kondratyev*
2337
854
 
2338
- Fixes #39065.
855
+ * The SQLite3 adapter now implements the `supports_deferrable_constraints?` contract.
2339
856
 
2340
- *Alex Ghiculescu*
857
+ Allows foreign keys to be deferred by adding the `:deferrable` key to the `foreign_key` options.
2341
858
 
2342
- * Add option to run `default_scope` on all queries.
859
+ ```ruby
860
+ add_reference :person, :alias, foreign_key: { deferrable: :deferred }
861
+ add_reference :alias, :person, foreign_key: { deferrable: :deferred }
862
+ ```
2343
863
 
2344
- Previously, a `default_scope` would only run on select or insert queries. In some cases, like non-Rails tenant sharding solutions, it may be desirable to run `default_scope` on all queries in order to ensure queries are including a foreign key for the shard (i.e. `blog_id`).
864
+ *Stephen Margheim*
2345
865
 
2346
- Now applications can add an option to run on all queries including select, insert, delete, and update by adding an `all_queries` option to the default scope definition.
866
+ * Add the `set_constraints` helper to PostgreSQL connections.
2347
867
 
2348
868
  ```ruby
2349
- class Article < ApplicationRecord
2350
- default_scope -> { where(blog_id: Current.blog.id) }, all_queries: true
869
+ Post.create!(user_id: -1) # => ActiveRecord::InvalidForeignKey
870
+
871
+ Post.transaction do
872
+ Post.connection.set_constraints(:deferred)
873
+ p = Post.create!(user_id: -1)
874
+ u = User.create!
875
+ p.user = u
876
+ p.save!
2351
877
  end
2352
878
  ```
2353
879
 
2354
- *Eileen M. Uchitelle*
880
+ *Cody Cutrer*
2355
881
 
2356
- * Add `where.associated` to check for the presence of an association.
882
+ * Include `ActiveModel::API` in `ActiveRecord::Base`.
2357
883
 
2358
- ```ruby
2359
- # Before:
2360
- account.users.joins(:contact).where.not(contact_id: nil)
884
+ *Sean Doyle*
2361
885
 
2362
- # After:
2363
- account.users.where.associated(:contact)
2364
- ```
886
+ * Ensure `#signed_id` outputs `url_safe` strings.
887
+
888
+ *Jason Meller*
2365
889
 
2366
- Also mirrors `where.missing`.
890
+ * Add `nulls_last` and working `desc.nulls_first` for MySQL.
2367
891
 
2368
- *Kasper Timm Hansen*
892
+ *Tristan Fellows*
2369
893
 
2370
- * Allow constructors (`build_association` and `create_association`) on
2371
- `has_one :through` associations.
894
+ * Allow for more complex hash arguments for `order` which mimics `where` in `ActiveRecord::Relation`.
2372
895
 
2373
- *Santiago Perez Perret*
896
+ ```ruby
897
+ Topic.includes(:posts).order(posts: { created_at: :desc })
898
+ ```
2374
899
 
900
+ *Myles Boone*
2375
901
 
2376
- Please check [6-1-stable](https://github.com/rails/rails/blob/6-1-stable/activerecord/CHANGELOG.md) for previous changes.
902
+ Please check [7-1-stable](https://github.com/rails/rails/blob/7-1-stable/activerecord/CHANGELOG.md) for previous changes.