activerecord 6.1.7 → 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 (332) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +520 -1385
  3. data/MIT-LICENSE +1 -1
  4. data/README.rdoc +31 -31
  5. data/examples/performance.rb +2 -2
  6. data/lib/active_record/aggregations.rb +17 -14
  7. data/lib/active_record/association_relation.rb +2 -12
  8. data/lib/active_record/associations/alias_tracker.rb +25 -19
  9. data/lib/active_record/associations/association.rb +60 -21
  10. data/lib/active_record/associations/association_scope.rb +17 -12
  11. data/lib/active_record/associations/belongs_to_association.rb +37 -11
  12. data/lib/active_record/associations/belongs_to_polymorphic_association.rb +13 -4
  13. data/lib/active_record/associations/builder/association.rb +11 -5
  14. data/lib/active_record/associations/builder/belongs_to.rb +41 -14
  15. data/lib/active_record/associations/builder/collection_association.rb +10 -3
  16. data/lib/active_record/associations/builder/has_and_belongs_to_many.rb +3 -7
  17. data/lib/active_record/associations/builder/has_many.rb +4 -4
  18. data/lib/active_record/associations/builder/has_one.rb +4 -4
  19. data/lib/active_record/associations/builder/singular_association.rb +6 -2
  20. data/lib/active_record/associations/collection_association.rb +46 -36
  21. data/lib/active_record/associations/collection_proxy.rb +44 -16
  22. data/lib/active_record/associations/disable_joins_association_scope.rb +59 -0
  23. data/lib/active_record/associations/errors.rb +265 -0
  24. data/lib/active_record/associations/foreign_association.rb +10 -3
  25. data/lib/active_record/associations/has_many_association.rb +29 -19
  26. data/lib/active_record/associations/has_many_through_association.rb +12 -7
  27. data/lib/active_record/associations/has_one_association.rb +20 -10
  28. data/lib/active_record/associations/has_one_through_association.rb +1 -1
  29. data/lib/active_record/associations/join_dependency/join_association.rb +27 -25
  30. data/lib/active_record/associations/join_dependency.rb +23 -15
  31. data/lib/active_record/associations/nested_error.rb +47 -0
  32. data/lib/active_record/associations/preloader/association.rb +212 -53
  33. data/lib/active_record/associations/preloader/batch.rb +48 -0
  34. data/lib/active_record/associations/preloader/branch.rb +153 -0
  35. data/lib/active_record/associations/preloader/through_association.rb +50 -16
  36. data/lib/active_record/associations/preloader.rb +50 -121
  37. data/lib/active_record/associations/singular_association.rb +15 -3
  38. data/lib/active_record/associations/through_association.rb +25 -14
  39. data/lib/active_record/associations.rb +404 -509
  40. data/lib/active_record/asynchronous_queries_tracker.rb +60 -0
  41. data/lib/active_record/attribute_assignment.rb +2 -14
  42. data/lib/active_record/attribute_methods/before_type_cast.rb +24 -2
  43. data/lib/active_record/attribute_methods/composite_primary_key.rb +84 -0
  44. data/lib/active_record/attribute_methods/dirty.rb +73 -22
  45. data/lib/active_record/attribute_methods/primary_key.rb +47 -27
  46. data/lib/active_record/attribute_methods/query.rb +31 -19
  47. data/lib/active_record/attribute_methods/read.rb +14 -11
  48. data/lib/active_record/attribute_methods/serialization.rb +174 -37
  49. data/lib/active_record/attribute_methods/time_zone_conversion.rb +11 -9
  50. data/lib/active_record/attribute_methods/write.rb +12 -15
  51. data/lib/active_record/attribute_methods.rb +164 -52
  52. data/lib/active_record/attributes.rb +51 -49
  53. data/lib/active_record/autosave_association.rb +74 -57
  54. data/lib/active_record/base.rb +27 -5
  55. data/lib/active_record/callbacks.rb +18 -34
  56. data/lib/active_record/coders/column_serializer.rb +61 -0
  57. data/lib/active_record/coders/json.rb +1 -1
  58. data/lib/active_record/coders/yaml_column.rb +70 -46
  59. data/lib/active_record/connection_adapters/abstract/connection_handler.rb +284 -0
  60. data/lib/active_record/connection_adapters/abstract/connection_pool/queue.rb +211 -0
  61. data/lib/active_record/connection_adapters/abstract/connection_pool/reaper.rb +79 -0
  62. data/lib/active_record/connection_adapters/abstract/connection_pool.rb +327 -612
  63. data/lib/active_record/connection_adapters/abstract/database_limits.rb +5 -17
  64. data/lib/active_record/connection_adapters/abstract/database_statements.rb +199 -60
  65. data/lib/active_record/connection_adapters/abstract/query_cache.rb +201 -64
  66. data/lib/active_record/connection_adapters/abstract/quoting.rb +119 -131
  67. data/lib/active_record/connection_adapters/abstract/savepoints.rb +4 -3
  68. data/lib/active_record/connection_adapters/abstract/schema_creation.rb +21 -20
  69. data/lib/active_record/connection_adapters/abstract/schema_definitions.rb +186 -31
  70. data/lib/active_record/connection_adapters/abstract/schema_dumper.rb +14 -1
  71. data/lib/active_record/connection_adapters/abstract/schema_statements.rb +377 -142
  72. data/lib/active_record/connection_adapters/abstract/transaction.rb +361 -76
  73. data/lib/active_record/connection_adapters/abstract_adapter.rb +624 -163
  74. data/lib/active_record/connection_adapters/abstract_mysql_adapter.rb +345 -166
  75. data/lib/active_record/connection_adapters/column.rb +13 -0
  76. data/lib/active_record/connection_adapters/mysql/column.rb +1 -0
  77. data/lib/active_record/connection_adapters/mysql/database_statements.rb +29 -130
  78. data/lib/active_record/connection_adapters/mysql/quoting.rb +81 -55
  79. data/lib/active_record/connection_adapters/mysql/schema_creation.rb +9 -0
  80. data/lib/active_record/connection_adapters/mysql/schema_definitions.rb +10 -1
  81. data/lib/active_record/connection_adapters/mysql/schema_dumper.rb +8 -2
  82. data/lib/active_record/connection_adapters/mysql/schema_statements.rb +45 -14
  83. data/lib/active_record/connection_adapters/mysql2/database_statements.rb +152 -0
  84. data/lib/active_record/connection_adapters/mysql2_adapter.rb +107 -68
  85. data/lib/active_record/connection_adapters/pool_config.rb +26 -16
  86. data/lib/active_record/connection_adapters/pool_manager.rb +19 -9
  87. data/lib/active_record/connection_adapters/postgresql/column.rb +30 -1
  88. data/lib/active_record/connection_adapters/postgresql/database_statements.rb +114 -54
  89. data/lib/active_record/connection_adapters/postgresql/oid/array.rb +1 -1
  90. data/lib/active_record/connection_adapters/postgresql/oid/cidr.rb +6 -0
  91. data/lib/active_record/connection_adapters/postgresql/oid/date.rb +8 -0
  92. data/lib/active_record/connection_adapters/postgresql/oid/date_time.rb +5 -0
  93. data/lib/active_record/connection_adapters/postgresql/oid/hstore.rb +53 -14
  94. data/lib/active_record/connection_adapters/postgresql/oid/interval.rb +1 -1
  95. data/lib/active_record/connection_adapters/postgresql/oid/money.rb +3 -2
  96. data/lib/active_record/connection_adapters/postgresql/oid/range.rb +12 -3
  97. data/lib/active_record/connection_adapters/postgresql/oid/timestamp.rb +15 -0
  98. data/lib/active_record/connection_adapters/postgresql/oid/timestamp_with_time_zone.rb +30 -0
  99. data/lib/active_record/connection_adapters/postgresql/oid/type_map_initializer.rb +18 -6
  100. data/lib/active_record/connection_adapters/postgresql/oid/uuid.rb +14 -4
  101. data/lib/active_record/connection_adapters/postgresql/oid.rb +2 -0
  102. data/lib/active_record/connection_adapters/postgresql/quoting.rb +137 -104
  103. data/lib/active_record/connection_adapters/postgresql/referential_integrity.rb +28 -0
  104. data/lib/active_record/connection_adapters/postgresql/schema_creation.rb +92 -2
  105. data/lib/active_record/connection_adapters/postgresql/schema_definitions.rb +173 -3
  106. data/lib/active_record/connection_adapters/postgresql/schema_dumper.rb +78 -0
  107. data/lib/active_record/connection_adapters/postgresql/schema_statements.rb +401 -77
  108. data/lib/active_record/connection_adapters/postgresql/utils.rb +9 -10
  109. data/lib/active_record/connection_adapters/postgresql_adapter.rb +518 -251
  110. data/lib/active_record/connection_adapters/schema_cache.rb +326 -102
  111. data/lib/active_record/connection_adapters/sqlite3/column.rb +62 -0
  112. data/lib/active_record/connection_adapters/sqlite3/database_statements.rb +78 -55
  113. data/lib/active_record/connection_adapters/sqlite3/quoting.rb +68 -54
  114. data/lib/active_record/connection_adapters/sqlite3/schema_creation.rb +22 -0
  115. data/lib/active_record/connection_adapters/sqlite3/schema_definitions.rb +20 -0
  116. data/lib/active_record/connection_adapters/sqlite3/schema_dumper.rb +16 -0
  117. data/lib/active_record/connection_adapters/sqlite3/schema_statements.rb +66 -22
  118. data/lib/active_record/connection_adapters/sqlite3_adapter.rb +372 -130
  119. data/lib/active_record/connection_adapters/statement_pool.rb +7 -0
  120. data/lib/active_record/connection_adapters/trilogy/database_statements.rb +99 -0
  121. data/lib/active_record/connection_adapters/trilogy_adapter.rb +229 -0
  122. data/lib/active_record/connection_adapters.rb +130 -6
  123. data/lib/active_record/connection_handling.rb +132 -146
  124. data/lib/active_record/core.rb +276 -251
  125. data/lib/active_record/counter_cache.rb +68 -34
  126. data/lib/active_record/database_configurations/connection_url_resolver.rb +9 -3
  127. data/lib/active_record/database_configurations/database_config.rb +34 -10
  128. data/lib/active_record/database_configurations/hash_config.rb +107 -31
  129. data/lib/active_record/database_configurations/url_config.rb +38 -13
  130. data/lib/active_record/database_configurations.rb +96 -60
  131. data/lib/active_record/delegated_type.rb +90 -20
  132. data/lib/active_record/deprecator.rb +7 -0
  133. data/lib/active_record/destroy_association_async_job.rb +4 -2
  134. data/lib/active_record/disable_joins_association_relation.rb +39 -0
  135. data/lib/active_record/dynamic_matchers.rb +3 -3
  136. data/lib/active_record/encryption/auto_filtered_parameters.rb +66 -0
  137. data/lib/active_record/encryption/cipher/aes256_gcm.rb +101 -0
  138. data/lib/active_record/encryption/cipher.rb +53 -0
  139. data/lib/active_record/encryption/config.rb +68 -0
  140. data/lib/active_record/encryption/configurable.rb +60 -0
  141. data/lib/active_record/encryption/context.rb +42 -0
  142. data/lib/active_record/encryption/contexts.rb +76 -0
  143. data/lib/active_record/encryption/derived_secret_key_provider.rb +18 -0
  144. data/lib/active_record/encryption/deterministic_key_provider.rb +14 -0
  145. data/lib/active_record/encryption/encryptable_record.rb +230 -0
  146. data/lib/active_record/encryption/encrypted_attribute_type.rb +175 -0
  147. data/lib/active_record/encryption/encrypted_fixtures.rb +38 -0
  148. data/lib/active_record/encryption/encrypting_only_encryptor.rb +12 -0
  149. data/lib/active_record/encryption/encryptor.rb +170 -0
  150. data/lib/active_record/encryption/envelope_encryption_key_provider.rb +55 -0
  151. data/lib/active_record/encryption/errors.rb +15 -0
  152. data/lib/active_record/encryption/extended_deterministic_queries.rb +157 -0
  153. data/lib/active_record/encryption/extended_deterministic_uniqueness_validator.rb +28 -0
  154. data/lib/active_record/encryption/key.rb +28 -0
  155. data/lib/active_record/encryption/key_generator.rb +53 -0
  156. data/lib/active_record/encryption/key_provider.rb +46 -0
  157. data/lib/active_record/encryption/message.rb +33 -0
  158. data/lib/active_record/encryption/message_pack_message_serializer.rb +76 -0
  159. data/lib/active_record/encryption/message_serializer.rb +96 -0
  160. data/lib/active_record/encryption/null_encryptor.rb +25 -0
  161. data/lib/active_record/encryption/properties.rb +76 -0
  162. data/lib/active_record/encryption/read_only_null_encryptor.rb +28 -0
  163. data/lib/active_record/encryption/scheme.rb +100 -0
  164. data/lib/active_record/encryption.rb +56 -0
  165. data/lib/active_record/enum.rb +163 -63
  166. data/lib/active_record/errors.rb +210 -27
  167. data/lib/active_record/explain.rb +21 -12
  168. data/lib/active_record/explain_registry.rb +11 -6
  169. data/lib/active_record/explain_subscriber.rb +1 -1
  170. data/lib/active_record/fixture_set/file.rb +15 -1
  171. data/lib/active_record/fixture_set/model_metadata.rb +14 -4
  172. data/lib/active_record/fixture_set/render_context.rb +2 -0
  173. data/lib/active_record/fixture_set/table_row.rb +70 -14
  174. data/lib/active_record/fixture_set/table_rows.rb +4 -4
  175. data/lib/active_record/fixtures.rb +179 -112
  176. data/lib/active_record/future_result.rb +178 -0
  177. data/lib/active_record/gem_version.rb +4 -4
  178. data/lib/active_record/inheritance.rb +85 -31
  179. data/lib/active_record/insert_all.rb +148 -32
  180. data/lib/active_record/integration.rb +14 -10
  181. data/lib/active_record/internal_metadata.rb +123 -23
  182. data/lib/active_record/legacy_yaml_adapter.rb +2 -39
  183. data/lib/active_record/locking/optimistic.rb +43 -27
  184. data/lib/active_record/locking/pessimistic.rb +15 -6
  185. data/lib/active_record/log_subscriber.rb +41 -29
  186. data/lib/active_record/marshalling.rb +56 -0
  187. data/lib/active_record/message_pack.rb +124 -0
  188. data/lib/active_record/middleware/database_selector/resolver.rb +10 -10
  189. data/lib/active_record/middleware/database_selector.rb +23 -13
  190. data/lib/active_record/middleware/shard_selector.rb +62 -0
  191. data/lib/active_record/migration/command_recorder.rb +113 -16
  192. data/lib/active_record/migration/compatibility.rb +235 -46
  193. data/lib/active_record/migration/default_strategy.rb +22 -0
  194. data/lib/active_record/migration/execution_strategy.rb +19 -0
  195. data/lib/active_record/migration/join_table.rb +1 -1
  196. data/lib/active_record/migration/pending_migration_connection.rb +21 -0
  197. data/lib/active_record/migration.rb +374 -177
  198. data/lib/active_record/model_schema.rb +143 -159
  199. data/lib/active_record/nested_attributes.rb +48 -21
  200. data/lib/active_record/no_touching.rb +3 -3
  201. data/lib/active_record/normalization.rb +163 -0
  202. data/lib/active_record/persistence.rb +282 -283
  203. data/lib/active_record/promise.rb +84 -0
  204. data/lib/active_record/query_cache.rb +19 -25
  205. data/lib/active_record/query_logs.rb +189 -0
  206. data/lib/active_record/query_logs_formatter.rb +41 -0
  207. data/lib/active_record/querying.rb +44 -9
  208. data/lib/active_record/railtie.rb +234 -71
  209. data/lib/active_record/railties/controller_runtime.rb +25 -11
  210. data/lib/active_record/railties/databases.rake +189 -256
  211. data/lib/active_record/railties/job_runtime.rb +23 -0
  212. data/lib/active_record/readonly_attributes.rb +41 -3
  213. data/lib/active_record/reflection.rb +325 -103
  214. data/lib/active_record/relation/batches/batch_enumerator.rb +38 -9
  215. data/lib/active_record/relation/batches.rb +198 -63
  216. data/lib/active_record/relation/calculations.rb +300 -111
  217. data/lib/active_record/relation/delegation.rb +33 -22
  218. data/lib/active_record/relation/finder_methods.rb +123 -52
  219. data/lib/active_record/relation/merger.rb +26 -19
  220. data/lib/active_record/relation/predicate_builder/array_handler.rb +2 -2
  221. data/lib/active_record/relation/predicate_builder/association_query_value.rb +38 -4
  222. data/lib/active_record/relation/predicate_builder/polymorphic_array_value.rb +10 -7
  223. data/lib/active_record/relation/predicate_builder/relation_handler.rb +5 -1
  224. data/lib/active_record/relation/predicate_builder.rb +29 -22
  225. data/lib/active_record/relation/query_attribute.rb +30 -12
  226. data/lib/active_record/relation/query_methods.rb +842 -150
  227. data/lib/active_record/relation/record_fetch_warning.rb +10 -9
  228. data/lib/active_record/relation/spawn_methods.rb +7 -6
  229. data/lib/active_record/relation/where_clause.rb +15 -36
  230. data/lib/active_record/relation.rb +736 -145
  231. data/lib/active_record/result.rb +67 -54
  232. data/lib/active_record/runtime_registry.rb +71 -13
  233. data/lib/active_record/sanitization.rb +84 -34
  234. data/lib/active_record/schema.rb +39 -23
  235. data/lib/active_record/schema_dumper.rb +90 -31
  236. data/lib/active_record/schema_migration.rb +74 -23
  237. data/lib/active_record/scoping/default.rb +72 -15
  238. data/lib/active_record/scoping/named.rb +5 -13
  239. data/lib/active_record/scoping.rb +65 -34
  240. data/lib/active_record/secure_password.rb +60 -0
  241. data/lib/active_record/secure_token.rb +21 -3
  242. data/lib/active_record/serialization.rb +6 -1
  243. data/lib/active_record/signed_id.rb +30 -9
  244. data/lib/active_record/statement_cache.rb +7 -7
  245. data/lib/active_record/store.rb +10 -10
  246. data/lib/active_record/suppressor.rb +13 -15
  247. data/lib/active_record/table_metadata.rb +7 -3
  248. data/lib/active_record/tasks/database_tasks.rb +277 -149
  249. data/lib/active_record/tasks/mysql_database_tasks.rb +16 -7
  250. data/lib/active_record/tasks/postgresql_database_tasks.rb +35 -26
  251. data/lib/active_record/tasks/sqlite_database_tasks.rb +16 -7
  252. data/lib/active_record/test_databases.rb +1 -1
  253. data/lib/active_record/test_fixtures.rb +173 -155
  254. data/lib/active_record/testing/query_assertions.rb +121 -0
  255. data/lib/active_record/timestamp.rb +32 -19
  256. data/lib/active_record/token_for.rb +123 -0
  257. data/lib/active_record/touch_later.rb +12 -7
  258. data/lib/active_record/transaction.rb +132 -0
  259. data/lib/active_record/transactions.rb +118 -41
  260. data/lib/active_record/translation.rb +3 -5
  261. data/lib/active_record/type/adapter_specific_registry.rb +32 -14
  262. data/lib/active_record/type/hash_lookup_type_map.rb +34 -1
  263. data/lib/active_record/type/internal/timezone.rb +7 -2
  264. data/lib/active_record/type/serialized.rb +9 -7
  265. data/lib/active_record/type/time.rb +4 -0
  266. data/lib/active_record/type/type_map.rb +17 -20
  267. data/lib/active_record/type.rb +1 -2
  268. data/lib/active_record/type_caster/connection.rb +4 -4
  269. data/lib/active_record/validations/absence.rb +1 -1
  270. data/lib/active_record/validations/associated.rb +13 -7
  271. data/lib/active_record/validations/numericality.rb +5 -4
  272. data/lib/active_record/validations/presence.rb +5 -28
  273. data/lib/active_record/validations/uniqueness.rb +64 -15
  274. data/lib/active_record/validations.rb +12 -5
  275. data/lib/active_record/version.rb +1 -1
  276. data/lib/active_record.rb +444 -32
  277. data/lib/arel/alias_predication.rb +1 -1
  278. data/lib/arel/attributes/attribute.rb +0 -8
  279. data/lib/arel/collectors/bind.rb +2 -0
  280. data/lib/arel/collectors/composite.rb +7 -0
  281. data/lib/arel/collectors/sql_string.rb +1 -1
  282. data/lib/arel/collectors/substitute_binds.rb +1 -1
  283. data/lib/arel/crud.rb +28 -22
  284. data/lib/arel/delete_manager.rb +18 -4
  285. data/lib/arel/errors.rb +10 -0
  286. data/lib/arel/factory_methods.rb +4 -0
  287. data/lib/arel/filter_predications.rb +9 -0
  288. data/lib/arel/insert_manager.rb +2 -3
  289. data/lib/arel/nodes/binary.rb +6 -7
  290. data/lib/arel/nodes/bound_sql_literal.rb +65 -0
  291. data/lib/arel/nodes/casted.rb +1 -1
  292. data/lib/arel/nodes/cte.rb +36 -0
  293. data/lib/arel/nodes/delete_statement.rb +12 -13
  294. data/lib/arel/nodes/filter.rb +10 -0
  295. data/lib/arel/nodes/fragments.rb +35 -0
  296. data/lib/arel/nodes/function.rb +1 -0
  297. data/lib/arel/nodes/homogeneous_in.rb +1 -9
  298. data/lib/arel/nodes/insert_statement.rb +2 -2
  299. data/lib/arel/nodes/leading_join.rb +8 -0
  300. data/lib/arel/nodes/{and.rb → nary.rb} +9 -2
  301. data/lib/arel/nodes/node.rb +115 -5
  302. data/lib/arel/nodes/select_core.rb +2 -2
  303. data/lib/arel/nodes/select_statement.rb +2 -2
  304. data/lib/arel/nodes/sql_literal.rb +13 -0
  305. data/lib/arel/nodes/table_alias.rb +4 -0
  306. data/lib/arel/nodes/update_statement.rb +8 -3
  307. data/lib/arel/nodes.rb +7 -2
  308. data/lib/arel/predications.rb +14 -4
  309. data/lib/arel/select_manager.rb +11 -5
  310. data/lib/arel/table.rb +9 -6
  311. data/lib/arel/tree_manager.rb +8 -15
  312. data/lib/arel/update_manager.rb +20 -5
  313. data/lib/arel/visitors/dot.rb +81 -90
  314. data/lib/arel/visitors/mysql.rb +23 -5
  315. data/lib/arel/visitors/postgresql.rb +1 -22
  316. data/lib/arel/visitors/to_sql.rb +170 -36
  317. data/lib/arel/visitors/visitor.rb +2 -2
  318. data/lib/arel.rb +23 -4
  319. data/lib/rails/generators/active_record/application_record/USAGE +8 -0
  320. data/lib/rails/generators/active_record/application_record/templates/application_record.rb.tt +1 -1
  321. data/lib/rails/generators/active_record/migration/templates/create_table_migration.rb.tt +4 -1
  322. data/lib/rails/generators/active_record/migration.rb +3 -1
  323. data/lib/rails/generators/active_record/model/USAGE +113 -0
  324. data/lib/rails/generators/active_record/model/model_generator.rb +15 -6
  325. data/lib/rails/generators/active_record/model/templates/abstract_base_class.rb.tt +1 -1
  326. data/lib/rails/generators/active_record/model/templates/model.rb.tt +1 -1
  327. data/lib/rails/generators/active_record/model/templates/module.rb.tt +2 -2
  328. data/lib/rails/generators/active_record/multi_db/multi_db_generator.rb +16 -0
  329. data/lib/rails/generators/active_record/multi_db/templates/multi_db.rb.tt +44 -0
  330. metadata +100 -14
  331. data/lib/active_record/connection_adapters/legacy_pool_manager.rb +0 -35
  332. data/lib/active_record/null_relation.rb +0 -67
