activerecord 6.1.7 → 7.2.2

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 (333) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +616 -1290
  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 +19 -8
  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 +30 -27
  30. data/lib/active_record/associations/join_dependency.rb +28 -20
  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 +429 -522
  40. data/lib/active_record/asynchronous_queries_tracker.rb +60 -0
  41. data/lib/active_record/attribute_assignment.rb +1 -5
  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 +15 -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 +57 -54
  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 +19 -35
  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 +325 -604
  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 +230 -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 +378 -143
  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 +348 -165
  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 +403 -77
  108. data/lib/active_record/connection_adapters/postgresql/utils.rb +9 -10
  109. data/lib/active_record/connection_adapters/postgresql_adapter.rb +520 -253
  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 +310 -253
  125. data/lib/active_record/counter_cache.rb +68 -34
  126. data/lib/active_record/database_configurations/connection_url_resolver.rb +10 -4
  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 +58 -0
  165. data/lib/active_record/enum.rb +170 -62
  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 +59 -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 +145 -158
  199. data/lib/active_record/nested_attributes.rb +61 -23
  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 +18 -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 +229 -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 +332 -103
  214. data/lib/active_record/relation/batches/batch_enumerator.rb +38 -9
  215. data/lib/active_record/relation/batches.rb +200 -65
  216. data/lib/active_record/relation/calculations.rb +301 -112
  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 +870 -163
  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 +6 -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 +288 -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 +65 -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/sqlite.rb +25 -0
  317. data/lib/arel/visitors/to_sql.rb +170 -36
  318. data/lib/arel/visitors/visitor.rb +2 -2
  319. data/lib/arel.rb +23 -4
  320. data/lib/rails/generators/active_record/application_record/USAGE +8 -0
  321. data/lib/rails/generators/active_record/application_record/templates/application_record.rb.tt +1 -1
  322. data/lib/rails/generators/active_record/migration/templates/create_table_migration.rb.tt +4 -1
  323. data/lib/rails/generators/active_record/migration.rb +3 -1
  324. data/lib/rails/generators/active_record/model/USAGE +113 -0
  325. data/lib/rails/generators/active_record/model/model_generator.rb +15 -6
  326. data/lib/rails/generators/active_record/model/templates/abstract_base_class.rb.tt +1 -1
  327. data/lib/rails/generators/active_record/model/templates/model.rb.tt +1 -1
  328. data/lib/rails/generators/active_record/model/templates/module.rb.tt +2 -2
  329. data/lib/rails/generators/active_record/multi_db/multi_db_generator.rb +16 -0
  330. data/lib/rails/generators/active_record/multi_db/templates/multi_db.rb.tt +44 -0
  331. metadata +103 -17
  332. data/lib/active_record/connection_adapters/legacy_pool_manager.rb +0 -35
  333. data/lib/active_record/null_relation.rb +0 -67
data/CHANGELOG.md CHANGED
@@ -1,1767 +1,1093 @@
1
- ## Rails 6.1.7 (September 09, 2022) ##
1
+ ## Rails 7.2.2 (October 30, 2024) ##
2
2
 
3
- * Symbol is allowed by default for YAML columns
3
+ * Fix support for `query_cache: false` in `database.yml`.
4
4
 
5
- *Étienne Barrié*
5
+ `query_cache: false` would no longer entirely disable the Active Record query cache.
6
6
 
7
- * Fix `ActiveRecord::Store` to serialize as a regular Hash
7
+ *zzak*
8
8
 
9
- Previously it would serialize as an `ActiveSupport::HashWithIndifferentAccess`
10
- which is wasteful and cause problem with YAML safe_load.
9
+ * Set `.attributes_for_inspect` to `:all` by default.
11
10
 
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
- ```
11
+ For new applications it is set to `[:id]` in config/environment/production.rb.
44
12
 
45
- [CVE-2022-32224]
13
+ In the console all the attributes are always shown.
46
14
 
15
+ *Andrew Novoselac*
47
16
 
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.
17
+ * `PG::UnableToSend: no connection to the server` is now retryable as a connection-related exception
56
18
 
19
+ *Kazuma Watanabe*
57
20
 
58
- ## Rails 6.1.5 (March 09, 2022) ##
21
+ * Fix marshalling of unsaved associated records in 7.1 format.
59
22
 
60
- * Fix `ActiveRecord::ConnectionAdapters::SchemaCache#deep_deduplicate` for Ruby 2.6.
23
+ The 7.1 format would only marshal associated records if the association was loaded.
24
+ But associations that would only contain unsaved records would be skipped.
61
25
 
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.
26
+ *Jean Boussier*
71
27
 
72
- Fixes #43056
28
+ * Fix incorrect SQL query when passing an empty hash to `ActiveRecord::Base.insert`.
73
29
 
74
- *Eric O'Hanlon*
30
+ *David Stosik*
75
31
 
76
- * Fix migration compatibility to create SQLite references/belongs_to column as integer when
77
- migration version is 6.0.
32
+ * Allow to save records with polymorphic join tables that have `inverse_of`
33
+ specified.
78
34
 
79
- `reference`/`belongs_to` in migrations with version 6.0 were creating columns as
80
- bigint instead of integer for the SQLite Adapter.
35
+ *Markus Doits*
81
36
 
82
- *Marcelo Lauxen*
37
+ * Fix association scopes applying on the incorrect join when using a polymorphic `has_many through:`.
83
38
 
84
- * Fix dbconsole for 3-tier config.
39
+ *Joshua Young*
85
40
 
86
- *Eileen M. Uchitelle*
41
+ * Fix `dependent: :destroy` for bi-directional has one through association.
87
42
 
88
- * Better handle SQL queries with invalid encoding.
43
+ Fixes #50948.
89
44
 
90
45
  ```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*
46
+ class Left < ActiveRecord::Base
47
+ has_one :middle, dependent: :destroy
48
+ has_one :right, through: :middle
49
+ end
105
50
 
106
- * Fix regression bug that caused ignoring additional conditions for preloading
107
- `has_many` through relations.
51
+ class Middle < ActiveRecord::Base
52
+ belongs_to :left, dependent: :destroy
53
+ belongs_to :right, dependent: :destroy
54
+ end
108
55
 
109
- Fixes #43132
56
+ class Right < ActiveRecord::Base
57
+ has_one :middle, dependent: :destroy
58
+ has_one :left, through: :middle
59
+ end
60
+ ```
61
+ In the above example `left.destroy` wouldn't destroy its associated `Right`
62
+ record.
110
63
 
111
- *Alexander Pauly*
64
+ *Andy Stewart*
112
65
 
113
- * Fix `ActiveRecord::InternalMetadata` to not be broken by
114
- `config.active_record.record_timestamps = false`
66
+ * Properly handle lazily pinned connection pools.
115
67
 
116
- Since the model always create the timestamp columns, it has to set them, otherwise it breaks
117
- various DB management tasks.
68
+ Fixes #53147.
118
69
 
119
- Fixes #42983
70
+ When using transactional fixtures with system tests to similar tools
71
+ such as capybara, it could happen that a connection end up pinned by the
72
+ server thread rather than the test thread, causing
73
+ `"Cannot expire connection, it is owned by a different thread"` errors.
120
74
 
121
75
  *Jean Boussier*
122
76
 
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*
77
+ * Fix `ActiveRecord::Base.with` to accept more than two sub queries.
132
78
 
133
- * Fix performance regression in `CollectionAssocation#build`.
79
+ Fixes #53110.
134
80
 
135
- *Alex Ghiculescu*
81
+ ```ruby
82
+ User.with(foo: [User.select(:id), User.select(:id), User.select(:id)]).to_sql
83
+ undefined method `union' for an instance of Arel::Nodes::UnionAll (NoMethodError)
84
+ ```
136
85
 
137
- * Fix retrieving default value for text column for MariaDB.
86
+ The above now works as expected.
138
87
 
139
88
  *fatkodima*
140
89
 
90
+ * Properly release pinned connections with non joinable connections.
141
91
 
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`.
92
+ Fixes #52973
180
93
 
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.
94
+ When running system tests with transactional fixtures on, it could happen that
95
+ the connection leased by the Puma thread wouldn't be properly released back to the pool,
96
+ causing "Cannot expire connection, it is owned by a different thread" errors in later tests.
191
97
 
192
98
  *Jean Boussier*
193
99
 
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.
100
+ * Make Float distinguish between `float4` and `float8` in PostgreSQL.
203
101
 
204
- *Bastian Bartmann*
102
+ Fixes #52742
205
103
 
206
- * Fix user-defined `self.default_scope` to respect table alias.
104
+ *Ryota Kitazawa*, *Takayuki Nagatomi*
207
105
 
208
- *Ryuta Kamizono*
106
+ * Fix an issue where `.left_outer_joins` used with multiple associations that have
107
+ the same child association but different parents does not join all parents.
209
108
 
210
- * Clear `@cache_keys` cache after `update_all`, `delete_all`, `destroy_all`.
109
+ Previously, using `.left_outer_joins` with the same child association would only join one of the parents.
211
110
 
212
- *Ryuta Kamizono*
111
+ Now it will correctly join both parents.
213
112
 
214
- * Changed Arel predications `contains` and `overlaps` to use
215
- `quoted_node` so that PostgreSQL arrays are quoted properly.
113
+ Fixes #41498.
216
114
 
217
- *Bradley Priest*
115
+ *Garrett Blehm*
218
116
 
219
- * Fix `merge` when the `where` clauses have string contents.
117
+ * Ensure `ActiveRecord::Encryption.config` is always ready before access.
220
118
 
221
- *Ryuta Kamizono*
119
+ Previously, `ActiveRecord::Encryption` configuration was deferred until `ActiveRecord::Base`
120
+ was loaded. Therefore, accessing `ActiveRecord::Encryption.config` properties before
121
+ `ActiveRecord::Base` was loaded would give incorrect results.
222
122
 
223
- * Fix rollback of parent destruction with nested `dependent: :destroy`.
123
+ `ActiveRecord::Encryption` now has its own loading hook so that its configuration is set as
124
+ soon as needed.
224
125
 