data/CHANGELOG.md CHANGED
@@ -1,1767 +1,902 @@
1
- ## Rails 6.1.7 (September 09, 2022) ##
1
+ ## Rails 7.2.0 (August 09, 2024) ##
2
2
 
3
- * Symbol is allowed by default for YAML columns
3
+ * Handle commas in Sqlite3 default function definitions.
4
4
 
5
- *Étienne Barrié*
5
+ *Stephen Margheim*
6
6
 
7
- * Fix `ActiveRecord::Store` to serialize as a regular Hash
7
+ * Fixes `validates_associated` raising an exception when configured with a
8
+ singular association and having `index_nested_attribute_errors` enabled.
8
9
 
9
- Previously it would serialize as an `ActiveSupport::HashWithIndifferentAccess`
10
- which is wasteful and cause problem with YAML safe_load.
10
+ *Martin Spickermann*
11
11
 
12
- *Jean Boussier*
13
-
14
- * Fix PG.connect keyword arguments deprecation warning on ruby 2.7
15
-
16
- Fixes #44307.
17
-
18
- *Nikita Vasilevsky*
19
-
20
- ## Rails 6.1.6.1 (July 12, 2022) ##
21
-
22
- * Change ActiveRecord::Coders::YAMLColumn default to safe_load
23
-
24
- This adds two new configuration options The configuration options are as
25
- follows:
26
-
27
- * `config.active_storage.use_yaml_unsafe_load`
28
-
29
- When set to true, this configuration option tells Rails to use the old
30
- "unsafe" YAML loading strategy, maintaining the existing behavior but leaving
31
- the possible escalation vulnerability in place. Setting this option to true
32
- is *not* recommended, but can aid in upgrading.
33
-
34
- * `config.active_record.yaml_column_permitted_classes`
35
-
36
- The "safe YAML" loading method does not allow all classes to be deserialized
37
- by default. This option allows you to specify classes deemed "safe" in your
38
- application. For example, if your application uses Symbol and Time in
39
- serialized data, you can add Symbol and Time to the allowed list as follows:
40
-
41
- ```
42
- config.active_record.yaml_column_permitted_classes = [Symbol, Date, Time]
43
- ```
44
-
45
- [CVE-2022-32224]
46
-
47
-
48
- ## Rails 6.1.6 (May 09, 2022) ##
49
-
50
- * No changes.
51
-
52
-
53
- ## Rails 6.1.5.1 (April 26, 2022) ##
54
-
55
- * No changes.
56
-
57
-
58
- ## Rails 6.1.5 (March 09, 2022) ##
59
-
60
- * Fix `ActiveRecord::ConnectionAdapters::SchemaCache#deep_deduplicate` for Ruby 2.6.
61
-
62
- Ruby 2.6 and 2.7 have slightly different implementations of the `String#-@` method.
63
- In Ruby 2.6, the receiver of the `String#-@` method is modified under certain circumstances.
64
- This was later identified as a bug (https://bugs.ruby-lang.org/issues/15926) and only
65
- fixed in Ruby 2.7.
66
-
67
- Before the changes in this commit, the
68
- `ActiveRecord::ConnectionAdapters::SchemaCache#deep_deduplicate` method, which internally
69
- calls the `String#-@` method, could also modify an input string argument in Ruby 2.6 --
70
- changing a tainted, unfrozen string into a tainted, frozen string.
71
-
72
- Fixes #43056
73
-
74
- *Eric O'Hanlon*
75
-
76
- * Fix migration compatibility to create SQLite references/belongs_to column as integer when
77
- migration version is 6.0.
78
-
79
- `reference`/`belongs_to` in migrations with version 6.0 were creating columns as
80
- bigint instead of integer for the SQLite Adapter.
81
-
82
- *Marcelo Lauxen*
83
-
84
- * Fix dbconsole for 3-tier config.
85
-
86
- *Eileen M. Uchitelle*
87
-
88
- * Better handle SQL queries with invalid encoding.
89
-
90
- ```ruby
91
- Post.create(name: "broken \xC8 UTF-8")
92
- ```
93
-
94
- Would cause all adapters to fail in a non controlled way in the code
95
- responsible to detect write queries.
96
-
97
- The query is now properly passed to the database connection, which might or might
98
- not be able to handle it, but will either succeed or failed in a more correct way.
99
-
100
- *Jean Boussier*
101
-
102
- * Ignore persisted in-memory records when merging target lists.
103
-
104
- *Kevin Sjöberg*
105
-
106
- * Fix regression bug that caused ignoring additional conditions for preloading
107
- `has_many` through relations.
108
-
109
- Fixes #43132
110
-
111
- *Alexander Pauly*
112
-
113
- * Fix `ActiveRecord::InternalMetadata` to not be broken by
114
- `config.active_record.record_timestamps = false`
115
-
116
- Since the model always create the timestamp columns, it has to set them, otherwise it breaks
117
- various DB management tasks.
118
-
119
- Fixes #42983
120
-
121
- *Jean Boussier*
122
-
123
- * Fix duplicate active record objects on `inverse_of`.
124
-
125
- *Justin Carvalho*
126
-
127
- * Fix duplicate objects stored in has many association after save.
128
-
129
- Fixes #42549.
130
-
131
- *Alex Ghiculescu*
132
-
133
- * Fix performance regression in `CollectionAssocation#build`.
134
-
135
- *Alex Ghiculescu*
136
-
137
- * Fix retrieving default value for text column for MariaDB.
138
-
139
- *fatkodima*
140
-
141
-
142
- ## Rails 6.1.4.7 (March 08, 2022) ##
143
-
144
- * No changes.
145
-
146
-
147
- ## Rails 6.1.4.6 (February 11, 2022) ##
148
-
149
- * No changes.
150
-
151
-
152
- ## Rails 6.1.4.5 (February 11, 2022) ##
153
-
154
- * No changes.
155
-
156
-
157
- ## Rails 6.1.4.4 (December 15, 2021) ##
158
-
159
- * No changes.
160
-
161
-
162
- ## Rails 6.1.4.3 (December 14, 2021) ##
163
-
164
- * No changes.
165
-
166
-
167
- ## Rails 6.1.4.2 (December 14, 2021) ##
168
-
169
- * No changes.
170
-
171
-
172
- ## Rails 6.1.4.1 (August 19, 2021) ##
173
-
174
- * No changes.
175
-
176
-
177
- ## Rails 6.1.4 (June 24, 2021) ##
178
-
179
- * Do not try to rollback transactions that failed due to a `ActiveRecord::TransactionRollbackError`.
180
-
181
- *Jamie McCarthy*
182
-
183
- * Raise an error if `pool_config` is `nil` in `set_pool_config`.
184
-
185
- *Eileen M. Uchitelle*
186
-
187
- * Fix compatibility with `psych >= 4`.
188
-
189
- Starting in Psych 4.0.0 `YAML.load` behaves like `YAML.safe_load`. To preserve compatibility
190
- Active Record's schema cache loader and `YAMLColumn` now uses `YAML.unsafe_load` if available.
191
-
192
- *Jean Boussier*
193
-
194
- * Support using replicas when using `rails dbconsole`.
195
-
196
- *Christopher Thornton*
197
-
198
- * Restore connection pools after transactional tests.
199
-
200
- *Eugene Kenny*
201
-
202
- * Change `upsert_all` to fails cleanly for MySQL when `:unique_by` is used.
203
-
204
- *Bastian Bartmann*
205
-
206
- * Fix user-defined `self.default_scope` to respect table alias.
207
-
208
- *Ryuta Kamizono*
209
-
210
- * Clear `@cache_keys` cache after `update_all`, `delete_all`, `destroy_all`.
211
-
212
- *Ryuta Kamizono*
213
-
214
- * Changed Arel predications `contains` and `overlaps` to use
215
- `quoted_node` so that PostgreSQL arrays are quoted properly.
216
-
217
- *Bradley Priest*
218
-
219
- * Fix `merge` when the `where` clauses have string contents.
220
-
221
- *Ryuta Kamizono*
222
-
223
- * Fix rollback of parent destruction with nested `dependent: :destroy`.
224
-
225
- *Jacopo Beschi*
226
-
227
- * Fix binds logging for `"WHERE ... IN ..."` statements.
228
-
229
- *Ricardo Díaz*
230
-
231
- * Handle `false` in relation strict loading checks.
232
-
233
- Previously when a model had strict loading set to true and then had a
234
- relation set `strict_loading` to false the false wasn't considered when
235
- deciding whether to raise/warn about strict loading.
236
-
237
- ```
238
- class Dog < ActiveRecord::Base
239
- self.strict_loading_by_default = true
240
-
241
- has_many :treats, strict_loading: false
242
- end
243
- ```
244
-
245
- In the example, `dog.treats` would still raise even though
246
- `strict_loading` was set to false. This is a bug affecting more than
247
- Active Storage which is why I made this PR superseding #41461. We need
248
- to fix this for all applications since the behavior is a little
249
- surprising. I took the test from #41461 and the code suggestion from #41453
250
- with some additions.
251
-
252
- *Eileen M. Uchitelle*, *Radamés Roriz*
253
-
254
- * Fix numericality validator without precision.
255
-
256
- *Ryuta Kamizono*
257
-
258
- * Fix aggregate attribute on Enum types.
259
-
260
- *Ryuta Kamizono*
261
-
262
- * Fix `CREATE INDEX` statement generation for PostgreSQL.
263
-
264
- *eltongo*
265
-
266
- * Fix where clause on enum attribute when providing array of strings.
267
-
268
- *Ryuta Kamizono*
269
-
270
- * Fix `unprepared_statement` to work it when nesting.
271
-
272
- *Ryuta Kamizono*
273
-
274
-
275
- ## Rails 6.1.3.2 (May 05, 2021) ##
276
-
277
- * No changes.
278
-
279
-
280
- ## Rails 6.1.3.1 (March 26, 2021) ##
281
-
282
- * No changes.
283
-
284
-
285
- ## Rails 6.1.3 (February 17, 2021) ##
286
-
287
- * Fix the MySQL adapter to always set the right collation and charset
288
- to the connection session.
289
-
290
- *Rafael Mendonça França*
291
-
292
- * Fix MySQL adapter handling of time objects when prepared statements
293
- are enabled.
294
-
295
- *Rafael Mendonça França*
296
-
297
- * Fix scoping in enum fields using conditions that would generate
298
- an `IN` clause.
299
-
300
- *Ryuta Kamizono*
301
-
302
- * Skip optimised #exist? query when #include? is called on a relation
303
- with a having clause
304
-
305
- Relations that have aliased select values AND a having clause that
306
- references an aliased select value would generate an error when
307
- #include? was called, due to an optimisation that would generate
308
- call #exists? on the relation instead, which effectively alters
309
- the select values of the query (and thus removes the aliased select
310
- values), but leaves the having clause intact. Because the having
311
- clause is then referencing an aliased column that is no longer
312
- present in the simplified query, an ActiveRecord::InvalidStatement
313
- error was raised.
314
-
315
- An sample query affected by this problem:
316
-
317
- ```ruby
318
- Author.select('COUNT(*) as total_posts', 'authors.*')
319
- .joins(:posts)
320
- .group(:id)
321
- .having('total_posts > 2')
322
- .include?(Author.first)
323
- ```
324
-
325
- This change adds an addition check to the condition that skips the
326
- simplified #exists? query, which simply checks for the presence of
327
- a having clause.
328
-
329
- Fixes #41417
330
-
331
- *Michael Smart*
332
-
333
- * Increment postgres prepared statement counter before making a prepared statement, so if the statement is aborted
334
- without Rails knowledge (e.g., if app gets kill -9d during long-running query or due to Rack::Timeout), app won't end
335
- up in perpetual crash state for being inconsistent with Postgres.
336
-
337
- *wbharding*, *Martin Tepper*
338
-
339
-
340
- ## Rails 6.1.2.1 (February 10, 2021) ##
341
-
342
- * Fix possible DoS vector in PostgreSQL money type
343
-
344
- Carefully crafted input can cause a DoS via the regular expressions used
345
- for validating the money format in the PostgreSQL adapter. This patch
346
- fixes the regexp.
347
-
348
- Thanks to @dee-see from Hackerone for this patch!
349
-
350
- [CVE-2021-22880]
351
-
352
- *Aaron Patterson*
353
-
354
-
355
- ## Rails 6.1.2 (February 09, 2021) ##
356
-
357
- * Fix timestamp type for sqlite3.
358
-
359
- *Eileen M. Uchitelle*
360
-
361
- * Make destroy async transactional.
362
-
363
- An active record rollback could occur while enqueuing a job. In this
364
- case the job would enqueue even though the database deletion
365
- rolledback putting things in a funky state.
366
-
367
- Now the jobs are only enqueued until after the db transaction has been committed.
368
-
369
- *Cory Gwin*
370
-
371
- * Fix malformed packet error in MySQL statement for connection configuration.
372
-
373
- *robinroestenburg*
374
-
375
- * Connection specification now passes the "url" key as a configuration for the
376
- adapter if the "url" protocol is "jdbc", "http", or "https". Previously only
377
- urls with the "jdbc" prefix were passed to the Active Record Adapter, others
378
- are assumed to be adapter specification urls.
379
-
380
- Fixes #41137.
381
-
382
- *Jonathan Bracy*
383
-
384
- * Fix granular connection swapping when there are multiple abstract classes.
385
-
386
- *Eileen M. Uchitelle*
387
-
388
- * Fix `find_by` with custom primary key for belongs_to association.
389
-
390
- *Ryuta Kamizono*
391
-
392
- * Add support for `rails console --sandbox` for multiple database applications.
393
-
394
- *alpaca-tc*
395
-
396
- * Fix `where` on polymorphic association with empty array.
397
-
398
- *Ryuta Kamizono*
399
-
400
- * Fix preventing writes for `ApplicationRecord`.
401
-
402
- *Eileen M. Uchitelle*
403
-
404
-
405
- ## Rails 6.1.1 (January 07, 2021) ##
406
-
407
- * Fix fixtures loading when strict loading is enabled for the association.
408
-
409
- *Alex Ghiculescu*
410
-
411
- * Fix `where` with custom primary key for belongs_to association.
412
-
413
- *Ryuta Kamizono*
414
-
415
- * Fix `where` with aliased associations.
416
-
417
- *Ryuta Kamizono*
418
-
419
- * Fix `composed_of` with symbol mapping.
420
-
421
- *Ryuta Kamizono*
422
-
423
- * Don't skip money's type cast for pluck and calculations.
424
-
425
- *Ryuta Kamizono*
426
-
427
- * Fix `where` on polymorphic association with non Active Record object.
428
-
429
- *Ryuta Kamizono*
430
-
431
- * Make sure `db:prepare` works even the schema file doesn't exist.
432
-
433
- *Rafael Mendonça França*
434
-
435
- * Fix complicated `has_many :through` with nested where condition.
436
-
437
- *Ryuta Kamizono*
438
-
439
- * Handle STI models for `has_many dependent: :destroy_async`.
440
-
441
- *Muhammad Usman*
442
-
443
- * Restore possibility of passing `false` to :polymorphic option of `belongs_to`.
444
-
445
- Previously, passing `false` would trigger the option validation logic
446
- to throw an error saying :polymorphic would not be a valid option.
447
-
448
- *glaszig*
449
-
450
- * Allow adding nonnamed expression indexes to be revertible.
451
-
452
- Fixes #40732.
453
-
454
- Previously, the following code would raise an error, when executed while rolling back,
455
- and the index name should be specified explicitly. Now, the index name is inferred
456
- automatically.
457
-
458
- ```ruby
459
- add_index(:items, "to_tsvector('english', description)")
460
- ```
461
-
462
- *fatkodima*
463
-
464
-
465
- ## Rails 6.1.0 (December 09, 2020) ##
466
-
467
- * Only warn about negative enums if a positive form that would cause conflicts exists.
468
-
469
- Fixes #39065.
470
-
471
- *Alex Ghiculescu*
472
-
473
- * Change `attribute_for_inspect` to take `filter_attributes` in consideration.
474
-
475
- *Rafael Mendonça França*
476
-
477
- * Fix odd behavior of inverse_of with multiple belongs_to to same class.
478
-
479
- Fixes #35204.
480
-
481
- *Tomoyuki Kai*
482
-
483
- * Build predicate conditions with objects that delegate `#id` and primary key:
484
-
485
- ```ruby
486
- class AdminAuthor
487
- delegate_missing_to :@author
488
-
489
- def initialize(author)
490
- @author = author
491
- end
492
- end
493
-
494
- Post.where(author: AdminAuthor.new(author))
495
- ```
496
-
497
- *Sean Doyle*
498
-
499
- * Add `connected_to_many` API.
500
-
501
- This API allows applications to connect to multiple databases at once without switching all of them or implementing a deeply nested stack.
502
-
503
- Before:
504
-
505
- AnimalsRecord.connected_to(role: :reading) do
506
- MealsRecord.connected_to(role: :reading) do
507
- Dog.first # read from animals replica
508
- Dinner.first # read from meals replica
509
- Person.first # read from primary writer
510
- end
511
- end
512
-
513
- After:
514
-
515
- ActiveRecord::Base.connected_to_many([AnimalsRecord, MealsRecord], role: :reading) do
516
- Dog.first # read from animals replica
517
- Dinner.first # read from meals replica
518
- Person.first # read from primary writer
519
- end
520
-
521
- *Eileen M. Uchitelle*, *John Crepezzi*
522
-
523
- * Add option to raise or log for `ActiveRecord::StrictLoadingViolationError`.
524
-
525
- Some applications may not want to raise an error in production if using `strict_loading`. This would allow an application to set strict loading to log for the production environment while still raising in development and test environments.
526
-
527
- Set `config.active_record.action_on_strict_loading_violation` to `:log` errors instead of raising.
528
-
529
- *Eileen M. Uchitelle*
530
-
531
- * Allow the inverse of a `has_one` association that was previously autosaved to be loaded.
532
-
533
- Fixes #34255.
534
-
535
- *Steven Weber*
536
-
537
- * Optimise the length of index names for polymorphic references by using the reference name rather than the type and id column names.
538
-
539
- Because the default behaviour when adding an index with multiple columns is to use all column names in the index name, this could frequently lead to overly long index names for polymorphic references which would fail the migration if it exceeded the database limit.
540
-
541
- This change reduces the chance of that happening by using the reference name, e.g. `index_my_table_on_my_reference`.
542
-
543
- Fixes #38655.
544
-
545
- *Luke Redpath*
546
-
547
- * MySQL: Uniqueness validator now respects default database collation,
548
- no longer enforce case sensitive comparison by default.
549
-
550
- *Ryuta Kamizono*
551
-
552
- * Remove deprecated methods from `ActiveRecord::ConnectionAdapters::DatabaseLimits`.
553
-
554
- `column_name_length`
555
- `table_name_length`
556
- `columns_per_table`
557
- `indexes_per_table`
558
- `columns_per_multicolumn_index`
559
- `sql_query_length`
560
- `joins_per_query`
561
-
562
- *Rafael Mendonça França*
563
-
564
- * Remove deprecated `ActiveRecord::ConnectionAdapters::AbstractAdapter#supports_multi_insert?`.
565
-
566
- *Rafael Mendonça França*
567
-
568
- * Remove deprecated `ActiveRecord::ConnectionAdapters::AbstractAdapter#supports_foreign_keys_in_create?`.
569
-
570
- *Rafael Mendonça França*
571
-
572
- * Remove deprecated `ActiveRecord::ConnectionAdapters::PostgreSQLAdapter#supports_ranges?`.
573
-
574
- *Rafael Mendonça França*
575
-
576
- * Remove deprecated `ActiveRecord::Base#update_attributes` and `ActiveRecord::Base#update_attributes!`.
577
-
578
- *Rafael Mendonça França*
579
-
580
- * Remove deprecated `migrations_path` argument in `ActiveRecord::ConnectionAdapter::SchemaStatements#assume_migrated_upto_version`.
581
-
582
- *Rafael Mendonça França*
583
-
584
- * Remove deprecated `config.active_record.sqlite3.represent_boolean_as_integer`.
585
-
586
- *Rafael Mendonça França*
587
-
588
- * `relation.create` does no longer leak scope to class level querying methods
589
- in initialization block and callbacks.
590
-
591
- Before:
592
-
593
- User.where(name: "John").create do |john|
594
- User.find_by(name: "David") # => nil
595
- end
596
-
597
- After:
598
-
599
- User.where(name: "John").create do |john|
600
- User.find_by(name: "David") # => #<User name: "David", ...>
601
- end
602
-
603
- *Ryuta Kamizono*
604
-
605
- * Named scope chain does no longer leak scope to class level querying methods.
606
-
607
- class User < ActiveRecord::Base
608
- scope :david, -> { User.where(name: "David") }
609
- end
610
-
611
- Before:
612
-
613
- User.where(name: "John").david
614
- # SELECT * FROM users WHERE name = 'John' AND name = 'David'
615
-
616
- After:
617
-
618
- User.where(name: "John").david
619
- # SELECT * FROM users WHERE name = 'David'
620
-
621
- *Ryuta Kamizono*
622
-
623
- * Remove deprecated methods from `ActiveRecord::DatabaseConfigurations`.
624
-
625
- `fetch`
626
- `each`
627
- `first`
628
- `values`
629
- `[]=`
630
-
631
- *Rafael Mendonça França*
632
-
633
- * `where.not` now generates NAND predicates instead of NOR.
634
-
635
- Before:
636
-
637
- User.where.not(name: "Jon", role: "admin")
638
- # SELECT * FROM users WHERE name != 'Jon' AND role != 'admin'
639
-
640
- After:
641
-
642
- User.where.not(name: "Jon", role: "admin")
643
- # SELECT * FROM users WHERE NOT (name == 'Jon' AND role == 'admin')
644
-
645
- *Rafael Mendonça França*
646
-
647
- * Remove deprecated `ActiveRecord::Result#to_hash` method.
648
-
649
- *Rafael Mendonça França*
650
-
651
- * Deprecate `ActiveRecord::Base.allow_unsafe_raw_sql`.
652
-
653
- *Rafael Mendonça França*
654
-
655
- * Remove deprecated support for using unsafe raw SQL in `ActiveRecord::Relation` methods.
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.
656
15
 
657
- *Rafael Mendonça França*
658
-
659
- * Allow users to silence the "Rails couldn't infer whether you are using multiple databases..."
660
- message using `config.active_record.suppress_multiple_database_warning`.
661
-
662
- *Omri Gabay*
663
-
664
- * Connections can be granularly switched for abstract classes when `connected_to` is called.
16
+ *Xavier Noria*
665
17
 
666
- This change allows `connected_to` to switch a `role` and/or `shard` for a single abstract class instead of all classes globally. Applications that want to use the new feature need to set `config.active_record.legacy_connection_handling` to `false` in their application configuration.
18
+ * Add condensed `#inspect` for `ConnectionPool`, `AbstractAdapter`, and
19
+ `DatabaseConfig`.
667
20
 
668
- Example usage:
21
+ *Hartley McGuire*
669
22
 
670
- Given an application we have a `User` model that inherits from `ApplicationRecord` and a `Dog` model that inherits from `AnimalsRecord`. `AnimalsRecord` and `ApplicationRecord` have writing and reading connections as well as shard `default`, `one`, and `two`.
23
+ * Fixed a memory performance issue in Active Record attribute methods definition.
671
24
 
672
- ```ruby
673
- ActiveRecord::Base.connected_to(role: :reading) do
674
- User.first # reads from default replica
675
- Dog.first # reads from default replica
25
+ *Jean Boussier*
676
26
 
677
- AnimalsRecord.connected_to(role: :writing, shard: :one) do
678
- User.first # reads from default replica
679
- Dog.first # reads from shard one primary
680
- end
27
+ * Define the new Active Support notification event `start_transaction.active_record`.
681
28
 
682
- User.first # reads from default replica
683
- Dog.first # reads from default replica
29
+ This event is fired when database transactions or savepoints start, and
30
+ complements `transaction.active_record`, which is emitted when they finish.
684
31
 
685
- ApplicationRecord.connected_to(role: :writing, shard: :two) do
686
- User.first # reads from shard two primary
687
- Dog.first # reads from default replica
688
- end
689
- end
690
- ```
32
+ The payload has the transaction (`:transaction`) and the connection (`:connection`).
691
33
 
692
- *Eileen M. Uchitelle*, *John Crepezzi*
34
+ *Xavier Noria*
693
35
 
694
- * Allow double-dash comment syntax when querying read-only databases
36
+ * Fix an issue where the IDs reader method did not return expected results
37
+ for preloaded associations in models using composite primary keys.
695
38
 
696
- *James Adam*
39
+ *Jay Ang*
697
40
 
698
- * Add `values_at` method.
41
+ * The payload of `sql.active_record` Active Support notifications now has the current transaction in the `:transaction` key.
699
42
 
700
- Returns an array containing the values associated with the given methods.
43
+ *Xavier Noria*
701
44
 
702
- ```ruby
703
- topic = Topic.first
704
- topic.values_at(:title, :author_name)
705
- # => ["Budget", "Jason"]
706
- ```
45
+ * The payload of `transaction.active_record` Active Support notifications now has the transaction the event is related to in the `:transaction` key.
707
46
 
708
- Similar to `Hash#values_at` but on an Active Record instance.
47
+ *Xavier Noria*
709
48
 
710
- *Guillaume Briday*
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.
711
50
 
712
- * Fix `read_attribute_before_type_cast` to consider attribute aliases.
51
+ *Xavier Noria*
713
52
 
714
- *Marcelo Lauxen*
53
+ * Fix inference of association model on nested models with the same demodularized name.
715
54
 
716
- * Support passing record to uniqueness validator `:conditions` callable:
55
+ E.g. with the following setup:
717
56
 
718
57
  ```ruby
719
- class Article < ApplicationRecord
720
- validates_uniqueness_of :title, conditions: ->(article) {
721
- published_at = article.published_at
722
- where(published_at: published_at.beginning_of_year..published_at.end_of_year)
723
- }
58
+ class Nested::Post < ApplicationRecord
59
+ has_one :post, through: :other
724
60
  end
725
61
  ```
726
62
 
727
- *Eliot Sykes*
728
-
729
- * `BatchEnumerator#update_all` and `BatchEnumerator#delete_all` now return the
730
- total number of rows affected, just like their non-batched counterparts.
731
-
732
- ```ruby
733
- Person.in_batches.update_all("first_name = 'Eugene'") # => 42
734
- Person.in_batches.delete_all # => 42
735
- ```
736
-
737
- Fixes #40287.
738
-
739
- *Eugene Kenny*
740
-
741
- * Add support for PostgreSQL `interval` data type with conversion to
742
- `ActiveSupport::Duration` when loading records from database and
743
- serialization to ISO 8601 formatted duration string on save.
744
- Add support to define a column in migrations and get it in a schema dump.
745
- Optional column precision is supported.
746
-
747
- To use this in 6.1, you need to place the next string to your model file:
63
+ Before, `#post` would infer the model as `Nested::Post`, but now it correctly infers `Post`.
748
64
 
749
- attribute :duration, :interval
65
+ *Joshua Young*
750
66
 
751
- To keep old behavior until 7.0 is released:
67
+ * PostgreSQL `Cidr#change?` detects the address prefix change.
752
68
 
753
- attribute :duration, :string
754
-
755
- Example:
756
-
757
- create_table :events do |t|
758
- t.string :name
759
- t.interval :duration
760
- end
69
+ *Taketo Takashima*
761
70
 
762
- class Event < ApplicationRecord
763
- attribute :duration, :interval
764
- end
71
+ * Change `BatchEnumerator#destroy_all` to return the total number of affected rows.
765
72
 
766
- Event.create!(name: 'Rock Fest', duration: 2.days)
767
- Event.last.duration # => 2 days
768
- Event.last.duration.iso8601 # => "P2D"
769
- Event.new(duration: 'P1DT12H3S').duration # => 1 day, 12 hours, and 3 seconds
770
- Event.new(duration: '1 day') # Unknown value will be ignored and NULL will be written to database
73
+ Previously, it always returned `nil`.
771
74
 
772
- *Andrey Novikov*
75
+ *fatkodima*
773
76
 
774
- * Allow associations supporting the `dependent:` key to take `dependent: :destroy_async`.
77
+ * Support `touch_all` in batches.
775
78
 
776
79
  ```ruby
777
- class Account < ActiveRecord::Base
778
- belongs_to :supplier, dependent: :destroy_async
779
- end
80
+ Post.in_batches.touch_all
780
81
  ```
781
82
 
782
- `:destroy_async` will enqueue a job to destroy associated records in the background.
783
-
784
- *DHH*, *George Claghorn*, *Cory Gwin*, *Rafael Mendonça França*, *Adrianna Chang*
83
+ *fatkodima*
785
84
 
786
- * Add `SKIP_TEST_DATABASE` environment variable to disable modifying the test database when `rails db:create` and `rails db:drop` are called.
85
+ * Add support for `:if_not_exists` and `:force` options to `create_schema`.
787
86
 
788
- *Jason Schweier*
87
+ *fatkodima*
789
88
 
790
- * `connects_to` can only be called on `ActiveRecord::Base` or abstract classes.
89
+ * Fix `index_errors` having incorrect index in association validation errors.
791
90
 
792
- Ensure that `connects_to` can only be called from `ActiveRecord::Base` or abstract classes. This protects the application from opening duplicate or too many connections.
91
+ *lulalala*
793
92
 
794
- *Eileen M. Uchitelle*, *John Crepezzi*
93
+ * Add `index_errors: :nested_attributes_order` mode.
795
94
 
796
- * All connection adapters `execute` now raises `ActiveRecord::ConnectionNotEstablished` rather than
797
- `ActiveRecord::StatementInvalid` when they encounter a connection error.
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.
798
96
 
799
- *Jean Boussier*
97
+ *lulalala*
800
98
 
801
- * `Mysql2Adapter#quote_string` now raises `ActiveRecord::ConnectionNotEstablished` rather than
802
- `ActiveRecord::StatementInvalid` when it can't connect to the MySQL server.
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.
803
100
 
804
- *Jean Boussier*
101
+ *Joé Dupuis*
805
102
 
806
- * Add support for check constraints that are `NOT VALID` via `validate: false` (PostgreSQL-only).
103
+ * Association option `query_constraints` is deprecated in favor of `foreign_key`.
807
104
 
808
- *Alex Robbin*
105
+ *Nikita Vasilevsky*
809
106
 
810
- * Ensure the default configuration is considered primary or first for an environment
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.
811
108
 
812
- If a multiple database application provides a configuration named primary, that will be treated as default. In applications that do not have a primary entry, the default database configuration will be the first configuration for an environment.
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.
813
110
 
814
- *Eileen M. Uchitelle*
111
+ *DHH*
815
112
 
816
- * Allow `where` references association names as joined table name aliases.
113
+ * Added support for recursive common table expressions.
817
114
 
818
115
  ```ruby
819
- class Comment < ActiveRecord::Base
820
- enum label: [:default, :child]
821
- has_many :children, class_name: "Comment", foreign_key: :parent_id
822
- end
823
-
824
- # ... FROM comments LEFT OUTER JOIN comments children ON ... WHERE children.label = 1
825
- Comment.includes(:children).where("children.label": "child")
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
+ )
826
122
  ```
827
123
 
828
- *Ryuta Kamizono*
829
-
830
- * Support storing demodulized class name for polymorphic type.
831
-
832
- Before Rails 6.1, storing demodulized class name is supported only for STI type
833
- by `store_full_sti_class` class attribute.
834
-
835
- Now `store_full_class_name` class attribute can handle both STI and polymorphic types.
836
-
837
- *Ryuta Kamizono*
124
+ Generates the following SQL:
838
125
 
839
- * Deprecate `rails db:structure:{load, dump}` tasks and extend
840
- `rails db:schema:{load, dump}` tasks to work with either `:ruby` or `:sql` format,
841
- depending on `config.active_record.schema_format` configuration value.
842
-
843
- *fatkodima*
844
-
845
- * Respect the `select` values for eager loading.
846
-
847
- ```ruby
848
- post = Post.select("UPPER(title) AS title").first
849
- post.title # => "WELCOME TO THE WEBLOG"
850
- post.body # => ActiveModel::MissingAttributeError
851
-
852
- # Rails 6.0 (ignore the `select` values)
853
- post = Post.select("UPPER(title) AS title").eager_load(:comments).first
854
- post.title # => "Welcome to the weblog"
855
- post.body # => "Such a lovely day"
856
-
857
- # Rails 6.1 (respect the `select` values)
858
- post = Post.select("UPPER(title) AS title").eager_load(:comments).first
859
- post.title # => "WELCOME TO THE WEBLOG"
860
- post.body # => ActiveModel::MissingAttributeError
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"
861
133
  ```
862
134
 
863
- *Ryuta Kamizono*
135
+ *ClearlyClaire*
864
136
 
865
- * Allow attribute's default to be configured but keeping its own type.
137
+ * `validate_constraint` can be called in a `change_table` block.
866
138
 
139
+ ex:
867
140
  ```ruby
868
- class Post < ActiveRecord::Base
869
- attribute :written_at, default: -> { Time.now.utc }
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"
870
144
  end
871
-
872
- # Rails 6.0
873
- Post.type_for_attribute(:written_at) # => #<Type::Value ... precision: nil, ...>
874
-
875
- # Rails 6.1
876
- Post.type_for_attribute(:written_at) # => #<Type::DateTime ... precision: 6, ...>
877
145
  ```
878
146
 
879
- *Ryuta Kamizono*
147
+ *Cody Cutrer*
880
148
 
881
- * Allow default to be configured for Enum.
149
+ * `PostgreSQLAdapter` now decodes columns of type date to `Date` instead of string.
882
150
 
151
+ Ex:
883
152
  ```ruby
884
- class Book < ActiveRecord::Base
885
- enum status: [:proposed, :written, :published], _default: :published
886
- end
887
-
888
- Book.new.status # => "published"
153
+ ActiveRecord::Base.connection
154
+ .select_value("select '2024-01-01'::date").class #=> Date
889
155
  ```
890
156
 
891
- *Ryuta Kamizono*
892
-
893
- * Deprecate YAML loading from legacy format older than Rails 5.0.
894
-
895
- *Ryuta Kamizono*
896
-
897
- * Added the setting `ActiveRecord::Base.immutable_strings_by_default`, which
898
- allows you to specify that all string columns should be frozen unless
899
- otherwise specified. This will reduce memory pressure for applications which
900
- do not generally mutate string properties of Active Record objects.
157
+ *Joé Dupuis*
901
158
 
902
- *Sean Griffin*, *Ryuta Kamizono*
159
+ * Strict loading using `:n_plus_one_only` does not eagerly load child associations.
903
160
 
904
- * Deprecate `map!` and `collect!` on `ActiveRecord::Result`.
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.
905
166
 
906
- *Ryuta Kamizono*
907
-
908
- * Support `relation.and` for intersection as Set theory.
167
+ Before:
909
168
 
910
169
  ```ruby
911
- david_and_mary = Author.where(id: [david, mary])
912
- mary_and_bob = Author.where(id: [mary, bob])
913
-
914
- david_and_mary.merge(mary_and_bob) # => [mary, bob]
915
-
916
- david_and_mary.and(mary_and_bob) # => [mary]
917
- david_and_mary.or(mary_and_bob) # => [david, mary, bob]
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
918
175
  ```
919
176
 
920
- *Ryuta Kamizono*
921
-
922
- * Merging conditions on the same column no longer maintain both conditions,
923
- and will be consistently replaced by the latter condition in Rails 7.0.
924
- To migrate to Rails 7.0's behavior, use `relation.merge(other, rewhere: true)`.
177
+ After:
925
178
 
926
179
  ```ruby
927
- # Rails 6.1 (IN clause is replaced by merger side equality condition)
928
- Author.where(id: [david.id, mary.id]).merge(Author.where(id: bob)) # => [bob]
929
-
930
- # Rails 6.1 (both conflict conditions exists, deprecated)
931
- Author.where(id: david.id..mary.id).merge(Author.where(id: bob)) # => []
932
-
933
- # Rails 6.1 with rewhere to migrate to Rails 7.0's behavior
934
- Author.where(id: david.id..mary.id).merge(Author.where(id: bob), rewhere: true) # => [bob]
935
-
936
- # Rails 7.0 (same behavior with IN clause, mergee side condition is consistently replaced)
937
- Author.where(id: [david.id, mary.id]).merge(Author.where(id: bob)) # => [bob]
938
- Author.where(id: david.id..mary.id).merge(Author.where(id: bob)) # => [bob]
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
939
185
  ```
940
186
 
941
- *Ryuta Kamizono*
942
-
943
- * Do not mark Postgresql MAC address and UUID attributes as changed when the assigned value only varies by case.
187
+ *Reid Lynch*
944
188
 
945
- *Peter Fry*
189
+ * Allow `Sqlite3Adapter` to use `sqlite3` gem version `2.x`.
946
190
 
947
- * Resolve issue with insert_all unique_by option when used with expression index.
191
+ *Mike Dalessio*
948
192
 
949
- When the `:unique_by` option of `ActiveRecord::Persistence.insert_all` and
950
- `ActiveRecord::Persistence.upsert_all` was used with the name of an expression index, an error
951
- was raised. Adding a guard around the formatting behavior for the `:unique_by` corrects this.
952
-
953
- Usage:
193
+ * Allow `ActiveRecord::Base#pluck` to accept hash values.
954
194
 
955
195
  ```ruby
956
- create_table :books, id: :integer, force: true do |t|
957
- t.column :name, :string
958
- t.index "lower(name)", unique: true
959
- end
196
+ # Before
197
+ Post.joins(:comments).pluck("posts.id", "comments.id", "comments.body")
960
198
 
961
- Book.insert_all [{ name: "MyTest" }], unique_by: :index_books_on_lower_name
199
+ # After
200
+ Post.joins(:comments).pluck(posts: [:id], comments: [:id, :body])
962
201
  ```
963
202
 
964
- Fixes #39516.
203
+ *fatkodima*
204
+
205
+ * Raise an `ActiveRecord::ActiveRecordError` error when the MySQL database returns an invalid version string.
965
206
 
966
- *Austen Madden*
207
+ *Kevin McPhillips*
967
208
 
968
- * Add basic support for CHECK constraints to database migrations.
209
+ * `ActiveRecord::Base.transaction` now yields an `ActiveRecord::Transaction` object.
969
210
 
970
- Usage:
211
+ This allows to register callbacks on it.
971
212
 
972
213
  ```ruby
973
- add_check_constraint :products, "price > 0", name: "price_check"
974
- remove_check_constraint :products, name: "price_check"
214
+ Article.transaction do |transaction|
215
+ article.update(published: true)
216
+ transaction.after_commit do
217
+ PublishNotificationMailer.with(article: article).deliver_later
218
+ end
219
+ end
975
220
  ```
976
221
 
977
- *fatkodima*
222
+ *Jean Boussier*
978
223
 
979
- * Add `ActiveRecord::Base.strict_loading_by_default` and `ActiveRecord::Base.strict_loading_by_default=`
980
- to enable/disable strict_loading mode by default for a model. The configuration's value is
981
- inheritable by subclasses, but they can override that value and it will not impact parent class.
224
+ * Add `ActiveRecord::Base.current_transaction`.
982
225
 
983
- Usage:
226
+ Returns the current transaction, to allow registering callbacks on it.
984
227
 
985
228
  ```ruby
986
- class Developer < ApplicationRecord
987
- self.strict_loading_by_default = true
988
-
989
- has_many :projects
229
+ Article.current_transaction.after_commit do
230
+ PublishNotificationMailer.with(article: article).deliver_later
990
231
  end
991
-
992
- dev = Developer.first
993
- dev.projects.first
994
- # => ActiveRecord::StrictLoadingViolationError Exception: Developer is marked as strict_loading and Project cannot be lazily loaded.
995
232
  ```
996
233
 
997
- *bogdanvlviv*
998
-
999
- * Deprecate passing an Active Record object to `quote`/`type_cast` directly.
1000
-
1001
- *Ryuta Kamizono*
234
+ *Jean Boussier*
1002
235
 
1003
- * Default engine `ENGINE=InnoDB` is no longer dumped to make schema more agnostic.
236
+ * Add `ActiveRecord.after_all_transactions_commit` callback.
1004
237
 
1005
- Before:
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.
1006
240
 
1007
241
  ```ruby
1008
- create_table "accounts", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci", force: :cascade do |t|
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
1009
247
  end
1010
248
  ```
1011
249
 
1012
- After:
1013
-
1014
- ```ruby
1015
- create_table "accounts", charset: "utf8mb4", collation: "utf8mb4_0900_ai_ci", force: :cascade do |t|
1016
- end
1017
- ```
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.
1018
252
 
1019
- *Ryuta Kamizono*
253
+ If the transaction is rolled back, the block isn't called.
1020
254
 
1021
- * Added delegated type as an alternative to single-table inheritance for representing class hierarchies.
1022
- See ActiveRecord::DelegatedType for the full description.
255
+ *Jean Boussier*
1023
256
 
1024
- *DHH*
257
+ * Add the ability to ignore counter cache columns until they are backfilled.
1025
258
 
1026
- * Deprecate aggregations with group by duplicated fields.
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.
1027
265
 
1028
- To migrate to Rails 7.0's behavior, use `uniq!(:group)` to deduplicate group fields.
266
+ Now, to safely backfill the column, while keeping the column updated with child records added/removed, use:
1029
267
 
1030
268
  ```ruby
1031
- accounts = Account.group(:firm_id)
1032
-
1033
- # duplicated group fields, deprecated.
1034
- accounts.merge(accounts.where.not(credit_limit: nil)).sum(:credit_limit)
1035
- # => {
1036
- # [1, 1] => 50,
1037
- # [2, 2] => 60
1038
- # }
1039
-
1040
- # use `uniq!(:group)` to deduplicate group fields.
1041
- accounts.merge(accounts.where.not(credit_limit: nil)).uniq!(:group).sum(:credit_limit)
1042
- # => {
1043
- # 1 => 50,
1044
- # 2 => 60
1045
- # }
269
+ class Comment < ApplicationRecord
270
+ belongs_to :post, counter_cache: { active: false }
271
+ end
1046
272
  ```
1047
273
 
1048
- *Ryuta Kamizono*
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.
1049
278
 
1050
- * Deprecate duplicated query annotations.
279
+ *fatkodima*
1051
280
 
1052
- To migrate to Rails 7.0's behavior, use `uniq!(:annotate)` to deduplicate query annotations.
281
+ * Retry known idempotent SELECT queries on connection-related exceptions.
1053
282
 
1054
- ```ruby
1055
- accounts = Account.where(id: [1, 2]).annotate("david and mary")
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.
1056
287
 
1057
- # duplicated annotations, deprecated.
1058
- accounts.merge(accounts.rewhere(id: 3))
1059
- # SELECT accounts.* FROM accounts WHERE accounts.id = 3 /* david and mary */ /* david and mary */
288
+ *Adrianna Chang*
1060
289
 
1061
- # use `uniq!(:annotate)` to deduplicate annotations.
1062
- accounts.merge(accounts.rewhere(id: 3)).uniq!(:annotate)
1063
- # SELECT accounts.* FROM accounts WHERE accounts.id = 3 /* david and mary */
1064
- ```
290
+ * Allow association's `foreign_key` to be composite.
1065
291
 
1066
- *Ryuta Kamizono*
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.
1067
294
 
1068
- * Resolve conflict between counter cache and optimistic locking.
295
+ *Nikita Vasilevsky*
1069
296
 
1070
- Bump an Active Record instance's lock version after updating its counter
1071
- cache. This avoids raising an unnecessary `ActiveRecord::StaleObjectError`
1072
- upon subsequent transactions by maintaining parity with the corresponding
1073
- database record's `lock_version` column.
297
+ * Allow association's `primary_key` to be composite.
1074
298
 
1075
- Fixes #16449.
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.
1076
301
 
1077
- *Aaron Lipman*
302
+ *Nikita Vasilevsky*
1078
303
 
1079
- * Support merging option `:rewhere` to allow mergee side condition to be replaced exactly.
304
+ * Add `config.active_record.permanent_connection_checkout` setting.
1080
305
 
1081
- ```ruby
1082
- david_and_mary = Author.where(id: david.id..mary.id)
306
+ Controls whether `ActiveRecord::Base.connection` raises an error, emits a deprecation warning, or neither.
1083
307
 
1084
- # both conflict conditions exists
1085
- david_and_mary.merge(Author.where(id: bob)) # => []
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.
1086
311
 
1087
- # mergee side condition is replaced by rewhere
1088
- david_and_mary.merge(Author.rewhere(id: bob)) # => [bob]
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.
1089
314
 
1090
- # mergee side condition is replaced by rewhere option
1091
- david_and_mary.merge(Author.where(id: bob), rewhere: true) # => [bob]
1092
- ```
315
+ The default behavior remains unchanged, and there is currently no plans to change the default.
1093
316
 
1094
- *Ryuta Kamizono*
317
+ *Jean Boussier*
1095
318
 
1096
- * Add support for finding records based on signed ids, which are tamper-proof, verified ids that can be
1097
- set to expire and scoped with a purpose. This is particularly useful for things like password reset
1098
- or email verification, where you want the bearer of the signed id to be able to interact with the
1099
- underlying record, but usually only within a certain time period.
319
+ * Add dirties option to uncached.
1100
320
 
1101
- ```ruby
1102
- signed_id = User.first.signed_id expires_in: 15.minutes, purpose: :password_reset
321
+ This adds a `dirties` option to `ActiveRecord::Base.uncached` and
322
+ `ActiveRecord::ConnectionAdapters::ConnectionPool#uncached`.
1103
323
 
1104
- User.find_signed signed_id # => nil, since the purpose does not match
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.
1105
326
 
1106
- travel 16.minutes
1107
- User.find_signed signed_id, purpose: :password_reset # => nil, since the signed id has expired
327
+ This is needed by Solid Cache so that cache writes do not clear query caches.
1108
328
 
1109
- travel_back
1110
- User.find_signed signed_id, purpose: :password_reset # => User.first
329
+ *Donal McBreen*
1111
330
 
1112
- User.find_signed! "bad data" # => ActiveSupport::MessageVerifier::InvalidSignature
1113
- ```
331
+ * Deprecate `ActiveRecord::Base.connection` in favor of `.lease_connection`.
1114
332
 
1115
- *DHH*
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.
1116
335
 
1117
- * Support `ALGORITHM = INSTANT` DDL option for index operations on MySQL.
336
+ This deprecation is a soft deprecation, no warnings will be issued and there is no
337
+ current plan to remove the method.
1118
338
 
1119
- *Ryuta Kamizono*
339
+ *Jean Boussier*
1120
340
 
1121
- * Fix index creation to preserve index comment in bulk change table on MySQL.
341
+ * Deprecate `ActiveRecord::ConnectionAdapters::ConnectionPool#connection`.
1122
342
 
1123
- *Ryuta Kamizono*
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.
1124
345
 
1125
- * Allow `unscope` to be aware of table name qualified values.
346
+ *Jean Boussier*
1126
347
 
1127
- It is possible to unscope only the column in the specified table.
348
+ * Expose a generic fixture accessor for fixture names that may conflict with Minitest.
1128
349
 
1129
350
  ```ruby
1130
- posts = Post.joins(:comments).group(:"posts.hidden")
1131
- posts = posts.where("posts.hidden": false, "comments.hidden": false)
1132
-
1133
- posts.count
1134
- # => { false => 10 }
1135
-
1136
- # unscope both hidden columns
1137
- posts.unscope(where: :hidden).count
1138
- # => { false => 11, true => 1 }
1139
-
1140
- # unscope only comments.hidden column
1141
- posts.unscope(where: :"comments.hidden").count
1142
- # => { false => 11 }
351
+ assert_equal "Ruby on Rails", web_sites(:rubyonrails).name
352
+ assert_equal "Ruby on Rails", fixture(:web_sites, :rubyonrails).name
1143
353
  ```
1144
354
 
1145
- *Ryuta Kamizono*, *Slava Korolev*
1146
-
1147
- * Fix `rewhere` to truly overwrite collided where clause by new where clause.
1148
-
1149
- ```ruby
1150
- steve = Person.find_by(name: "Steve")
1151
- david = Author.find_by(name: "David")
1152
-
1153
- relation = Essay.where(writer: steve)
1154
-
1155
- # Before
1156
- relation.rewhere(writer: david).to_a # => []
355
+ *Jean Boussier*
1157
356
 
1158
- # After
1159
- relation.rewhere(writer: david).to_a # => [david]
1160
- ```
357
+ * Using `Model.query_constraints` with a single non-primary-key column used to raise as expected, but with an
358
+ incorrect error message.
1161
359
 
1162
- *Ryuta Kamizono*
360
+ This has been fixed to raise with a more appropriate error message.
1163
361
 
1164
- * Inspect time attributes with subsec and time zone offset.
362
+ *Joshua Young*
1165
363
 
1166
- ```ruby
1167
- p Knot.create
1168
- => #<Knot id: 1, created_at: "2016-05-05 01:29:47.116928000 +0000">
1169
- ```
364
+ * Fix `has_one` association autosave setting the foreign key attribute when it is unchanged.
1170
365
 
1171
- *akinomaeni*, *Jonathan Hefner*
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.
1172
368
 
1173
- * Deprecate passing a column to `type_cast`.
369
+ *Joshua Young*
1174
370
 
1175
- *Ryuta Kamizono*
371
+ * Remove deprecated behavior that would rollback a transaction block when exited using `return`, `break` or `throw`.
1176
372
 
1177
- * Deprecate `in_clause_length` and `allowed_index_name_length` in `DatabaseLimits`.
373
+ *Rafael Mendonça França*
1178
374
 
1179
- *Ryuta Kamizono*
375
+ * Deprecate `Rails.application.config.active_record.commit_transaction_on_non_local_return`.
1180
376
 
1181
- * Support bulk insert/upsert on relation to preserve scope values.
377
+ *Rafael Mendonça França*
1182
378
 
1183
- *Josef Šimánek*, *Ryuta Kamizono*
379
+ * Remove deprecated support to pass `rewhere` to `ActiveRecord::Relation#merge`.
1184
380
 
1185
- * Preserve column comment value on changing column name on MySQL.
381
+ *Rafael Mendonça França*
1186
382
 
1187
- *Islam Taha*
383
+ * Remove deprecated support to pass `deferrable: true` to `add_foreign_key`.
1188
384
 
1189
- * Add support for `if_exists` option for removing an index.
385
+ *Rafael Mendonça França*
1190
386
 
1191
- The `remove_index` method can take an `if_exists` option. If this is set to true an error won't be raised if the index doesn't exist.
387
+ * Remove deprecated support to quote `ActiveSupport::Duration`.
1192
388
 
1193
- *Eileen M. Uchitelle*
389
+ *Rafael Mendonça França*
1194
390
 
1195
- * Remove ibm_db, informix, mssql, oracle, and oracle12 Arel visitors which are not used in the code base.
391
+ * Remove deprecated `#quote_bound_value`.
1196
392
 
1197
- *Ryuta Kamizono*
393
+ *Rafael Mendonça França*
1198
394
 
1199
- * Prevent `build_association` from `touching` a parent record if the record isn't persisted for `has_one` associations.
395
+ * Remove deprecated `ActiveRecord::ConnectionAdapters::ConnectionPool#connection_klass`.
1200
396
 
1201
- Fixes #38219.
397
+ *Rafael Mendonça França*
1202
398
 
1203
- *Josh Brody*
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.
1204
402
 
1205
- * Add support for `if_not_exists` option for adding index.
403
+ *Rafael Mendonça França*
1206
404
 
1207
- The `add_index` method respects `if_not_exists` option. If it is set to true
1208
- index won't be added.
405
+ * Remove deprecated `#all_connection_pools`.
1209
406
 
1210
- Usage:
407
+ *Rafael Mendonça França*
1211
408
 
1212
- ```ruby
1213
- add_index :users, :account_id, if_not_exists: true
1214
- ```
409
+ * Remove deprecated `ActiveRecord::ConnectionAdapters::SchemaCache#data_sources`.
1215
410
 
1216
- The `if_not_exists` option passed to `create_table` also gets propagated to indexes
1217
- created within that migration so that if table and its indexes exist then there is no
1218
- attempt to create them again.
411
+ *Rafael Mendonça França*
1219
412
 
1220
- *Prathamesh Sonpatki*
413
+ * Remove deprecated `ActiveRecord::ConnectionAdapters::SchemaCache.load_from`.
1221
414
 
1222
- * Add `ActiveRecord::Base#previously_new_record?` to show if a record was new before the last save.
415
+ *Rafael Mendonça França*
1223
416
 
1224
- *Tom Ward*
417
+ * Remove deprecated `#all_foreign_keys_valid?` from database adapters.
1225
418
 
1226
- * Support descending order for `find_each`, `find_in_batches`, and `in_batches`.
419
+ *Rafael Mendonça França*
1227
420
 
1228
- Batch processing methods allow you to work with the records in batches, greatly reducing memory consumption, but records are always batched from oldest id to newest.
421
+ * Remove deprecated support to passing coder and class as second argument to `serialize`.
1229
422
 
1230
- This change allows reversing the order, batching from newest to oldest. This is useful when you need to process newer batches of records first.
423
+ *Rafael Mendonça França*
1231
424
 
1232
- Pass `order: :desc` to yield batches in descending order. The default remains `order: :asc`.
425
+ * Remove deprecated support to `ActiveRecord::Base#read_attribute(:id)` to return the custom primary key value.
1233
426
 
1234
- ```ruby
1235
- Person.find_each(order: :desc) do |person|
1236
- person.party_all_night!
1237
- end
1238
- ```
427
+ *Rafael Mendonça França*
1239
428
 
1240
- *Alexey Vasiliev*
429
+ * Remove deprecated `TestFixtures.fixture_path`.
1241
430
 
1242
- * Fix `insert_all` with enum values.
431
+ *Rafael Mendonça França*
1243
432
 
1244
- Fixes #38716.
433
+ * Remove deprecated behavior to support referring to a singular association by its plural name.
1245
434
 
1246
- *Joel Blum*
435
+ *Rafael Mendonça França*
1247
436
 
1248
- * Add support for `db:rollback:name` for multiple database applications.
437
+ * Deprecate `Rails.application.config.active_record.allow_deprecated_singular_associations_name`.
1249
438
 
1250
- Multiple database applications will now raise if `db:rollback` is call and recommend using the `db:rollback:[NAME]` to rollback migrations.
439
+ *Rafael Mendonça França*
1251
440
 
1252
- *Eileen M. Uchitelle*
441
+ * Remove deprecated support to passing `SchemaMigration` and `InternalMetadata` classes as arguments to
442
+ `ActiveRecord::MigrationContext`.
1253
443
 
1254
- * `Relation#pick` now uses already loaded results instead of making another query.
444
+ *Rafael Mendonça França*
1255
445
 
1256
- *Eugene Kenny*
446
+ * Remove deprecated `ActiveRecord::Migration.check_pending!` method.
1257
447
 
1258
- * Deprecate using `return`, `break` or `throw` to exit a transaction block after writes.
448
+ *Rafael Mendonça França*
1259
449
 
1260
- *Dylan Thacker-Smith*
450
+ * Remove deprecated `ActiveRecord::LogSubscriber.runtime` method.
1261
451
 
1262
- * Dump the schema or structure of a database when calling `db:migrate:name`.
452
+ *Rafael Mendonça França*
1263
453
 
1264
- In previous versions of Rails, `rails db:migrate` would dump the schema of the database. In Rails 6, that holds true (`rails db:migrate` dumps all databases' schemas), but `rails db:migrate:name` does not share that behavior.
454
+ * Remove deprecated `ActiveRecord::LogSubscriber.runtime=` method.
1265
455
 
1266
- Going forward, calls to `rails db:migrate:name` will dump the schema (or structure) of the database being migrated.
456
+ *Rafael Mendonça França*
1267
457
 
1268
- *Kyle Thompson*
458
+ * Remove deprecated `ActiveRecord::LogSubscriber.reset_runtime` method.
1269
459
 
1270
- * Reset the `ActiveRecord::Base` connection after `rails db:migrate:name`.
460
+ *Rafael Mendonça França*
1271
461
 
1272
- When `rails db:migrate` has finished, it ensures the `ActiveRecord::Base` connection is reset to its original configuration. Going forward, `rails db:migrate:name` will have the same behavior.
462
+ * Remove deprecated support to define `explain` in the connection adapter with 2 arguments.
1273
463
 
1274
- *Kyle Thompson*
464
+ *Rafael Mendonça França*
1275
465
 
1276
- * Disallow calling `connected_to` on subclasses of `ActiveRecord::Base`.
466
+ * Remove deprecated `ActiveRecord::ActiveJobRequiredError`.
1277
467
 
1278
- Behavior has not changed here but the previous API could be misleading to people who thought it would switch connections for only that class. `connected_to` switches the context from which we are getting connections, not the connections themselves.
468
+ *Rafael Mendonça França*
1279
469
 
1280
- *Eileen M. Uchitelle*, *John Crepezzi*
470
+ * Remove deprecated `ActiveRecord::Base.clear_active_connections!`.
1281
471
 
1282
- * Add support for horizontal sharding to `connects_to` and `connected_to`.
472
+ *Rafael Mendonça França*
1283
473
 
1284
- Applications can now connect to multiple shards and switch between their shards in an application. Note that the shard swapping is still a manual process as this change does not include an API for automatic shard swapping.
474
+ * Remove deprecated `ActiveRecord::Base.clear_reloadable_connections!`.
1285
475
 
1286
- Usage:
476
+ *Rafael Mendonça França*
1287
477
 
1288
- Given the following configuration:
478
+ * Remove deprecated `ActiveRecord::Base.clear_all_connections!`.
1289
479
 
1290
- ```yaml
1291
- # config/database.yml
1292
- production:
1293
- primary:
1294
- database: my_database
1295
- primary_shard_one:
1296
- database: my_database_shard_one
1297
- ```
480
+ *Rafael Mendonça França*
1298
481
 
1299
- Connect to multiple shards:
482
+ * Remove deprecated `ActiveRecord::Base.flush_idle_connections!`.
1300
483
 
1301
- ```ruby
1302
- class ApplicationRecord < ActiveRecord::Base
1303
- self.abstract_class = true
484
+ *Rafael Mendonça França*
1304
485
 
1305
- connects_to shards: {
1306
- default: { writing: :primary },
1307
- shard_one: { writing: :primary_shard_one }
1308
- }
1309
- ```
486
+ * Remove deprecated `name` argument from `ActiveRecord::Base.remove_connection`.
1310
487
 
1311
- Swap between shards in your controller / model code:
488
+ *Rafael Mendonça França*
1312
489
 
1313
- ```ruby
1314
- ActiveRecord::Base.connected_to(shard: :shard_one) do
1315
- # Read from shard one
1316
- end
1317
- ```
490
+ * Remove deprecated support to call `alias_attribute` with non-existent attribute names.
1318
491
 
1319
- The horizontal sharding API also supports read replicas. See guides for more details.
492
+ *Rafael Mendonça França*
1320
493
 
1321
- *Eileen M. Uchitelle*, *John Crepezzi*
494
+ * Remove deprecated `Rails.application.config.active_record.suppress_multiple_database_warning`.
1322
495
 
1323
- * Deprecate `spec_name` in favor of `name` on database configurations.
496
+ *Rafael Mendonça França*
1324
497
 
1325
- The accessors for `spec_name` on `configs_for` and `DatabaseConfig` are deprecated. Please use `name` instead.
498
+ * Add `ActiveRecord::Encryption::MessagePackMessageSerializer`.
1326
499
 
1327
- Deprecated behavior:
500
+ Serialize data to the MessagePack format, for efficient storage in binary columns.
1328
501
 
1329
- ```ruby
1330
- db_config = ActiveRecord::Base.configurations.configs_for(env_name: "development", spec_name: "primary")
1331
- db_config.spec_name
1332
- ```
502
+ The binary encoding requires around 30% less space than the base64 encoding
503
+ used by the default serializer.
1333
504
 
1334
- New behavior:
505
+ *Donal McBreen*
1335
506
 
1336
- ```ruby
1337
- db_config = ActiveRecord::Base.configurations.configs_for(env_name: "development", name: "primary")
1338
- db_config.name
1339
- ```
507
+ * Add support for encrypting binary columns.
1340
508
 
1341
- *Eileen M. Uchitelle*
509
+ Ensure encryption and decryption pass `Type::Binary::Data` around for binary data.
1342
510
 
1343
- * Add additional database-specific rake tasks for multi-database users.
511
+ Previously encrypting binary columns with the `ActiveRecord::Encryption::MessageSerializer`
512
+ incidentally worked for MySQL and SQLite, but not PostgreSQL.
1344
513
 
1345
- Previously, `rails db:create`, `rails db:drop`, and `rails db:migrate` were the only rails tasks that could operate on a single
1346
- database. For example:
514
+ *Donal McBreen*
1347
515
 
1348
- ```
1349
- rails db:create
1350
- rails db:create:primary
1351
- rails db:create:animals
1352
- rails db:drop
1353
- rails db:drop:primary
1354
- rails db:drop:animals
1355
- rails db:migrate
1356
- rails db:migrate:primary
1357
- rails db:migrate:animals
1358
- ```
516
+ * Deprecated `ENV["SCHEMA_CACHE"]` in favor of `schema_cache_path` in the database configuration.
1359
517
 
1360
- With these changes, `rails db:schema:dump`, `rails db:schema:load`, `rails db:structure:dump`, `rails db:structure:load` and
1361
- `rails db:test:prepare` can additionally operate on a single database. For example:
518
+ *Rafael Mendonça França*
1362
519
 
1363
- ```
1364
- rails db:schema:dump
1365
- rails db:schema:dump:primary
1366
- rails db:schema:dump:animals
1367
- rails db:schema:load
1368
- rails db:schema:load:primary
1369
- rails db:schema:load:animals
1370
- rails db:structure:dump
1371
- rails db:structure:dump:primary
1372
- rails db:structure:dump:animals
1373
- rails db:structure:load
1374
- rails db:structure:load:primary
1375
- rails db:structure:load:animals
1376
- rails db:test:prepare
1377
- rails db:test:prepare:primary
1378
- rails db:test:prepare:animals
1379
- ```
520
+ * Add `ActiveRecord::Base.with_connection` as a shortcut for leasing a connection for a short duration.
1380
521
 
1381
- *Kyle Thompson*
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.
1382
524
 
1383
- * Add support for `strict_loading` mode on association declarations.
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.
1384
527
 
1385
- Raise an error if attempting to load a record from an association that has been marked as `strict_loading` unless it was explicitly eager loaded.
528
+ *Jean Boussier*
1386
529
 
1387
- Usage:
530
+ * Deprecate `config.active_record.warn_on_records_fetched_greater_than` now that `sql.active_record`
531
+ notification includes `:row_count` field.
1388
532
 
1389
- ```ruby
1390
- class Developer < ApplicationRecord
1391
- has_many :projects, strict_loading: true
1392
- end
533
+ *Jason Nochlin*
1393
534
 
1394
- dev = Developer.first
1395
- dev.projects.first
1396
- # => ActiveRecord::StrictLoadingViolationError: The projects association is marked as strict_loading and cannot be lazily loaded.
1397
- ```
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.
1398
537
 
1399
- *Kevin Deisz*
538
+ This prevents unintentional overrides of existing join types and ensures consistency in the generated SQL queries.
1400
539
 
1401
- * Add support for `strict_loading` mode to prevent lazy loading of records.
540
+ Example:
1402
541
 
1403
- Raise an error if a parent record is marked as `strict_loading` and attempts to lazily load its associations. This is useful for finding places you may want to preload an association and avoid additional queries.
1404
542
 
1405
- Usage:
1406
543
 
1407
544
  ```ruby
1408
- dev = Developer.strict_loading.first
1409
- dev.audit_logs.to_a
1410
- # => ActiveRecord::StrictLoadingViolationError: Developer is marked as strict_loading and AuditLog cannot be lazily loaded.
545
+ # `associated` will use `LEFT JOIN` instead of using `JOIN`
546
+ Post.left_joins(:author).where.associated(:author)
1411
547
  ```
1412
548
 
1413
- *Eileen M. Uchitelle*, *Aaron Patterson*
1414
-
1415
- * Add support for PostgreSQL 11+ partitioned indexes when using `upsert_all`.
549
+ *Saleh Alhaddad*
1416
550
 
1417
- *Sebastián Palma*
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.
1418
554
 
1419
- * Adds support for `if_not_exists` to `add_column` and `if_exists` to `remove_column`.
555
+ *Maxime Réty*
1420
556
 
1421
- Applications can set their migrations to ignore exceptions raised when adding a column that already exists or when removing a column that does not exist.
1422
-
1423
- Example Usage:
557
+ * Deprecate defining an `enum` with keyword arguments.
1424
558
 
1425
559
  ```ruby
1426
- class AddColumnTitle < ActiveRecord::Migration[6.1]
1427
- def change
1428
- add_column :posts, :title, :string, if_not_exists: true
1429
- end
1430
- end
1431
- ```
560
+ class Function > ApplicationRecord
561
+ # BAD
562
+ enum color: [:red, :blue],
563
+ type: [:instance, :class]
1432
564
 
1433
- ```ruby
1434
- class RemoveColumnTitle < ActiveRecord::Migration[6.1]
1435
- def change
1436
- remove_column :posts, :title, if_exists: true
1437
- end
565
+ # GOOD
566
+ enum :color, [:red, :blue]
567
+ enum :type, [:instance, :class]
1438
568
  end
1439
569
  ```
1440
570
 
1441
- *Eileen M. Uchitelle*
571
+ *Hartley McGuire*
1442
572
 
1443
- * Regexp-escape table name for MS SQL Server.
573
+ * Add `config.active_record.validate_migration_timestamps` option for validating migration timestamps.
1444
574
 
1445
- Add `Regexp.escape` to one method in ActiveRecord, so that table names with regular expression characters in them work as expected. Since MS SQL Server uses "[" and "]" to quote table and column names, and those characters are regular expression characters, methods like `pluck` and `select` fail in certain cases when used with the MS SQL Server adapter.
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.
1446
579
 
1447
- *Larry Reid*
580
+ *Adrianna Chang*
1448
581
 
1449
- * Store advisory locks on their own named connection.
582
+ * Properly synchronize `Mysql2Adapter#active?` and `TrilogyAdapter#active?`.
1450
583
 
1451
- Previously advisory locks were taken out against a connection when a migration started. This works fine in single database applications but doesn't work well when migrations need to open new connections which results in the lock getting dropped.
584
+ As well as `disconnect!` and `verify!`.
1452
585
 
1453
- In order to fix this we are storing the advisory lock on a new connection with the connection specification name `AdvisoryLockBase`. The caveat is that we need to maintain at least 2 connections to a database while migrations are running in order to do this.
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.
1454
589
 
1455
- *Eileen M. Uchitelle*, *John Crepezzi*
1456
-
1457
- * Allow schema cache path to be defined in the database configuration file.
590
+ *Jean Boussier*
1458
591
 
1459
- For example:
592
+ * Support `:source_location` tag option for query log tags.
1460
593
 
1461
- ```yaml
1462
- development:
1463
- adapter: postgresql
1464
- database: blog_development
1465
- pool: 5
1466
- schema_cache_path: tmp/schema/main.yml
594
+ ```ruby
595
+ config.active_record.query_log_tags << :source_location
1467
596
  ```
1468
597
 
1469
- *Katrina Owen*
1470
-
1471
- * Deprecate `#remove_connection` in favor of `#remove_connection_pool` when called on the handler.
1472
-
1473
- `#remove_connection` is deprecated in order to support returning a `DatabaseConfig` object instead of a `Hash`. Use `#remove_connection_pool`, `#remove_connection` will be removed in Rails 7.0.
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.
1474
601
 
1475
- *Eileen M. Uchitelle*, *John Crepezzi*
1476
-
1477
- * Deprecate `#default_hash` and it's alias `#[]` on database configurations.
1478
-
1479
- Applications should use `configs_for`. `#default_hash` and `#[]` will be removed in Rails 7.0.
1480
-
1481
- *Eileen M. Uchitelle*, *John Crepezzi*
1482
-
1483
- * Add scale support to `ActiveRecord::Validations::NumericalityValidator`.
1484
-
1485
- *Gannon McGibbon*
1486
-
1487
- * Find orphans by looking for missing relations through chaining `where.missing`:
1488
-
1489
- Before:
602
+ *fatkodima*
1490
603
 
1491
- ```ruby
1492
- Post.left_joins(:author).where(authors: { id: nil })
1493
- ```
604
+ * Add an option to `ActiveRecord::Encryption::Encryptor` to disable compression.
1494
605
 
1495
- After:
606
+ Allow compression to be disabled by setting `compress: false`
1496
607
 
1497
608
  ```ruby
1498
- Post.where.missing(:author)
609
+ class User
610
+ encrypts :name, encryptor: ActiveRecord::Encryption::Encryptor.new(compress: false)
611
+ end
1499
612
  ```
1500
613
 
1501
- *Tom Rossi*
1502
-
1503
- * Ensure `:reading` connections always raise if a write is attempted.
1504
-
1505
- Now Rails will raise an `ActiveRecord::ReadOnlyError` if any connection on the reading handler attempts to make a write. If your reading role needs to write you should name the role something other than `:reading`.
1506
-
1507
- *Eileen M. Uchitelle*
614
+ *Donal McBreen*
1508
615
 
1509
- * Deprecate `"primary"` as the `connection_specification_name` for `ActiveRecord::Base`.
616
+ * Deprecate passing strings to `ActiveRecord::Tasks::DatabaseTasks.cache_dump_filename`.
1510
617
 
1511
- `"primary"` has been deprecated as the `connection_specification_name` for `ActiveRecord::Base` in favor of using `"ActiveRecord::Base"`. This change affects calls to `ActiveRecord::Base.connection_handler.retrieve_connection` and `ActiveRecord::Base.connection_handler.remove_connection`. If you're calling these methods with `"primary"`, please switch to `"ActiveRecord::Base"`.
618
+ A `ActiveRecord::DatabaseConfigurations::DatabaseConfig` object should be passed instead.
1512
619
 
1513
- *Eileen M. Uchitelle*, *John Crepezzi*
620
+ *Rafael Mendonça França*
1514
621
 
1515
- * Add `ActiveRecord::Validations::NumericalityValidator` with
1516
- support for casting floats using a database columns' precision value.
622
+ * Add `row_count` field to `sql.active_record` notification.
1517
623
 
1518
- *Gannon McGibbon*
624
+ This field returns the amount of rows returned by the query that emitted the notification.
1519
625
 
1520
- * Enforce fresh ETag header after a collection's contents change by adding
1521
- ActiveRecord::Relation#cache_key_with_version. This method will be used by
1522
- ActionController::ConditionalGet to ensure that when collection cache versioning
1523
- is enabled, requests using ConditionalGet don't return the same ETag header
1524
- after a collection is modified.
626
+ This metric is useful in cases where one wants to detect queries with big result sets.
1525
627
 
1526
- Fixes #38078.
628
+ *Marvin Bitterlich*
1527
629
 
1528
- *Aaron Lipman*
630
+ * Consistently raise an `ArgumentError` when passing an invalid argument to a nested attributes association writer.
1529
631
 
1530
- * Skip test database when running `db:create` or `db:drop` in development
1531
- with `DATABASE_URL` set.
632
+ Previously, this would only raise on collection associations and produce a generic error on singular associations.
1532
633
 
1533
- *Brian Buchalter*
634
+ Now, it will raise on both collection and singular associations.
1534
635
 
1535
- * Don't allow mutations on the database configurations hash.
636
+ *Joshua Young*
1536
637
 
1537
- Freeze the configurations hash to disallow directly changing it. If applications need to change the hash, for example to create databases for parallelization, they should use the `DatabaseConfig` object directly.
638
+ * Fix single quote escapes on default generated MySQL columns.
1538
639
 
1539
- Before:
640
+ MySQL 5.7.5+ supports generated columns, which can be used to create a column that is computed from an expression.
1540
641
 
1541
- ```ruby
1542
- @db_config = ActiveRecord::Base.configurations.configs_for(env_name: "test", spec_name: "primary")
1543
- @db_config.configuration_hash.merge!(idle_timeout: "0.02")
1544
- ```
642
+ Previously, the schema dump would output a string with double escapes for generated columns with single quotes in the default expression.
1545
643
 
1546
- After:
644
+ This would result in issues when importing the schema on a fresh instance of a MySQL database.
1547
645
 
1548
- ```ruby
1549
- @db_config = ActiveRecord::Base.configurations.configs_for(env_name: "test", spec_name: "primary")
1550
- config = @db_config.configuration_hash.merge(idle_timeout: "0.02")
1551
- db_config = ActiveRecord::DatabaseConfigurations::HashConfig.new(@db_config.env_name, @db_config.spec_name, config)
1552
- ```
646
+ Now, the string will not be escaped and will be valid Ruby upon importing of the schema.
1553
647
 
1554
- *Eileen M. Uchitelle*, *John Crepezzi*
648
+ *Yash Kapadia*
1555
649
 
1556
- * Remove `:connection_id` from the `sql.active_record` notification.
650
+ * Fix Migrations with versions older than 7.1 validating options given to
651
+ `add_reference` and `t.references`.
1557
652
 
1558
- *Aaron Patterson*, *Rafael Mendonça França*
653
+ *Hartley McGuire*
1559
654
 
1560
- * The `:name` key will no longer be returned as part of `DatabaseConfig#configuration_hash`. Please use `DatabaseConfig#owner_name` instead.
655
+ * Add `<role>_types` class method to `ActiveRecord::DelegatedType` so that the delegated types can be introspected.
1561
656
 
1562
- *Eileen M. Uchitelle*, *John Crepezzi*
657
+ *JP Rosevear*
1563
658
 
1564
- * ActiveRecord's `belongs_to_required_by_default` flag can now be set per model.
659
+ * Make `schema_dump`, `query_cache`, `replica` and `database_tasks` configurable via `DATABASE_URL`.
1565
660
 
1566
- You can now opt-out/opt-in specific models from having their associations required
1567
- by default.
661
+ This wouldn't always work previously because boolean values would be interpreted as strings.
1568
662
 
1569
- This change is meant to ease the process of migrating all your models to have
1570
- their association required.
663
+ e.g. `DATABASE_URL=postgres://localhost/foo?schema_dump=false` now properly disable dumping the schema
664
+ cache.
1571
665
 
1572
- *Edouard Chin*
666
+ *Mike Coutermarsh*, *Jean Boussier*
1573
667
 
1574
- * The `connection_config` method has been deprecated, please use `connection_db_config` instead which will return a `DatabaseConfigurations::DatabaseConfig` instead of a `Hash`.
668
+ * Introduce `ActiveRecord::Transactions::ClassMethods#set_callback`.
1575
669
 
1576
- *Eileen M. Uchitelle*, *John Crepezzi*
670
+ It is identical to `ActiveSupport::Callbacks::ClassMethods#set_callback`
671
+ but with support for `after_commit` and `after_rollback` callback options.
1577
672
 
1578
- * Retain explicit selections on the base model after applying `includes` and `joins`.
673
+ *Joshua Young*
1579
674
 
1580
- Resolves #34889.
675
+ * Make `ActiveRecord::Encryption::Encryptor` agnostic of the serialization format used for encrypted data.
1581
676
 
1582
- *Patrick Rebsch*
677
+ Previously, the encryptor instance only allowed an encrypted value serialized as a `String` to be passed to the message serializer.
1583
678
 
1584
- * The `database` kwarg is deprecated without replacement because it can't be used for sharding and creates an issue if it's used during a request. Applications that need to create new connections should use `connects_to` instead.
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`.
1585
680
 
1586
- *Eileen M. Uchitelle*, *John Crepezzi*
681
+ The default `ActiveRecord::Encryption::MessageSerializer` already ensures that only `String` objects are passed for deserialization.
1587
682
 
1588
- * Allow attributes to be fetched from Arel node groupings.
683
+ *Maxime Réty*
1589
684
 
1590
- *Jeff Emminger*, *Gannon McGibbon*
685
+ * Fix `encrypted_attribute?` to take into account context properties passed to `encrypts`.
1591
686
 
1592
- * A database URL can now contain a querystring value that contains an equal sign. This is needed to support passing PostgreSQL `options`.
687
+ *Maxime Réty*
1593
688
 
1594
- *Joshua Flanagan*
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:
1595
692
 
1596
- * Calling methods like `establish_connection` with a `Hash` which is invalid (eg: no `adapter`) will now raise an error the same way as connections defined in `config/database.yml`.
693
+ ```ruby
694
+ User.all.explain.count
695
+ # EXPLAIN SELECT COUNT(*) FROM `users`
696
+ # ...
1597
697
 
1598
- *John Crepezzi*
698
+ User.all.explain.maximum(:id)
699
+ # EXPLAIN SELECT MAX(`users`.`id`) FROM `users`
700
+ # ...
701
+ ```
1599
702
 
1600
- * Specifying `implicit_order_column` now subsorts the records by primary key if available to ensure deterministic results.
703
+ *Petrik de Heus*
1601
704
 
1602
- *Paweł Urbanek*
705
+ * Fixes an issue where `validates_associated` `:on` option wasn't respected
706
+ when validating associated records.
1603
707
 
1604
- * `where(attr => [])` now loads an empty result without making a query.
708
+ *Austen Madden*, *Alex Ghiculescu*, *Rafał Brize*
1605
709
 
1606
- *John Hawthorn*
710
+ * Allow overriding SQLite defaults from `database.yml`.
1607
711
 
1608
- * Fixed the performance regression for `primary_keys` introduced MySQL 8.0.
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.
1609
715
 
1610
- *Hiroyuki Ishii*
716
+ ```yaml
717
+ database: storage/development.sqlite3
718
+ timeout: 5000
719
+ pragmas:
720
+ journal_mode: off
721
+ temp_store: memory
722
+ ```
1611
723
 
1612
- * Add support for `belongs_to` to `has_many` inversing.
724
+ *Stephen Margheim*
1613
725
 
1614
- *Gannon McGibbon*
726
+ * Remove warning message when running SQLite in production, but leave it unconfigured.
1615
727
 
1616
- * Allow length configuration for `has_secure_token` method. The minimum length
1617
- is set at 24 characters.
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.
1618
732
 
1619
- Before:
733
+ *Jacopo Beschi*, *Jean Boussier*
1620
734
 
1621
- ```ruby
1622
- has_secure_token :auth_token
1623
- ```
735
+ * Add support for generated columns to the SQLite3 adapter.
1624
736
 
1625
- After:
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.
1626
739
 
1627
740
  ```ruby
1628
- has_secure_token :default_token # 24 characters
1629
- has_secure_token :auth_token, length: 36 # 36 characters
1630
- has_secure_token :invalid_token, length: 12 # => ActiveRecord::SecureToken::MinimumLengthError
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
745
+ end
1631
746
  ```
1632
747
 
1633
- *Bernardo de Araujo*
1634
-
1635
- * Deprecate `DatabaseConfigurations#to_h`. These connection hashes are still available via `ActiveRecord::Base.configurations.configs_for`.
1636
-
1637
- *Eileen Uchitelle*, *John Crepezzi*
1638
-
1639
- * Add `DatabaseConfig#configuration_hash` to return database configuration hashes with symbol keys, and use all symbol-key configuration hashes internally. Deprecate `DatabaseConfig#config` which returns a String-keyed `Hash` with the same values.
1640
-
1641
- *John Crepezzi*, *Eileen Uchitelle*
1642
-
1643
- * Allow column names to be passed to `remove_index` positionally along with other options.
1644
-
1645
- Passing other options can be necessary to make `remove_index` correctly reversible.
1646
-
1647
- Before:
1648
-
1649
- add_index :reports, :report_id # => works
1650
- add_index :reports, :report_id, unique: true # => works
1651
- remove_index :reports, :report_id # => works
1652
- remove_index :reports, :report_id, unique: true # => ArgumentError
1653
-
1654
- After:
1655
-
1656
- remove_index :reports, :report_id, unique: true # => works
748
+ *Stephen Margheim*
1657
749
 
1658
- *Eugene Kenny*
750
+ * TrilogyAdapter: ignore `host` if `socket` parameter is set.
1659
751
 
1660
- * Allow bulk `ALTER` statements to drop and recreate indexes with the same name.
752
+ This allows to configure a connection on a UNIX socket via `DATABASE_URL`:
1661
753
 
1662
- *Eugene Kenny*
1663
-
1664
- * `insert`, `insert_all`, `upsert`, and `upsert_all` now clear the query cache.
1665
-
1666
- *Eugene Kenny*
754
+ ```
755
+ DATABASE_URL=trilogy://does-not-matter/my_db_production?socket=/var/run/mysql.sock
756
+ ```
1667
757
 
1668
- * Call `while_preventing_writes` directly from `connected_to`.
758
+ *Jean Boussier*
1669
759
 
1670
- In some cases application authors want to use the database switching middleware and make explicit calls with `connected_to`. It's possible for an app to turn off writes and not turn them back on by the time we call `connected_to(role: :writing)`.
760
+ * Make `assert_queries_count`, `assert_no_queries`, `assert_queries_match`, and
761
+ `assert_no_queries_match` assertions public.
1671
762
 
1672
- This change allows apps to fix this by assuming if a role is writing we want to allow writes, except in the case it's explicitly turned off.
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.
1673
766
 
1674
- *Eileen M. Uchitelle*
767
+ ```ruby
768
+ class ArticleTest < ActiveSupport::TestCase
769
+ test "queries are made" do
770
+ assert_queries_count(1) { Article.first }
771
+ end
1675
772
 
1676
- * Improve detection of ActiveRecord::StatementTimeout with mysql2 adapter in the edge case when the query is terminated during filesort.
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
779
+ ```
1677
780
 
1678
- *Kir Shatrov*
781
+ *Petrik de Heus*, *fatkodima*
1679
782
 
1680
- * Stop trying to read yaml file fixtures when loading Active Record fixtures.
783
+ * Fix `has_secure_token` calls the setter method on initialize.
1681
784
 
1682
- *Gannon McGibbon*
785
+ *Abeid Ahmed*
1683
786
 
1684
- * Deprecate `.reorder(nil)` with `.first` / `.first!` taking non-deterministic result.
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.
1685
790
 
1686
- To continue taking non-deterministic result, use `.take` / `.take!` instead.
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
795
+ ```
1687
796
 
1688
- *Ryuta Kamizono*
797
+ *Jean Boussier*, *Kevin McPhillips*
1689
798
 
1690
- * Preserve user supplied joins order as much as possible.
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).
1691
802
 
1692
- Fixes #36761, #34328, #24281, #12953.
803
+ *Kevin McPhillips*
1693
804
 
1694
- *Ryuta Kamizono*
805
+ * `DatabaseConfigurations#configs_for` accepts a symbol in the `name` parameter.
1695
806
 
1696
- * Allow `matches_regex` and `does_not_match_regexp` on the MySQL Arel visitor.
807
+ *Andrew Novoselac*
1697
808
 
1698
- *James Pearson*
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).
1699
812
 
1700
- * Allow specifying fixtures to be ignored by setting `ignore` in YAML file's '_fixture' section.
813
+ *João Alves*
1701
814
 
1702
- *Tongfei Gao*
815
+ * Make the output of `ActiveRecord::Core#inspect` configurable.
1703
816
 
1704
- * Make the DATABASE_URL env variable only affect the primary connection. Add new env variables for multiple databases.
817
+ By default, calling `inspect` on a record will yield a formatted string including just the `id`.
1705
818
 
1706
- *John Crepezzi*, *Eileen Uchitelle*
819
+ ```ruby
820
+ Post.first.inspect #=> "#<Post id: 1>"
821
+ ```
1707
822
 
1708
- * Add a warning for enum elements with 'not_' prefix.
823
+ The attributes to be included in the output of `inspect` can be configured with
824
+ `ActiveRecord::Core#attributes_for_inspect`.
1709
825
 
1710
- class Foo
1711
- enum status: [:sent, :not_sent]
1712
- end
826
+ ```ruby
827
+ Post.attributes_for_inspect = [:id, :title]
828
+ Post.first.inspect #=> "#<Post id: 1, title: "Hello, World!">"
829
+ ```
1713
830
 
1714
- *Edu Depetris*
831
+ With `attributes_for_inspect` set to `:all`, `inspect` will list all the record's attributes.
1715
832
 
1716
- * Make currency symbols optional for money column type in PostgreSQL.
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
+ ```
1717
837
 
1718
- *Joel Schneider*
838
+ In `development` and `test` mode, `attributes_for_inspect` will be set to `:all` by default.
1719
839
 
1720
- * Add support for beginless ranges, introduced in Ruby 2.7.
840
+ You can also call `full_inspect` to get an inspection with all the attributes.
1721
841
 
1722
- *Josh Goodall*
842
+ The attributes in `attribute_for_inspect` will also be used for `pretty_print`.
1723
843
 
1724
- * Add `database_exists?` method to connection adapters to check if a database exists.
844
+ *Andrew Novoselac*
1725
845
 
1726
- *Guilherme Mansur*
846
+ * Don't mark attributes as changed when reassigned to `Float::INFINITY` or
847
+ `-Float::INFINITY`.
1727
848
 
1728
- * Loading the schema for a model that has no `table_name` raises a `TableNotSpecified` error.
849
+ *Maicol Bentancor*
1729
850
 
1730
- *Guilherme Mansur*, *Eugene Kenny*
851
+ * Support the `RETURNING` clause for MariaDB.
1731
852
 
1732
- * PostgreSQL: Fix GROUP BY with ORDER BY virtual count attribute.
853
+ *fatkodima*, *Nikolay Kondratyev*
1733
854
 
1734
- Fixes #36022.
855
+ * The SQLite3 adapter now implements the `supports_deferrable_constraints?` contract.
1735
856
 
1736
- *Ryuta Kamizono*
857
+ Allows foreign keys to be deferred by adding the `:deferrable` key to the `foreign_key` options.
1737
858
 
1738
- * Make ActiveRecord `ConnectionPool.connections` method thread-safe.
859
+ ```ruby
860
+ add_reference :person, :alias, foreign_key: { deferrable: :deferred }
861
+ add_reference :alias, :person, foreign_key: { deferrable: :deferred }
862
+ ```
1739
863
 
1740
- Fixes #36465.
864
+ *Stephen Margheim*
1741
865
 
1742
- *Jeff Doering*
866
+ * Add the `set_constraints` helper to PostgreSQL connections.
1743
867
 
1744
- * Add support for multiple databases to `rails db:abort_if_pending_migrations`.
868
+ ```ruby
869
+ Post.create!(user_id: -1) # => ActiveRecord::InvalidForeignKey
1745
870
 
1746
- *Mark Lee*
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!
877
+ end
878
+ ```
1747
879
 
1748
- * Fix sqlite3 collation parsing when using decimal columns.
880
+ *Cody Cutrer*
1749
881
 
1750
- *Martin R. Schuster*
882
+ * Include `ActiveModel::API` in `ActiveRecord::Base`.
1751
883
 
1752
- * Fix invalid schema when primary key column has a comment.
884
+ *Sean Doyle*
1753
885
 
1754
- Fixes #29966.
886
+ * Ensure `#signed_id` outputs `url_safe` strings.
1755
887
 
1756
- *Guilherme Goettems Schneider*
888
+ *Jason Meller*
1757
889
 
1758
- * Fix table comment also being applied to the primary key column.
890
+ * Add `nulls_last` and working `desc.nulls_first` for MySQL.
1759
891
 
1760
- *Guilherme Goettems Schneider*
892
+ *Tristan Fellows*
1761
893
 
1762
- * Allow generated `create_table` migrations to include or skip timestamps.
894
+ * Allow for more complex hash arguments for `order` which mimics `where` in `ActiveRecord::Relation`.
1763
895
 
1764
- *Michael Duchemin*
896
+ ```ruby
897
+ Topic.includes(:posts).order(posts: { created_at: :desc })
898
+ ```
1765
899
 
900
+ *Myles Boone*
1766
901
 
1767
- Please check [6-0-stable](https://github.com/rails/rails/blob/6-0-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.