225
- *Jacopo Beschi*
126
+ When `ActiveRecord::Base` is loaded, even lazily, it in turn triggers the loading of
127
+ `ActiveRecord::Encryption`, thus preserving the original behavior of having its config ready
128
+ before any use of `ActiveRecord::Base`.
226
129
 
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
- ```
130
+ *Maxime Réty*
244
131
 
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.
132
+ * Add `TimeZoneConverter#==` method, so objects will be properly compared by
133
+ their type, scale, limit & precision.
251
134
 
252
- *Eileen M. Uchitelle*, *Radamés Roriz*
135
+ Address #52699.
253
136
 
254
- * Fix numericality validator without precision.
137
+ *Ruy Rocha*
255
138
 
256
- *Ryuta Kamizono*
257
139
 
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) ##
140
+ ## Rails 7.2.1.2 (October 23, 2024) ##
276
141
 
277
142
  * No changes.
278
143
 
279
144
 
280
- ## Rails 6.1.3.1 (March 26, 2021) ##
145
+ ## Rails 7.2.1.1 (October 15, 2024) ##
281
146
 
282
147
  * No changes.
283
148
 
284
149
 
285
- ## Rails 6.1.3 (February 17, 2021) ##
150
+ ## Rails 7.2.1 (August 22, 2024) ##
286
151
 
287
- * Fix the MySQL adapter to always set the right collation and charset
288
- to the connection session.
152
+ * Fix detection for `enum` columns with parallelized tests and PostgreSQL.
289
153
 
290
154
  *Rafael Mendonça França*
291
155
 
292
- * Fix MySQL adapter handling of time objects when prepared statements
293
- are enabled.
156
+ * Allow to eager load nested nil associations.
294
157
 
295
- *Rafael Mendonça França*
158
+ *fatkodima*
296
159
 
297
- * Fix scoping in enum fields using conditions that would generate
298
- an `IN` clause.
160
+ * Fix swallowing ignore order warning when batching using `BatchEnumerator`.
299
161
 
300
- *Ryuta Kamizono*
162
+ *fatkodima*
301
163
 
302
- * Skip optimised #exist? query when #include? is called on a relation
303
- with a having clause
164
+ * Fix memory bloat on the connection pool when using the Fiber `IsolatedExecutionState`.
304
165
 
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.
166
+ *Jean Boussier*
314
167
 
315
- An sample query affected by this problem:
168
+ * Restore inferred association class with the same modularized name.
316
169
 
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
- ```
170
+ *Justin Ko*
324
171
 
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.
172
+ * Fix `ActiveRecord::Base.inspect` to properly explain how to load schema information.
328
173
 
329
- Fixes #41417
174
+ *Jean Boussier*
330
175
 
331
- *Michael Smart*
176
+ * Check invalid `enum` options for the new syntax.
332
177
 
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.
178
+ The options using `_` prefix in the old syntax are invalid in the new syntax.
336
179
 
337
- *wbharding*, *Martin Tepper*
180
+ *Rafael Mendonça França*
338
181
 
182
+ * Fix `ActiveRecord::Encryption::EncryptedAttributeType#type` to return
183
+ actual cast type.
339
184
 
340
- ## Rails 6.1.2.1 (February 10, 2021) ##
185
+ *Vasiliy Ermolovich*
341
186
 
342
- * Fix possible DoS vector in PostgreSQL money type
187
+ * Fix `create_table` with `:auto_increment` option for MySQL adapter.
343
188
 
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.
189
+ *fatkodima*
347
190
 
348
- Thanks to @dee-see from Hackerone for this patch!
349
191
 
350
- [CVE-2021-22880]
192
+ ## Rails 7.2.0 (August 09, 2024) ##
351
193
 
352
- *Aaron Patterson*
194
+ * Handle commas in Sqlite3 default function definitions.
353
195
 
196
+ *Stephen Margheim*
354
197
 
355
- ## Rails 6.1.2 (February 09, 2021) ##
198
+ * Fixes `validates_associated` raising an exception when configured with a
199
+ singular association and having `index_nested_attribute_errors` enabled.
356
200
 
357
- * Fix timestamp type for sqlite3.
201
+ *Martin Spickermann*
358
202
 
359
- *Eileen M. Uchitelle*
203
+ * The constant `ActiveRecord::ImmutableRelation` has been deprecated because
204
+ we want to reserve that name for a stronger sense of "immutable relation".
205
+ Please use `ActiveRecord::UnmodifiableRelation` instead.
360
206
 
361
- * Make destroy async transactional.
207
+ *Xavier Noria*
362
208
 
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.
209
+ * Add condensed `#inspect` for `ConnectionPool`, `AbstractAdapter`, and
210
+ `DatabaseConfig`.
366
211
 
367
- Now the jobs are only enqueued until after the db transaction has been committed.
212
+ *Hartley McGuire*
368
213
 
369
- *Cory Gwin*
214
+ * Fixed a memory performance issue in Active Record attribute methods definition.
370
215
 
371
- * Fix malformed packet error in MySQL statement for connection configuration.
216
+ *Jean Boussier*
372
217
 
373
- *robinroestenburg*
218
+ * Define the new Active Support notification event `start_transaction.active_record`.
374
219
 
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.
220
+ This event is fired when database transactions or savepoints start, and
221
+ complements `transaction.active_record`, which is emitted when they finish.
379
222
 
380
- Fixes #41137.
223
+ The payload has the transaction (`:transaction`) and the connection (`:connection`).
381
224
 
382
- *Jonathan Bracy*
225
+ *Xavier Noria*
383
226
 
384
- * Fix granular connection swapping when there are multiple abstract classes.
227
+ * Fix an issue where the IDs reader method did not return expected results
228
+ for preloaded associations in models using composite primary keys.
385
229
 
386
- *Eileen M. Uchitelle*
230
+ *Jay Ang*
387
231
 
388
- * Fix `find_by` with custom primary key for belongs_to association.
232
+ * The payload of `sql.active_record` Active Support notifications now has the current transaction in the `:transaction` key.
389
233
 
390
- *Ryuta Kamizono*
234
+ *Xavier Noria*
391
235
 
392
- * Add support for `rails console --sandbox` for multiple database applications.
236
+ * The payload of `transaction.active_record` Active Support notifications now has the transaction the event is related to in the `:transaction` key.
393
237
 
394
- *alpaca-tc*
238
+ *Xavier Noria*
395
239
 
396
- * Fix `where` on polymorphic association with empty array.
240
+ * Define `ActiveRecord::Transaction#uuid`, which returns a UUID for the database transaction. This may be helpful when tracing database activity. These UUIDs are generated only on demand.
397
241
 
398
- *Ryuta Kamizono*
242
+ *Xavier Noria*
399
243
 
400
- * Fix preventing writes for `ApplicationRecord`.
244
+ * Fix inference of association model on nested models with the same demodularized name.
401
245
 
402
- *Eileen M. Uchitelle*
246
+ E.g. with the following setup:
403
247
 
248
+ ```ruby
249
+ class Nested::Post < ApplicationRecord
250
+ has_one :post, through: :other
251
+ end
252
+ ```
404
253
 
405
- ## Rails 6.1.1 (January 07, 2021) ##
254
+ Before, `#post` would infer the model as `Nested::Post`, but now it correctly infers `Post`.
406
255
 
407
- * Fix fixtures loading when strict loading is enabled for the association.
256
+ *Joshua Young*
408
257
 
409
- *Alex Ghiculescu*
258
+ * PostgreSQL `Cidr#change?` detects the address prefix change.
410
259
 
411
- * Fix `where` with custom primary key for belongs_to association.
260
+ *Taketo Takashima*
412
261
 
413
- *Ryuta Kamizono*
262
+ * Change `BatchEnumerator#destroy_all` to return the total number of affected rows.
414
263
 
415
- * Fix `where` with aliased associations.
264
+ Previously, it always returned `nil`.
416
265
 
417
- *Ryuta Kamizono*
266
+ *fatkodima*
418
267
 
419
- * Fix `composed_of` with symbol mapping.
268
+ * Support `touch_all` in batches.
420
269
 
421
- *Ryuta Kamizono*
270
+ ```ruby
271
+ Post.in_batches.touch_all
272
+ ```
422
273
 
423
- * Don't skip money's type cast for pluck and calculations.
274
+ *fatkodima*
424
275
 
425
- *Ryuta Kamizono*
276
+ * Add support for `:if_not_exists` and `:force` options to `create_schema`.
426
277
 
427
- * Fix `where` on polymorphic association with non Active Record object.
278
+ *fatkodima*
428
279
 
429
- *Ryuta Kamizono*
280
+ * Fix `index_errors` having incorrect index in association validation errors.
430
281
 
431
- * Make sure `db:prepare` works even the schema file doesn't exist.
282
+ *lulalala*
432
283
 
433
- *Rafael Mendonça França*
284
+ * Add `index_errors: :nested_attributes_order` mode.
434
285
 
435
- * Fix complicated `has_many :through` with nested where condition.
286
+ This indexes the association validation errors based on the order received by nested attributes setter, and respects the `reject_if` configuration. This enables API to provide enough information to the frontend to map the validation errors back to their respective form fields.
436
287
 
437
- *Ryuta Kamizono*
288
+ *lulalala*
438
289
 
439
- * Handle STI models for `has_many dependent: :destroy_async`.
290
+ * Add `Rails.application.config.active_record.postgresql_adapter_decode_dates` to opt out of decoding dates automatically with the postgresql adapter. Defaults to true.
440
291
 
441
- *Muhammad Usman*
292
+ *Joé Dupuis*
442
293
 
443
- * Restore possibility of passing `false` to :polymorphic option of `belongs_to`.
294
+ * Association option `query_constraints` is deprecated in favor of `foreign_key`.
444
295
 
445
- Previously, passing `false` would trigger the option validation logic
446
- to throw an error saying :polymorphic would not be a valid option.
296
+ *Nikita Vasilevsky*
447
297
 
448
- *glaszig*
298
+ * Add `ENV["SKIP_TEST_DATABASE_TRUNCATE"]` flag to speed up multi-process test runs on large DBs when all tests run within default transaction.
449
299
 
450
- * Allow adding nonnamed expression indexes to be revertible.
300
+ This cuts ~10s from the test run of HEY when run by 24 processes against the 178 tables, since ~4,000 table truncates can then be skipped.
451
301
 
452
- Fixes #40732.
302
+ *DHH*
453
303
 
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.
304
+ * Added support for recursive common table expressions.
457
305
 
458
306
  ```ruby
459
- add_index(:items, "to_tsvector('english', description)")
307
+ Post.with_recursive(
308
+ post_and_replies: [
309
+ Post.where(id: 42),
310
+ Post.joins('JOIN post_and_replies ON posts.in_reply_to_id = post_and_replies.id'),
311
+ ]
312
+ )
460
313
  ```
461
314
 
462
- *fatkodima*
315
+ Generates the following SQL:
463
316
 
317
+ ```sql
318
+ WITH RECURSIVE "post_and_replies" AS (
319
+ (SELECT "posts".* FROM "posts" WHERE "posts"."id" = 42)
320
+ UNION ALL
321
+ (SELECT "posts".* FROM "posts" JOIN post_and_replies ON posts.in_reply_to_id = post_and_replies.id)
322
+ )
323
+ SELECT "posts".* FROM "posts"
324
+ ```
464
325
 
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*
326
+ *ClearlyClaire*
482
327
 
483
- * Build predicate conditions with objects that delegate `#id` and primary key:
328
+ * `validate_constraint` can be called in a `change_table` block.
484
329
 
330
+ ex:
485
331
  ```ruby
486
- class AdminAuthor
487
- delegate_missing_to :@author
488
-
489
- def initialize(author)
490
- @author = author
491
- end
332
+ change_table :products do |t|
333
+ t.check_constraint "price > discounted_price", name: "price_check", validate: false
334
+ t.validate_check_constraint "price_check"
492
335
  end
493
-
494
- Post.where(author: AdminAuthor.new(author))
495
336
  ```
496
337
 
497
- *Sean Doyle*
498
-
499
- * Add `connected_to_many` API.
338
+ *Cody Cutrer*
500
339
 
501
- This API allows applications to connect to multiple databases at once without switching all of them or implementing a deeply nested stack.
340
+ * `PostgreSQLAdapter` now decodes columns of type date to `Date` instead of string.
502
341
 
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:
342
+ Ex:
343
+ ```ruby
344
+ ActiveRecord::Base.connection
345
+ .select_value("select '2024-01-01'::date").class #=> Date
346
+ ```
598
347
 
599
- User.where(name: "John").create do |john|
600
- User.find_by(name: "David") # => #<User name: "David", ...>
601
- end
348
+ *Joé Dupuis*
602
349
 
603
- *Ryuta Kamizono*
350
+ * Strict loading using `:n_plus_one_only` does not eagerly load child associations.
604
351
 
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
352
+ With this change, child associations are no longer eagerly loaded, to
353
+ match intended behavior and to prevent non-deterministic order issues caused
354
+ by calling methods like `first` or `last`. As `first` and `last` don't cause
355
+ an N+1 by themselves, calling child associations will no longer raise.
356
+ Fixes #49473.
610
357
 
611
358
  Before:
612
359
 
613
- User.where(name: "John").david
614
- # SELECT * FROM users WHERE name = 'John' AND name = 'David'
360
+ ```ruby
361
+ person = Person.find(1)
362
+ person.strict_loading!(mode: :n_plus_one_only)
363
+ person.posts.first
364
+ # SELECT * FROM posts WHERE person_id = 1; -- non-deterministic order
365
+ person.posts.first.firm # raises ActiveRecord::StrictLoadingViolationError
366
+ ```
615
367
 
616
368
  After:
617
369
 
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.
370
+ ```ruby
371
+ person = Person.find(1)
372
+ person.strict_loading!(mode: :n_plus_one_only)
373
+ person.posts.first # this is 1+1, not N+1
374
+ # SELECT * FROM posts WHERE person_id = 1 ORDER BY id LIMIT 1;
375
+ person.posts.first.firm # no longer raises
376
+ ```
648
377
 
649
- *Rafael Mendonça França*
378
+ *Reid Lynch*
650
379
 
651
- * Deprecate `ActiveRecord::Base.allow_unsafe_raw_sql`.
380
+ * Allow `Sqlite3Adapter` to use `sqlite3` gem version `2.x`.
652
381
 
653
- *Rafael Mendonça França*
382
+ *Mike Dalessio*
654
383
 
655
- * Remove deprecated support for using unsafe raw SQL in `ActiveRecord::Relation` methods.
384
+ * Allow `ActiveRecord::Base#pluck` to accept hash values.
656
385
 
657
- *Rafael Mendonça França*
386
+ ```ruby
387
+ # Before
388
+ Post.joins(:comments).pluck("posts.id", "comments.id", "comments.body")
658
389
 
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`.
390
+ # After
391
+ Post.joins(:comments).pluck(posts: [:id], comments: [:id, :body])
392
+ ```
661
393
 
662
- *Omri Gabay*
394
+ *fatkodima*
663
395
 
664
- * Connections can be granularly switched for abstract classes when `connected_to` is called.
396
+ * Raise an `ActiveRecord::ActiveRecordError` error when the MySQL database returns an invalid version string.
665
397
 
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.
398
+ *Kevin McPhillips*
667
399
 
668
- Example usage:
400
+ * `ActiveRecord::Base.transaction` now yields an `ActiveRecord::Transaction` object.
669
401
 
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`.
402
+ This allows to register callbacks on it.
671
403
 
672
404
  ```ruby
673
- ActiveRecord::Base.connected_to(role: :reading) do
674
- User.first # reads from default replica
675
- Dog.first # reads from default replica
676
-
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
681
-
682
- User.first # reads from default replica
683
- Dog.first # reads from default replica
684
-
685
- ApplicationRecord.connected_to(role: :writing, shard: :two) do
686
- User.first # reads from shard two primary
687
- Dog.first # reads from default replica
405
+ Article.transaction do |transaction|
406
+ article.update(published: true)
407
+ transaction.after_commit do
408
+ PublishNotificationMailer.with(article: article).deliver_later
688
409
  end
689
410
  end
690
411
  ```
691
412
 
692
- *Eileen M. Uchitelle*, *John Crepezzi*
693
-
694
- * Allow double-dash comment syntax when querying read-only databases
695
-
696
- *James Adam*
413
+ *Jean Boussier*
697
414
 
698
- * Add `values_at` method.
415
+ * Add `ActiveRecord::Base.current_transaction`.
699
416
 
700
- Returns an array containing the values associated with the given methods.
417
+ Returns the current transaction, to allow registering callbacks on it.
701
418
 
702
419
  ```ruby
703
- topic = Topic.first
704
- topic.values_at(:title, :author_name)
705
- # => ["Budget", "Jason"]
420
+ Article.current_transaction.after_commit do
421
+ PublishNotificationMailer.with(article: article).deliver_later
422
+ end
706
423
  ```
707
424
 
708
- Similar to `Hash#values_at` but on an Active Record instance.
709
-
710
- *Guillaume Briday*
711
-
712
- * Fix `read_attribute_before_type_cast` to consider attribute aliases.
425
+ *Jean Boussier*
713
426
 
714
- *Marcelo Lauxen*
427
+ * Add `ActiveRecord.after_all_transactions_commit` callback.
715
428
 
716
- * Support passing record to uniqueness validator `:conditions` callable:
429
+ Useful for code that may run either inside or outside a transaction and needs
430
+ to perform work after the state changes have been properly persisted.
717
431
 
718
432
  ```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
- }
433
+ def publish_article(article)
434
+ article.update(published: true)
435
+ ActiveRecord.after_all_transactions_commit do
436
+ PublishNotificationMailer.with(article: article).deliver_later
437
+ end
724
438
  end
725
439
  ```
726
440
 
727
- *Eliot Sykes*
441
+ In the above example, the block is either executed immediately if called outside
442
+ of a transaction, or called after the open transaction is committed.
728
443
 
729
- * `BatchEnumerator#update_all` and `BatchEnumerator#delete_all` now return the
730
- total number of rows affected, just like their non-batched counterparts.
444
+ If the transaction is rolled back, the block isn't called.
731
445
 
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:
748
-
749
- attribute :duration, :interval
750
-
751
- To keep old behavior until 7.0 is released:
752
-
753
- attribute :duration, :string
754
-
755
- Example:
756
-
757
- create_table :events do |t|
758
- t.string :name
759
- t.interval :duration
760
- end
761
-
762
- class Event < ApplicationRecord
763
- attribute :duration, :interval
764
- end
446
+ *Jean Boussier*
765
447
 
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
448
+ * Add the ability to ignore counter cache columns until they are backfilled.
771
449
 
772
- *Andrey Novikov*
450
+ Starting to use counter caches on existing large tables can be troublesome, because the column
451
+ values must be backfilled separately of the column addition (to not lock the table for too long)
452
+ and before the use of `:counter_cache` (otherwise methods like `size`/`any?`/etc, which use
453
+ counter caches internally, can produce incorrect results). People usually use database triggers
454
+ or callbacks on child associations while backfilling before introducing a counter cache
455
+ configuration to the association.
773
456
 
774
- * Allow associations supporting the `dependent:` key to take `dependent: :destroy_async`.
457
+ Now, to safely backfill the column, while keeping the column updated with child records added/removed, use:
775
458
 
776
459
  ```ruby
777
- class Account < ActiveRecord::Base
778
- belongs_to :supplier, dependent: :destroy_async
460
+ class Comment < ApplicationRecord
461
+ belongs_to :post, counter_cache: { active: false }
779
462
  end
780
463
  ```
781
464
 
782
- `:destroy_async` will enqueue a job to destroy associated records in the background.
465
+ While the counter cache is not "active", the methods like `size`/`any?`/etc will not use it,
466
+ but get the results directly from the database. After the counter cache column is backfilled, simply
467
+ remove the `{ active: false }` part from the counter cache definition, and it will now be used by the
468
+ mentioned methods.
783
469
 
784
- *DHH*, *George Claghorn*, *Cory Gwin*, *Rafael Mendonça França*, *Adrianna Chang*
470
+ *fatkodima*
785
471
 
786
- * Add `SKIP_TEST_DATABASE` environment variable to disable modifying the test database when `rails db:create` and `rails db:drop` are called.
472
+ * Retry known idempotent SELECT queries on connection-related exceptions.
787
473
 
788
- *Jason Schweier*
474
+ SELECT queries we construct by walking the Arel tree and / or with known model attributes
475
+ are idempotent and can safely be retried in the case of a connection error. Previously,
476
+ adapters such as `TrilogyAdapter` would raise `ActiveRecord::ConnectionFailed: Trilogy::EOFError`
477
+ when encountering a connection error mid-request.
789
478
 
790
- * `connects_to` can only be called on `ActiveRecord::Base` or abstract classes.
479
+ *Adrianna Chang*
791
480
 
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.
481
+ * Allow association's `foreign_key` to be composite.
793
482
 
794
- *Eileen M. Uchitelle*, *John Crepezzi*
483
+ `query_constraints` option was the only way to configure a composite foreign key by passing an `Array`.
484
+ Now it's possible to pass an Array value as `foreign_key` to achieve the same behavior of an association.
795
485
 
796
- * All connection adapters `execute` now raises `ActiveRecord::ConnectionNotEstablished` rather than
797
- `ActiveRecord::StatementInvalid` when they encounter a connection error.
486
+ *Nikita Vasilevsky*
798
487
 
799
- *Jean Boussier*
488
+ * Allow association's `primary_key` to be composite.
800
489
 
801
- * `Mysql2Adapter#quote_string` now raises `ActiveRecord::ConnectionNotEstablished` rather than
802
- `ActiveRecord::StatementInvalid` when it can't connect to the MySQL server.
490
+ Association's `primary_key` can be composite when derived from associated model `primary_key` or `query_constraints`.
491
+ Now it's possible to explicitly set it as composite on the association.
803
492
 
804
- *Jean Boussier*
493
+ *Nikita Vasilevsky*
805
494
 
806
- * Add support for check constraints that are `NOT VALID` via `validate: false` (PostgreSQL-only).
495
+ * Add `config.active_record.permanent_connection_checkout` setting.
807
496
 
808
- *Alex Robbin*
497
+ Controls whether `ActiveRecord::Base.connection` raises an error, emits a deprecation warning, or neither.
809
498
 
810
- * Ensure the default configuration is considered primary or first for an environment
499
+ `ActiveRecord::Base.connection` checkouts a database connection from the pool and keeps it leased until the end of
500
+ the request or job. This behavior can be undesirable in environments that use many more threads or fibers than there
501
+ is available connections.
811
502
 
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.
503
+ This configuration can be used to track down and eliminate code that calls `ActiveRecord::Base.connection` and
504
+ migrate it to use `ActiveRecord::Base.with_connection` instead.
813
505
 
814
- *Eileen M. Uchitelle*
506
+ The default behavior remains unchanged, and there is currently no plans to change the default.
815
507
 
816
- * Allow `where` references association names as joined table name aliases.
508
+ *Jean Boussier*
817
509
 
818
- ```ruby
819
- class Comment < ActiveRecord::Base
820
- enum label: [:default, :child]
821
- has_many :children, class_name: "Comment", foreign_key: :parent_id
822
- end
510
+ * Add dirties option to uncached.
823
511
 
824
- # ... FROM comments LEFT OUTER JOIN comments children ON ... WHERE children.label = 1
825
- Comment.includes(:children).where("children.label": "child")
826
- ```
512
+ This adds a `dirties` option to `ActiveRecord::Base.uncached` and
513
+ `ActiveRecord::ConnectionAdapters::ConnectionPool#uncached`.
827
514
 
828
- *Ryuta Kamizono*
515
+ When set to `true` (the default), writes will clear all query caches belonging to the current thread.
516
+ When set to `false`, writes to the affected connection pool will not clear any query cache.
829
517
 
830
- * Support storing demodulized class name for polymorphic type.
518
+ This is needed by Solid Cache so that cache writes do not clear query caches.
831
519
 
832
- Before Rails 6.1, storing demodulized class name is supported only for STI type
833
- by `store_full_sti_class` class attribute.
520
+ *Donal McBreen*
834
521
 
835
- Now `store_full_class_name` class attribute can handle both STI and polymorphic types.
522
+ * Deprecate `ActiveRecord::Base.connection` in favor of `.lease_connection`.
836
523
 
837
- *Ryuta Kamizono*
524
+ The method has been renamed as `lease_connection` to better reflect that the returned
525
+ connection will be held for the duration of the request or job.
838
526
 
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.
527
+ This deprecation is a soft deprecation, no warnings will be issued and there is no
528
+ current plan to remove the method.
842
529
 
843
- *fatkodima*
530
+ *Jean Boussier*
844
531
 
845
- * Respect the `select` values for eager loading.
532
+ * Deprecate `ActiveRecord::ConnectionAdapters::ConnectionPool#connection`.
846
533
 
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
861
- ```
534
+ The method has been renamed as `lease_connection` to better reflect that the returned
535
+ connection will be held for the duration of the request or job.
862
536
 
863
- *Ryuta Kamizono*
537
+ *Jean Boussier*
864
538
 
865
- * Allow attribute's default to be configured but keeping its own type.
539
+ * Expose a generic fixture accessor for fixture names that may conflict with Minitest.
866
540
 
867
541
  ```ruby
868
- class Post < ActiveRecord::Base
869
- attribute :written_at, default: -> { Time.now.utc }
870
- 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, ...>
542
+ assert_equal "Ruby on Rails", web_sites(:rubyonrails).name
543
+ assert_equal "Ruby on Rails", fixture(:web_sites, :rubyonrails).name
877
544
  ```
878
545
 
879
- *Ryuta Kamizono*
546
+ *Jean Boussier*
880
547
 
881
- * Allow default to be configured for Enum.
548
+ * Using `Model.query_constraints` with a single non-primary-key column used to raise as expected, but with an
549
+ incorrect error message.
882
550
 
883
- ```ruby
884
- class Book < ActiveRecord::Base
885
- enum status: [:proposed, :written, :published], _default: :published
886
- end
551
+ This has been fixed to raise with a more appropriate error message.
887
552
 
888
- Book.new.status # => "published"
889
- ```
553
+ *Joshua Young*
890
554
 
891
- *Ryuta Kamizono*
555
+ * Fix `has_one` association autosave setting the foreign key attribute when it is unchanged.
892
556
 
893
- * Deprecate YAML loading from legacy format older than Rails 5.0.
557
+ This behavior is also inconsistent with autosaving `belongs_to` and can have unintended side effects like raising
558
+ an `ActiveRecord::ReadonlyAttributeError` when the foreign key attribute is marked as read-only.
894
559
 
895
- *Ryuta Kamizono*
560
+ *Joshua Young*
896
561
 
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.
562
+ * Remove deprecated behavior that would rollback a transaction block when exited using `return`, `break` or `throw`.
901
563
 
902
- *Sean Griffin*, *Ryuta Kamizono*
564
+ *Rafael Mendonça França*
903
565
 
904
- * Deprecate `map!` and `collect!` on `ActiveRecord::Result`.
566
+ * Deprecate `Rails.application.config.active_record.commit_transaction_on_non_local_return`.
905
567
 
906
- *Ryuta Kamizono*
568
+ *Rafael Mendonça França*
907
569
 
908
- * Support `relation.and` for intersection as Set theory.
570
+ * Remove deprecated support to pass `rewhere` to `ActiveRecord::Relation#merge`.
909
571
 
910
- ```ruby
911
- david_and_mary = Author.where(id: [david, mary])
912
- mary_and_bob = Author.where(id: [mary, bob])
572
+ *Rafael Mendonça França*
913
573
 
914
- david_and_mary.merge(mary_and_bob) # => [mary, bob]
574
+ * Remove deprecated support to pass `deferrable: true` to `add_foreign_key`.
915
575
 
916
- david_and_mary.and(mary_and_bob) # => [mary]
917
- david_and_mary.or(mary_and_bob) # => [david, mary, bob]
918
- ```
576
+ *Rafael Mendonça França*
919
577
 
920
- *Ryuta Kamizono*
578
+ * Remove deprecated support to quote `ActiveSupport::Duration`.
921
579
 
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)`.
580
+ *Rafael Mendonça França*
925
581
 
926
- ```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]
582
+ * Remove deprecated `#quote_bound_value`.
929
583
 
930
- # Rails 6.1 (both conflict conditions exists, deprecated)
931
- Author.where(id: david.id..mary.id).merge(Author.where(id: bob)) # => []
584
+ *Rafael Mendonça França*
932
585
 
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]
586
+ * Remove deprecated `ActiveRecord::ConnectionAdapters::ConnectionPool#connection_klass`.
935
587
 
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]
939
- ```
588
+ *Rafael Mendonça França*
940
589
 
941
- *Ryuta Kamizono*
590
+ * Remove deprecated support to apply `#connection_pool_list`, `#active_connections?`, `#clear_active_connections!`,
591
+ `#clear_reloadable_connections!`, `#clear_all_connections!` and `#flush_idle_connections!` to the connections pools
592
+ for the current role when the `role` argument isn't provided.
942
593
 
943
- * Do not mark Postgresql MAC address and UUID attributes as changed when the assigned value only varies by case.
594
+ *Rafael Mendonça França*
944
595
 
945
- *Peter Fry*
596
+ * Remove deprecated `#all_connection_pools`.
946
597
 
947
- * Resolve issue with insert_all unique_by option when used with expression index.
598
+ *Rafael Mendonça França*
948
599
 
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.
600
+ * Remove deprecated `ActiveRecord::ConnectionAdapters::SchemaCache#data_sources`.
952
601
 
953
- Usage:
602
+ *Rafael Mendonça França*
954
603
 
955
- ```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
604
+ * Remove deprecated `ActiveRecord::ConnectionAdapters::SchemaCache.load_from`.
960
605
 
961
- Book.insert_all [{ name: "MyTest" }], unique_by: :index_books_on_lower_name
962
- ```
606
+ *Rafael Mendonça França*
963
607
 
964
- Fixes #39516.
608
+ * Remove deprecated `#all_foreign_keys_valid?` from database adapters.
965
609
 
966
- *Austen Madden*
610
+ *Rafael Mendonça França*
967
611
 
968
- * Add basic support for CHECK constraints to database migrations.
612
+ * Remove deprecated support to passing coder and class as second argument to `serialize`.
969
613
 
970
- Usage:
614
+ *Rafael Mendonça França*
971
615
 
972
- ```ruby
973
- add_check_constraint :products, "price > 0", name: "price_check"
974
- remove_check_constraint :products, name: "price_check"
975
- ```
616
+ * Remove deprecated support to `ActiveRecord::Base#read_attribute(:id)` to return the custom primary key value.
976
617
 
977
- *fatkodima*
618
+ *Rafael Mendonça França*
978
619
 
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.
620
+ * Remove deprecated `TestFixtures.fixture_path`.
982
621
 
983
- Usage:
622
+ *Rafael Mendonça França*
984
623
 
985
- ```ruby
986
- class Developer < ApplicationRecord
987
- self.strict_loading_by_default = true
624
+ * Remove deprecated behavior to support referring to a singular association by its plural name.
988
625
 
989
- has_many :projects
990
- end
626
+ *Rafael Mendonça França*
991
627
 
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
- ```
628
+ * Deprecate `Rails.application.config.active_record.allow_deprecated_singular_associations_name`.
996
629
 
997
- *bogdanvlviv*
630
+ *Rafael Mendonça França*
998
631
 
999
- * Deprecate passing an Active Record object to `quote`/`type_cast` directly.
632
+ * Remove deprecated support to passing `SchemaMigration` and `InternalMetadata` classes as arguments to
633
+ `ActiveRecord::MigrationContext`.
1000
634
 
1001
- *Ryuta Kamizono*
635
+ *Rafael Mendonça França*
1002
636
 
1003
- * Default engine `ENGINE=InnoDB` is no longer dumped to make schema more agnostic.
637
+ * Remove deprecated `ActiveRecord::Migration.check_pending!` method.
1004
638
 
1005
- Before:
639
+ *Rafael Mendonça França*
1006
640
 
1007
- ```ruby
1008
- create_table "accounts", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci", force: :cascade do |t|
1009
- end
1010
- ```
641
+ * Remove deprecated `ActiveRecord::LogSubscriber.runtime` method.
1011
642
 
1012
- After:
643
+ *Rafael Mendonça França*
1013
644
 
1014
- ```ruby
1015
- create_table "accounts", charset: "utf8mb4", collation: "utf8mb4_0900_ai_ci", force: :cascade do |t|
1016
- end
1017
- ```
645
+ * Remove deprecated `ActiveRecord::LogSubscriber.runtime=` method.
1018
646
 
1019
- *Ryuta Kamizono*
647
+ *Rafael Mendonça França*
1020
648
 
1021
- * Added delegated type as an alternative to single-table inheritance for representing class hierarchies.
1022
- See ActiveRecord::DelegatedType for the full description.
649
+ * Remove deprecated `ActiveRecord::LogSubscriber.reset_runtime` method.
1023
650
 
1024
- *DHH*
651
+ *Rafael Mendonça França*
1025
652
 
1026
- * Deprecate aggregations with group by duplicated fields.
653
+ * Remove deprecated support to define `explain` in the connection adapter with 2 arguments.
1027
654
 
1028
- To migrate to Rails 7.0's behavior, use `uniq!(:group)` to deduplicate group fields.
655
+ *Rafael Mendonça França*
1029
656
 
1030
- ```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
- # }
1046
- ```
657
+ * Remove deprecated `ActiveRecord::ActiveJobRequiredError`.
1047
658
 
1048
- *Ryuta Kamizono*
659
+ *Rafael Mendonça França*
1049
660
 
1050
- * Deprecate duplicated query annotations.
661
+ * Remove deprecated `ActiveRecord::Base.clear_active_connections!`.
1051
662
 
1052
- To migrate to Rails 7.0's behavior, use `uniq!(:annotate)` to deduplicate query annotations.
663
+ *Rafael Mendonça França*
1053
664
 
1054
- ```ruby
1055
- accounts = Account.where(id: [1, 2]).annotate("david and mary")
665
+ * Remove deprecated `ActiveRecord::Base.clear_reloadable_connections!`.
1056
666
 
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 */
667
+ *Rafael Mendonça França*
1060
668
 
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
- ```
669
+ * Remove deprecated `ActiveRecord::Base.clear_all_connections!`.
1065
670
 
1066
- *Ryuta Kamizono*
671
+ *Rafael Mendonça França*
1067
672
 
1068
- * Resolve conflict between counter cache and optimistic locking.
673
+ * Remove deprecated `ActiveRecord::Base.flush_idle_connections!`.
1069
674
 
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.
675
+ *Rafael Mendonça França*
1074
676
 
1075
- Fixes #16449.
677
+ * Remove deprecated `name` argument from `ActiveRecord::Base.remove_connection`.
1076
678
 
1077
- *Aaron Lipman*
679
+ *Rafael Mendonça França*
1078
680
 
1079
- * Support merging option `:rewhere` to allow mergee side condition to be replaced exactly.
681
+ * Remove deprecated support to call `alias_attribute` with non-existent attribute names.
1080
682
 
1081
- ```ruby
1082
- david_and_mary = Author.where(id: david.id..mary.id)
683
+ *Rafael Mendonça França*
1083
684
 
1084
- # both conflict conditions exists
1085
- david_and_mary.merge(Author.where(id: bob)) # => []
685
+ * Remove deprecated `Rails.application.config.active_record.suppress_multiple_database_warning`.
1086
686
 
1087
- # mergee side condition is replaced by rewhere
1088
- david_and_mary.merge(Author.rewhere(id: bob)) # => [bob]
687
+ *Rafael Mendonça França*
1089
688
 
1090
- # mergee side condition is replaced by rewhere option
1091
- david_and_mary.merge(Author.where(id: bob), rewhere: true) # => [bob]
1092
- ```
689
+ * Add `ActiveRecord::Encryption::MessagePackMessageSerializer`.
1093
690
 
1094
- *Ryuta Kamizono*
691
+ Serialize data to the MessagePack format, for efficient storage in binary columns.
1095
692
 
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.
693
+ The binary encoding requires around 30% less space than the base64 encoding
694
+ used by the default serializer.
1100
695
 
1101
- ```ruby
1102
- signed_id = User.first.signed_id expires_in: 15.minutes, purpose: :password_reset
696
+ *Donal McBreen*
1103
697
 
1104
- User.find_signed signed_id # => nil, since the purpose does not match
698
+ * Add support for encrypting binary columns.
1105
699
 
1106
- travel 16.minutes
1107
- User.find_signed signed_id, purpose: :password_reset # => nil, since the signed id has expired
700
+ Ensure encryption and decryption pass `Type::Binary::Data` around for binary data.
1108
701
 
1109
- travel_back
1110
- User.find_signed signed_id, purpose: :password_reset # => User.first
702
+ Previously encrypting binary columns with the `ActiveRecord::Encryption::MessageSerializer`
703
+ incidentally worked for MySQL and SQLite, but not PostgreSQL.
1111
704
 
1112
- User.find_signed! "bad data" # => ActiveSupport::MessageVerifier::InvalidSignature
1113
- ```
705
+ *Donal McBreen*
1114
706
 
1115
- *DHH*
707
+ * Deprecated `ENV["SCHEMA_CACHE"]` in favor of `schema_cache_path` in the database configuration.
1116
708
 
1117
- * Support `ALGORITHM = INSTANT` DDL option for index operations on MySQL.
709
+ *Rafael Mendonça França*
1118
710
 
1119
- *Ryuta Kamizono*
711
+ * Add `ActiveRecord::Base.with_connection` as a shortcut for leasing a connection for a short duration.
1120
712
 
1121
- * Fix index creation to preserve index comment in bulk change table on MySQL.
713
+ The leased connection is yielded, and for the duration of the block, any call to `ActiveRecord::Base.connection`
714
+ will yield that same connection.
1122
715
 
1123
- *Ryuta Kamizono*
716
+ This is useful to perform a few database operations without causing a connection to be leased for the
717
+ entire duration of the request or job.
1124
718
 
1125
- * Allow `unscope` to be aware of table name qualified values.
719
+ *Jean Boussier*
1126
720
 
1127
- It is possible to unscope only the column in the specified table.
721
+ * Deprecate `config.active_record.warn_on_records_fetched_greater_than` now that `sql.active_record`
722
+ notification includes `:row_count` field.
1128
723
 
1129
- ```ruby
1130
- posts = Post.joins(:comments).group(:"posts.hidden")
1131
- posts = posts.where("posts.hidden": false, "comments.hidden": false)
724
+ *Jason Nochlin*
1132
725
 
1133
- posts.count
1134
- # => { false => 10 }
726
+ * The fix ensures that the association is joined using the appropriate join type
727
+ (either inner join or left outer join) based on the existing joins in the scope.
1135
728
 
1136
- # unscope both hidden columns
1137
- posts.unscope(where: :hidden).count
1138
- # => { false => 11, true => 1 }
729
+ This prevents unintentional overrides of existing join types and ensures consistency in the generated SQL queries.
1139
730
 
1140
- # unscope only comments.hidden column
1141
- posts.unscope(where: :"comments.hidden").count
1142
- # => { false => 11 }
1143
- ```
731
+ Example:
1144
732
 
1145
- *Ryuta Kamizono*, *Slava Korolev*
1146
733
 
1147
- * Fix `rewhere` to truly overwrite collided where clause by new where clause.
1148
734
 
1149
735
  ```ruby
1150
- steve = Person.find_by(name: "Steve")
1151
- david = Author.find_by(name: "David")
1152
-
1153
- relation = Essay.where(writer: steve)
736
+ # `associated` will use `LEFT JOIN` instead of using `JOIN`
737
+ Post.left_joins(:author).where.associated(:author)
738
+ ```
1154
739
 
1155
- # Before
1156
- relation.rewhere(writer: david).to_a # => []
740
+ *Saleh Alhaddad*
1157
741
 
1158
- # After
1159
- relation.rewhere(writer: david).to_a # => [david]
1160
- ```
742
+ * Fix an issue where `ActiveRecord::Encryption` configurations are not ready before the loading
743
+ of Active Record models, when an application is eager loaded. As a result, encrypted attributes
744
+ could be misconfigured in some cases.
1161
745
 
1162
- *Ryuta Kamizono*
746
+ *Maxime Réty*
1163
747
 
1164
- * Inspect time attributes with subsec and time zone offset.
748
+ * Deprecate defining an `enum` with keyword arguments.
1165
749
 
1166
750
  ```ruby
1167
- p Knot.create
1168
- => #<Knot id: 1, created_at: "2016-05-05 01:29:47.116928000 +0000">
751
+ class Function > ApplicationRecord
752
+ # BAD
753
+ enum color: [:red, :blue],
754
+ type: [:instance, :class]
755
+
756
+ # GOOD
757
+ enum :color, [:red, :blue]
758
+ enum :type, [:instance, :class]
759
+ end
1169
760
  ```
1170
761
 
1171
- *akinomaeni*, *Jonathan Hefner*
1172
-
1173
- * Deprecate passing a column to `type_cast`.
1174
-
1175
- *Ryuta Kamizono*
1176
-
1177
- * Deprecate `in_clause_length` and `allowed_index_name_length` in `DatabaseLimits`.
1178
-
1179
- *Ryuta Kamizono*
1180
-
1181
- * Support bulk insert/upsert on relation to preserve scope values.
1182
-
1183
- *Josef Šimánek*, *Ryuta Kamizono*
1184
-
1185
- * Preserve column comment value on changing column name on MySQL.
762
+ *Hartley McGuire*
1186
763
 
1187
- *Islam Taha*
764
+ * Add `config.active_record.validate_migration_timestamps` option for validating migration timestamps.
1188
765
 
1189
- * Add support for `if_exists` option for removing an index.
766
+ When set, validates that the timestamp prefix for a migration is no more than a day ahead of
767
+ the timestamp associated with the current time. This is designed to prevent migrations prefixes
768
+ from being hand-edited to future timestamps, which impacts migration generation and other
769
+ migration commands.
1190
770
 
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.
771
+ *Adrianna Chang*
1192
772
 
1193
- *Eileen M. Uchitelle*
773
+ * Properly synchronize `Mysql2Adapter#active?` and `TrilogyAdapter#active?`.
1194
774
 
1195
- * Remove ibm_db, informix, mssql, oracle, and oracle12 Arel visitors which are not used in the code base.
775
+ As well as `disconnect!` and `verify!`.
1196
776
 
1197
- *Ryuta Kamizono*
777
+ This generally isn't a big problem as connections must not be shared between
778
+ threads, but is required when running transactional tests or system tests
779
+ and could lead to a SEGV.
1198
780
 
1199
- * Prevent `build_association` from `touching` a parent record if the record isn't persisted for `has_one` associations.
1200
-
1201
- Fixes #38219.
1202
-
1203
- *Josh Brody*
1204
-
1205
- * Add support for `if_not_exists` option for adding index.
1206
-
1207
- The `add_index` method respects `if_not_exists` option. If it is set to true
1208
- index won't be added.
781
+ *Jean Boussier*
1209
782
 
1210
- Usage:
783
+ * Support `:source_location` tag option for query log tags.
1211
784
 
1212
785
  ```ruby
1213
- add_index :users, :account_id, if_not_exists: true
786
+ config.active_record.query_log_tags << :source_location
1214
787
  ```
1215
788
 
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.
1219
-
1220
- *Prathamesh Sonpatki*
1221
-
1222
- * Add `ActiveRecord::Base#previously_new_record?` to show if a record was new before the last save.
789
+ Calculating the caller location is a costly operation and should be used primarily in development
790
+ (note, there is also a `config.active_record.verbose_query_logs` that serves the same purpose)
791
+ or occasionally on production for debugging purposes.
1223
792
 
1224
- *Tom Ward*
1225
-
1226
- * Support descending order for `find_each`, `find_in_batches`, and `in_batches`.
1227
-
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.
793
+ *fatkodima*
1229
794
 
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.
795
+ * Add an option to `ActiveRecord::Encryption::Encryptor` to disable compression.
1231
796
 
1232
- Pass `order: :desc` to yield batches in descending order. The default remains `order: :asc`.
797
+ Allow compression to be disabled by setting `compress: false`
1233
798
 
1234
799
  ```ruby
1235
- Person.find_each(order: :desc) do |person|
1236
- person.party_all_night!
1237
- end
800
+ class User
801
+ encrypts :name, encryptor: ActiveRecord::Encryption::Encryptor.new(compress: false)
802
+ end
1238
803
  ```
1239
804
 
1240
- *Alexey Vasiliev*
805
+ *Donal McBreen*
1241
806
 
1242
- * Fix `insert_all` with enum values.
807
+ * Deprecate passing strings to `ActiveRecord::Tasks::DatabaseTasks.cache_dump_filename`.
1243
808
 
1244
- Fixes #38716.
809
+ A `ActiveRecord::DatabaseConfigurations::DatabaseConfig` object should be passed instead.
1245
810
 
1246
- *Joel Blum*
811
+ *Rafael Mendonça França*
1247
812
 
1248
- * Add support for `db:rollback:name` for multiple database applications.
813
+ * Add `row_count` field to `sql.active_record` notification.
1249
814
 
1250
- Multiple database applications will now raise if `db:rollback` is call and recommend using the `db:rollback:[NAME]` to rollback migrations.
815
+ This field returns the amount of rows returned by the query that emitted the notification.
1251
816
 
1252
- *Eileen M. Uchitelle*
817
+ This metric is useful in cases where one wants to detect queries with big result sets.
1253
818
 
1254
- * `Relation#pick` now uses already loaded results instead of making another query.
819
+ *Marvin Bitterlich*
1255
820
 
1256
- *Eugene Kenny*
821
+ * Consistently raise an `ArgumentError` when passing an invalid argument to a nested attributes association writer.
1257
822
 
1258
- * Deprecate using `return`, `break` or `throw` to exit a transaction block after writes.
823
+ Previously, this would only raise on collection associations and produce a generic error on singular associations.
1259
824
 
1260
- *Dylan Thacker-Smith*
825
+ Now, it will raise on both collection and singular associations.
1261
826
 
1262
- * Dump the schema or structure of a database when calling `db:migrate:name`.
827
+ *Joshua Young*
1263
828
 
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.
829
+ * Fix single quote escapes on default generated MySQL columns.
1265
830
 
1266
- Going forward, calls to `rails db:migrate:name` will dump the schema (or structure) of the database being migrated.
831
+ MySQL 5.7.5+ supports generated columns, which can be used to create a column that is computed from an expression.
1267
832
 
1268
- *Kyle Thompson*
833
+ Previously, the schema dump would output a string with double escapes for generated columns with single quotes in the default expression.
1269
834
 
1270
- * Reset the `ActiveRecord::Base` connection after `rails db:migrate:name`.
835
+ This would result in issues when importing the schema on a fresh instance of a MySQL database.
1271
836
 
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.
837
+ Now, the string will not be escaped and will be valid Ruby upon importing of the schema.
1273
838
 
1274
- *Kyle Thompson*
839
+ *Yash Kapadia*
1275
840
 
1276
- * Disallow calling `connected_to` on subclasses of `ActiveRecord::Base`.
841
+ * Fix Migrations with versions older than 7.1 validating options given to
842
+ `add_reference` and `t.references`.
1277
843
 
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.
844
+ *Hartley McGuire*
1279
845
 
1280
- *Eileen M. Uchitelle*, *John Crepezzi*
846
+ * Add `<role>_types` class method to `ActiveRecord::DelegatedType` so that the delegated types can be introspected.
1281
847
 
1282
- * Add support for horizontal sharding to `connects_to` and `connected_to`.
848
+ *JP Rosevear*
1283
849
 
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.
850
+ * Make `schema_dump`, `query_cache`, `replica` and `database_tasks` configurable via `DATABASE_URL`.
1285
851
 
1286
- Usage:
852
+ This wouldn't always work previously because boolean values would be interpreted as strings.
1287
853
 
1288
- Given the following configuration:
854
+ e.g. `DATABASE_URL=postgres://localhost/foo?schema_dump=false` now properly disable dumping the schema
855
+ cache.
1289
856
 
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
- ```
857
+ *Mike Coutermarsh*, *Jean Boussier*
1298
858
 
1299
- Connect to multiple shards:
859
+ * Introduce `ActiveRecord::Transactions::ClassMethods#set_callback`.
1300
860
 
1301
- ```ruby
1302
- class ApplicationRecord < ActiveRecord::Base
1303
- self.abstract_class = true
861
+ It is identical to `ActiveSupport::Callbacks::ClassMethods#set_callback`
862
+ but with support for `after_commit` and `after_rollback` callback options.
1304
863
 
1305
- connects_to shards: {
1306
- default: { writing: :primary },
1307
- shard_one: { writing: :primary_shard_one }
1308
- }
1309
- ```
864
+ *Joshua Young*
1310
865
 
1311
- Swap between shards in your controller / model code:
866
+ * Make `ActiveRecord::Encryption::Encryptor` agnostic of the serialization format used for encrypted data.
1312
867
 
1313
- ```ruby
1314
- ActiveRecord::Base.connected_to(shard: :shard_one) do
1315
- # Read from shard one
1316
- end
1317
- ```
868
+ Previously, the encryptor instance only allowed an encrypted value serialized as a `String` to be passed to the message serializer.
869
+
870
+ Now, the encryptor lets the configured `message_serializer` decide which types of serialized encrypted values are supported. A custom serialiser is therefore allowed to serialize `ActiveRecord::Encryption::Message` objects using a type other than `String`.
1318
871
 
1319
- The horizontal sharding API also supports read replicas. See guides for more details.
872
+ The default `ActiveRecord::Encryption::MessageSerializer` already ensures that only `String` objects are passed for deserialization.
1320
873
 
1321
- *Eileen M. Uchitelle*, *John Crepezzi*
874
+ *Maxime Réty*
1322
875
 
1323
- * Deprecate `spec_name` in favor of `name` on database configurations.
876
+ * Fix `encrypted_attribute?` to take into account context properties passed to `encrypts`.
1324
877
 
1325
- The accessors for `spec_name` on `configs_for` and `DatabaseConfig` are deprecated. Please use `name` instead.
878
+ *Maxime Réty*
1326
879
 
1327
- Deprecated behavior:
880
+ * The object returned by `explain` now responds to `pluck`, `first`,
881
+ `last`, `average`, `count`, `maximum`, `minimum`, and `sum`. Those
882
+ new methods run `EXPLAIN` on the corresponding queries:
1328
883
 
1329
884
  ```ruby
1330
- db_config = ActiveRecord::Base.configurations.configs_for(env_name: "development", spec_name: "primary")
1331
- db_config.spec_name
885
+ User.all.explain.count
886
+ # EXPLAIN SELECT COUNT(*) FROM `users`
887
+ # ...
888
+
889
+ User.all.explain.maximum(:id)
890
+ # EXPLAIN SELECT MAX(`users`.`id`) FROM `users`
891
+ # ...
1332
892
  ```
1333
893
 
1334
- New behavior:
894
+ *Petrik de Heus*
1335
895
 
1336
- ```ruby
1337
- db_config = ActiveRecord::Base.configurations.configs_for(env_name: "development", name: "primary")
1338
- db_config.name
1339
- ```
896
+ * Fixes an issue where `validates_associated` `:on` option wasn't respected
897
+ when validating associated records.
1340
898
 
1341
- *Eileen M. Uchitelle*
899
+ *Austen Madden*, *Alex Ghiculescu*, *Rafał Brize*
1342
900
 
1343
- * Add additional database-specific rake tasks for multi-database users.
901
+ * Allow overriding SQLite defaults from `database.yml`.
1344
902
 
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:
903
+ Any PRAGMA configuration set under the `pragmas` key in the configuration
904
+ file takes precedence over Rails' defaults, and additional PRAGMAs can be
905
+ set as well.
1347
906
 
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
907
+ ```yaml
908
+ database: storage/development.sqlite3
909
+ timeout: 5000
910
+ pragmas:
911
+ journal_mode: off
912
+ temp_store: memory
1358
913
  ```
1359
914
 
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:
915
+ *Stephen Margheim*
1362
916
 
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
- ```
917
+ * Remove warning message when running SQLite in production, but leave it unconfigured.
1380
918
 
1381
- *Kyle Thompson*
919
+ There are valid use cases for running SQLite in production. However, it must be done
920
+ with care, so instead of a warning most users won't see anyway, it's preferable to
921
+ leave the configuration commented out to force them to think about having the database
922
+ on a persistent volume etc.
1382
923
 
1383
- * Add support for `strict_loading` mode on association declarations.
924
+ *Jacopo Beschi*, *Jean Boussier*
1384
925
 
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.
926
+ * Add support for generated columns to the SQLite3 adapter.
1386
927
 
1387
- Usage:
928
+ Generated columns (both stored and dynamic) are supported since version 3.31.0 of SQLite.
929
+ This adds support for those to the SQLite3 adapter.
1388
930
 
1389
931
  ```ruby
1390
- class Developer < ApplicationRecord
1391
- has_many :projects, strict_loading: true
932
+ create_table :users do |t|
933
+ t.string :name
934
+ t.virtual :name_upper, type: :string, as: 'UPPER(name)'
935
+ t.virtual :name_lower, type: :string, as: 'LOWER(name)', stored: true
1392
936
  end
1393
-
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
937
  ```
1398
938
 
1399
- *Kevin Deisz*
939
+ *Stephen Margheim*
1400
940
 
1401
- * Add support for `strict_loading` mode to prevent lazy loading of records.
941
+ * TrilogyAdapter: ignore `host` if `socket` parameter is set.
1402
942
 
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.
943
+ This allows to configure a connection on a UNIX socket via `DATABASE_URL`:
1404
944
 
1405
- Usage:
1406
-
1407
- ```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.
945
+ ```
946
+ DATABASE_URL=trilogy://does-not-matter/my_db_production?socket=/var/run/mysql.sock
1411
947
  ```
1412
948
 
1413
- *Eileen M. Uchitelle*, *Aaron Patterson*
1414
-
1415
- * Add support for PostgreSQL 11+ partitioned indexes when using `upsert_all`.
1416
-
1417
- *Sebastián Palma*
1418
-
1419
- * Adds support for `if_not_exists` to `add_column` and `if_exists` to `remove_column`.
949
+ *Jean Boussier*
1420
950
 
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.
951
+ * Make `assert_queries_count`, `assert_no_queries`, `assert_queries_match`, and
952
+ `assert_no_queries_match` assertions public.
1422
953
 
1423
- Example Usage:
954
+ To assert the expected number of queries are made, Rails internally uses `assert_queries_count` and
955
+ `assert_no_queries`. To assert that specific SQL queries are made, `assert_queries_match` and
956
+ `assert_no_queries_match` are used. These assertions can now be used in applications as well.
1424
957
 
1425
958
  ```ruby
1426
- class AddColumnTitle < ActiveRecord::Migration[6.1]
1427
- def change
1428
- add_column :posts, :title, :string, if_not_exists: true
959
+ class ArticleTest < ActiveSupport::TestCase
960
+ test "queries are made" do
961
+ assert_queries_count(1) { Article.first }
1429
962
  end
1430
- end
1431
- ```
1432
963
 
1433
- ```ruby
1434
- class RemoveColumnTitle < ActiveRecord::Migration[6.1]
1435
- def change
1436
- remove_column :posts, :title, if_exists: true
964
+ test "creates a foreign key" do
965
+ assert_queries_match(/ADD FOREIGN KEY/i, include_schema: true) do
966
+ @connection.add_foreign_key(:comments, :posts)
967
+ end
1437
968
  end
1438
969
  end
1439
970
  ```
1440
971
 
1441
- *Eileen M. Uchitelle*
1442
-
1443
- * Regexp-escape table name for MS SQL Server.
1444
-
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.
1446
-
1447
- *Larry Reid*
1448
-
1449
- * Store advisory locks on their own named connection.
1450
-
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.
1452
-
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.
972
+ *Petrik de Heus*, *fatkodima*
1454
973
 
1455
- *Eileen M. Uchitelle*, *John Crepezzi*
974
+ * Fix `has_secure_token` calls the setter method on initialize.
1456
975
 
1457
- * Allow schema cache path to be defined in the database configuration file.
976
+ *Abeid Ahmed*
1458
977
 
1459
- For example:
978
+ * When using a `DATABASE_URL`, allow for a configuration to map the protocol in the URL to a specific database
979
+ adapter. This allows decoupling the adapter the application chooses to use from the database connection details
980
+ set in the deployment environment.
1460
981
 
1461
- ```yaml
1462
- development:
1463
- adapter: postgresql
1464
- database: blog_development
1465
- pool: 5
1466
- schema_cache_path: tmp/schema/main.yml
982
+ ```ruby
983
+ # ENV['DATABASE_URL'] = "mysql://localhost/example_database"
984
+ config.active_record.protocol_adapters.mysql = "trilogy"
985
+ # will connect to MySQL using the trilogy adapter
1467
986
  ```
1468
987
 
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.
988
+ *Jean Boussier*, *Kevin McPhillips*
1474
989
 
1475
- *Eileen M. Uchitelle*, *John Crepezzi*
990
+ * In cases where MySQL returns `warning_count` greater than zero, but returns no warnings when
991
+ the `SHOW WARNINGS` query is executed, `ActiveRecord.db_warnings_action` proc will still be
992
+ called with a generic warning message rather than silently ignoring the warning(s).
1476
993
 
1477
- * Deprecate `#default_hash` and it's alias `#[]` on database configurations.
994
+ *Kevin McPhillips*
1478
995
 
1479
- Applications should use `configs_for`. `#default_hash` and `#[]` will be removed in Rails 7.0.
996
+ * `DatabaseConfigurations#configs_for` accepts a symbol in the `name` parameter.
1480
997
 
1481
- *Eileen M. Uchitelle*, *John Crepezzi*
998
+ *Andrew Novoselac*
1482
999
 
1483
- * Add scale support to `ActiveRecord::Validations::NumericalityValidator`.
1000
+ * Fix `where(field: values)` queries when `field` is a serialized attribute
1001
+ (for example, when `field` uses `ActiveRecord::Base.serialize` or is a JSON
1002
+ column).
1484
1003
 
1485
- *Gannon McGibbon*
1004
+ *João Alves*
1486
1005
 
1487
- * Find orphans by looking for missing relations through chaining `where.missing`:
1006
+ * Make the output of `ActiveRecord::Core#inspect` configurable.
1488
1007
 
1489
- Before:
1008
+ By default, calling `inspect` on a record will yield a formatted string including just the `id`.
1490
1009
 
1491
1010
  ```ruby
1492
- Post.left_joins(:author).where(authors: { id: nil })
1011
+ Post.first.inspect #=> "#<Post id: 1>"
1493
1012
  ```
1494
1013
 
1495
- After:
1496
-
1497
- ```ruby
1498
- Post.where.missing(:author)
1499
- ```
1500
-
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*
1508
-
1509
- * Deprecate `"primary"` as the `connection_specification_name` for `ActiveRecord::Base`.
1510
-
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"`.
1512
-
1513
- *Eileen M. Uchitelle*, *John Crepezzi*
1514
-
1515
- * Add `ActiveRecord::Validations::NumericalityValidator` with
1516
- support for casting floats using a database columns' precision value.
1517
-
1518
- *Gannon McGibbon*
1519
-
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.
1525
-
1526
- Fixes #38078.
1527
-
1528
- *Aaron Lipman*
1529
-
1530
- * Skip test database when running `db:create` or `db:drop` in development
1531
- with `DATABASE_URL` set.
1532
-
1533
- *Brian Buchalter*
1534
-
1535
- * Don't allow mutations on the database configurations hash.
1536
-
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.
1538
-
1539
- Before:
1014
+ The attributes to be included in the output of `inspect` can be configured with
1015
+ `ActiveRecord::Core#attributes_for_inspect`.
1540
1016
 
1541
1017
  ```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")
1018
+ Post.attributes_for_inspect = [:id, :title]
1019
+ Post.first.inspect #=> "#<Post id: 1, title: "Hello, World!">"
1544
1020
  ```
1545
1021
 
1546
- After:
1022
+ With `attributes_for_inspect` set to `:all`, `inspect` will list all the record's attributes.
1547
1023
 
1548
1024
  ```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)
1025
+ Post.attributes_for_inspect = :all
1026
+ Post.first.inspect #=> "#<Post id: 1, title: "Hello, World!", published_at: "2023-10-23 14:28:11 +0000">"
1552
1027
  ```
1553
1028
 
1554
- *Eileen M. Uchitelle*, *John Crepezzi*
1555
-
1556
- * Remove `:connection_id` from the `sql.active_record` notification.
1557
-
1558
- *Aaron Patterson*, *Rafael Mendonça França*
1559
-
1560
- * The `:name` key will no longer be returned as part of `DatabaseConfig#configuration_hash`. Please use `DatabaseConfig#owner_name` instead.
1561
-
1562
- *Eileen M. Uchitelle*, *John Crepezzi*
1563
-
1564
- * ActiveRecord's `belongs_to_required_by_default` flag can now be set per model.
1565
-
1566
- You can now opt-out/opt-in specific models from having their associations required
1567
- by default.
1568
-
1569
- This change is meant to ease the process of migrating all your models to have
1570
- their association required.
1571
-
1572
- *Edouard Chin*
1573
-
1574
- * The `connection_config` method has been deprecated, please use `connection_db_config` instead which will return a `DatabaseConfigurations::DatabaseConfig` instead of a `Hash`.
1575
-
1576
- *Eileen M. Uchitelle*, *John Crepezzi*
1577
-
1578
- * Retain explicit selections on the base model after applying `includes` and `joins`.
1029
+ In `development` and `test` mode, `attributes_for_inspect` will be set to `:all` by default.
1579
1030
 
1580
- Resolves #34889.
1031
+ You can also call `full_inspect` to get an inspection with all the attributes.
1581
1032
 
1582
- *Patrick Rebsch*
1033
+ The attributes in `attribute_for_inspect` will also be used for `pretty_print`.
1583
1034
 
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.
1035
+ *Andrew Novoselac*
1585
1036
 
1586
- *Eileen M. Uchitelle*, *John Crepezzi*
1037
+ * Don't mark attributes as changed when reassigned to `Float::INFINITY` or
1038
+ `-Float::INFINITY`.
1587
1039
 
1588
- * Allow attributes to be fetched from Arel node groupings.
1040
+ *Maicol Bentancor*
1589
1041
 
1590
- *Jeff Emminger*, *Gannon McGibbon*
1042
+ * Support the `RETURNING` clause for MariaDB.
1591
1043
 
1592
- * A database URL can now contain a querystring value that contains an equal sign. This is needed to support passing PostgreSQL `options`.
1044
+ *fatkodima*, *Nikolay Kondratyev*
1593
1045
 
1594
- *Joshua Flanagan*
1046
+ * The SQLite3 adapter now implements the `supports_deferrable_constraints?` contract.
1595
1047
 
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`.
1597
-
1598
- *John Crepezzi*
1599
-
1600
- * Specifying `implicit_order_column` now subsorts the records by primary key if available to ensure deterministic results.
1601
-
1602
- *Paweł Urbanek*
1603
-
1604
- * `where(attr => [])` now loads an empty result without making a query.
1605
-
1606
- *John Hawthorn*
1607
-
1608
- * Fixed the performance regression for `primary_keys` introduced MySQL 8.0.
1609
-
1610
- *Hiroyuki Ishii*
1611
-
1612
- * Add support for `belongs_to` to `has_many` inversing.
1613
-
1614
- *Gannon McGibbon*
1615
-
1616
- * Allow length configuration for `has_secure_token` method. The minimum length
1617
- is set at 24 characters.
1618
-
1619
- Before:
1048
+ Allows foreign keys to be deferred by adding the `:deferrable` key to the `foreign_key` options.
1620
1049
 
1621
1050
  ```ruby
1622
- has_secure_token :auth_token
1051
+ add_reference :person, :alias, foreign_key: { deferrable: :deferred }
1052
+ add_reference :alias, :person, foreign_key: { deferrable: :deferred }
1623
1053
  ```
1624
1054
 
1625
- After:
1055
+ *Stephen Margheim*
1056
+
1057
+ * Add the `set_constraints` helper to PostgreSQL connections.
1626
1058
 
1627
1059
  ```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
1060
+ Post.create!(user_id: -1) # => ActiveRecord::InvalidForeignKey
1061
+
1062
+ Post.transaction do
1063
+ Post.connection.set_constraints(:deferred)
1064
+ p = Post.create!(user_id: -1)
1065
+ u = User.create!
1066
+ p.user = u
1067
+ p.save!
1068
+ end
1631
1069
  ```
1632
1070
 
1633
- *Bernardo de Araujo*
1071
+ *Cody Cutrer*
1634
1072
 
1635
- * Deprecate `DatabaseConfigurations#to_h`. These connection hashes are still available via `ActiveRecord::Base.configurations.configs_for`.
1073
+ * Include `ActiveModel::API` in `ActiveRecord::Base`.
1636
1074
 
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
1657
-
1658
- *Eugene Kenny*
1659
-
1660
- * Allow bulk `ALTER` statements to drop and recreate indexes with the same name.
1661
-
1662
- *Eugene Kenny*
1663
-
1664
- * `insert`, `insert_all`, `upsert`, and `upsert_all` now clear the query cache.
1665
-
1666
- *Eugene Kenny*
1667
-
1668
- * Call `while_preventing_writes` directly from `connected_to`.
1669
-
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)`.
1671
-
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.
1673
-
1674
- *Eileen M. Uchitelle*
1675
-
1676
- * Improve detection of ActiveRecord::StatementTimeout with mysql2 adapter in the edge case when the query is terminated during filesort.
1677
-
1678
- *Kir Shatrov*
1679
-
1680
- * Stop trying to read yaml file fixtures when loading Active Record fixtures.
1681
-
1682
- *Gannon McGibbon*
1683
-
1684
- * Deprecate `.reorder(nil)` with `.first` / `.first!` taking non-deterministic result.
1685
-
1686
- To continue taking non-deterministic result, use `.take` / `.take!` instead.
1687
-
1688
- *Ryuta Kamizono*
1689
-
1690
- * Preserve user supplied joins order as much as possible.
1691
-
1692
- Fixes #36761, #34328, #24281, #12953.
1693
-
1694
- *Ryuta Kamizono*
1695
-
1696
- * Allow `matches_regex` and `does_not_match_regexp` on the MySQL Arel visitor.
1697
-
1698
- *James Pearson*
1699
-
1700
- * Allow specifying fixtures to be ignored by setting `ignore` in YAML file's '_fixture' section.
1701
-
1702
- *Tongfei Gao*
1703
-
1704
- * Make the DATABASE_URL env variable only affect the primary connection. Add new env variables for multiple databases.
1705
-
1706
- *John Crepezzi*, *Eileen Uchitelle*
1707
-
1708
- * Add a warning for enum elements with 'not_' prefix.
1709
-
1710
- class Foo
1711
- enum status: [:sent, :not_sent]
1712
- end
1713
-
1714
- *Edu Depetris*
1715
-
1716
- * Make currency symbols optional for money column type in PostgreSQL.
1717
-
1718
- *Joel Schneider*
1719
-
1720
- * Add support for beginless ranges, introduced in Ruby 2.7.
1721
-
1722
- *Josh Goodall*
1723
-
1724
- * Add `database_exists?` method to connection adapters to check if a database exists.
1725
-
1726
- *Guilherme Mansur*
1727
-
1728
- * Loading the schema for a model that has no `table_name` raises a `TableNotSpecified` error.
1729
-
1730
- *Guilherme Mansur*, *Eugene Kenny*
1731
-
1732
- * PostgreSQL: Fix GROUP BY with ORDER BY virtual count attribute.
1733
-
1734
- Fixes #36022.
1735
-
1736
- *Ryuta Kamizono*
1737
-
1738
- * Make ActiveRecord `ConnectionPool.connections` method thread-safe.
1739
-
1740
- Fixes #36465.
1741
-
1742
- *Jeff Doering*
1743
-
1744
- * Add support for multiple databases to `rails db:abort_if_pending_migrations`.
1745
-
1746
- *Mark Lee*
1747
-
1748
- * Fix sqlite3 collation parsing when using decimal columns.
1749
-
1750
- *Martin R. Schuster*
1751
-
1752
- * Fix invalid schema when primary key column has a comment.
1075
+ *Sean Doyle*
1753
1076
 
1754
- Fixes #29966.
1077
+ * Ensure `#signed_id` outputs `url_safe` strings.
1755
1078
 
1756
- *Guilherme Goettems Schneider*
1079
+ *Jason Meller*
1757
1080
 
1758
- * Fix table comment also being applied to the primary key column.
1081
+ * Add `nulls_last` and working `desc.nulls_first` for MySQL.
1759
1082
 
1760
- *Guilherme Goettems Schneider*
1083
+ *Tristan Fellows*
1761
1084
 
1762
- * Allow generated `create_table` migrations to include or skip timestamps.
1085
+ * Allow for more complex hash arguments for `order` which mimics `where` in `ActiveRecord::Relation`.
1763
1086
 
1764
- *Michael Duchemin*
1087
+ ```ruby
1088
+ Topic.includes(:posts).order(posts: { created_at: :desc })
1089
+ ```
1765
1090
 
1091
+ *Myles Boone*
1766
1092
 
1767
- Please check [6-0-stable](https://github.com/rails/rails/blob/6-0-stable/activerecord/CHANGELOG.md) for previous changes.
1093
+ Please check [7-1-stable](https://github.com/rails/rails/blob/7-1-stable/activerecord/CHANGELOG.md) for previous changes.