activerecord 5.2.6 → 6.1.3.2

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of activerecord might be problematic. Click here for more details.

Files changed (316) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +1038 -571
  3. data/MIT-LICENSE +3 -1
  4. data/README.rdoc +7 -5
  5. data/examples/performance.rb +1 -1
  6. data/lib/active_record.rb +13 -12
  7. data/lib/active_record/aggregations.rb +9 -8
  8. data/lib/active_record/association_relation.rb +30 -10
  9. data/lib/active_record/associations.rb +137 -25
  10. data/lib/active_record/associations/alias_tracker.rb +19 -16
  11. data/lib/active_record/associations/association.rb +95 -42
  12. data/lib/active_record/associations/association_scope.rb +23 -21
  13. data/lib/active_record/associations/belongs_to_association.rb +54 -46
  14. data/lib/active_record/associations/belongs_to_polymorphic_association.rb +7 -6
  15. data/lib/active_record/associations/builder/association.rb +45 -22
  16. data/lib/active_record/associations/builder/belongs_to.rb +29 -59
  17. data/lib/active_record/associations/builder/collection_association.rb +8 -17
  18. data/lib/active_record/associations/builder/has_and_belongs_to_many.rb +17 -41
  19. data/lib/active_record/associations/builder/has_many.rb +8 -2
  20. data/lib/active_record/associations/builder/has_one.rb +33 -2
  21. data/lib/active_record/associations/builder/singular_association.rb +3 -1
  22. data/lib/active_record/associations/collection_association.rb +31 -29
  23. data/lib/active_record/associations/collection_proxy.rb +25 -21
  24. data/lib/active_record/associations/foreign_association.rb +20 -0
  25. data/lib/active_record/associations/has_many_association.rb +26 -13
  26. data/lib/active_record/associations/has_many_through_association.rb +24 -18
  27. data/lib/active_record/associations/has_one_association.rb +43 -31
  28. data/lib/active_record/associations/has_one_through_association.rb +5 -5
  29. data/lib/active_record/associations/join_dependency.rb +91 -60
  30. data/lib/active_record/associations/join_dependency/join_association.rb +44 -22
  31. data/lib/active_record/associations/join_dependency/join_part.rb +5 -5
  32. data/lib/active_record/associations/preloader.rb +47 -34
  33. data/lib/active_record/associations/preloader/association.rb +71 -43
  34. data/lib/active_record/associations/preloader/through_association.rb +49 -40
  35. data/lib/active_record/associations/singular_association.rb +3 -17
  36. data/lib/active_record/associations/through_association.rb +1 -1
  37. data/lib/active_record/attribute_assignment.rb +17 -19
  38. data/lib/active_record/attribute_methods.rb +81 -143
  39. data/lib/active_record/attribute_methods/before_type_cast.rb +13 -7
  40. data/lib/active_record/attribute_methods/dirty.rb +101 -40
  41. data/lib/active_record/attribute_methods/primary_key.rb +20 -25
  42. data/lib/active_record/attribute_methods/query.rb +4 -8
  43. data/lib/active_record/attribute_methods/read.rb +14 -56
  44. data/lib/active_record/attribute_methods/serialization.rb +12 -7
  45. data/lib/active_record/attribute_methods/time_zone_conversion.rb +12 -15
  46. data/lib/active_record/attribute_methods/write.rb +18 -34
  47. data/lib/active_record/attributes.rb +46 -9
  48. data/lib/active_record/autosave_association.rb +57 -42
  49. data/lib/active_record/base.rb +4 -17
  50. data/lib/active_record/callbacks.rb +158 -43
  51. data/lib/active_record/coders/yaml_column.rb +1 -2
  52. data/lib/active_record/connection_adapters.rb +50 -0
  53. data/lib/active_record/connection_adapters/abstract/connection_pool.rb +272 -130
  54. data/lib/active_record/connection_adapters/abstract/database_limits.rb +7 -36
  55. data/lib/active_record/connection_adapters/abstract/database_statements.rb +167 -146
  56. data/lib/active_record/connection_adapters/abstract/query_cache.rb +18 -14
  57. data/lib/active_record/connection_adapters/abstract/quoting.rb +98 -47
  58. data/lib/active_record/connection_adapters/abstract/savepoints.rb +3 -3
  59. data/lib/active_record/connection_adapters/abstract/schema_creation.rb +153 -110
  60. data/lib/active_record/connection_adapters/abstract/schema_definitions.rb +207 -90
  61. data/lib/active_record/connection_adapters/abstract/schema_dumper.rb +2 -4
  62. data/lib/active_record/connection_adapters/abstract/schema_statements.rb +385 -144
  63. data/lib/active_record/connection_adapters/abstract/transaction.rb +155 -68
  64. data/lib/active_record/connection_adapters/abstract_adapter.rb +228 -98
  65. data/lib/active_record/connection_adapters/abstract_mysql_adapter.rb +243 -275
  66. data/lib/active_record/connection_adapters/column.rb +30 -12
  67. data/lib/active_record/connection_adapters/deduplicable.rb +29 -0
  68. data/lib/active_record/connection_adapters/legacy_pool_manager.rb +31 -0
  69. data/lib/active_record/connection_adapters/mysql/column.rb +1 -1
  70. data/lib/active_record/connection_adapters/mysql/database_statements.rb +86 -32
  71. data/lib/active_record/connection_adapters/mysql/explain_pretty_printer.rb +1 -2
  72. data/lib/active_record/connection_adapters/mysql/quoting.rb +59 -7
  73. data/lib/active_record/connection_adapters/mysql/schema_creation.rb +34 -10
  74. data/lib/active_record/connection_adapters/mysql/schema_definitions.rb +48 -32
  75. data/lib/active_record/connection_adapters/mysql/schema_dumper.rb +18 -7
  76. data/lib/active_record/connection_adapters/mysql/schema_statements.rb +139 -19
  77. data/lib/active_record/connection_adapters/mysql/type_metadata.rb +14 -9
  78. data/lib/active_record/connection_adapters/mysql2_adapter.rb +53 -18
  79. data/lib/active_record/connection_adapters/pool_config.rb +73 -0
  80. data/lib/active_record/connection_adapters/pool_manager.rb +43 -0
  81. data/lib/active_record/connection_adapters/postgresql/column.rb +37 -28
  82. data/lib/active_record/connection_adapters/postgresql/database_statements.rb +38 -54
  83. data/lib/active_record/connection_adapters/postgresql/oid.rb +2 -0
  84. data/lib/active_record/connection_adapters/postgresql/oid/array.rb +1 -2
  85. data/lib/active_record/connection_adapters/postgresql/oid/bit.rb +1 -4
  86. data/lib/active_record/connection_adapters/postgresql/oid/cidr.rb +3 -5
  87. data/lib/active_record/connection_adapters/postgresql/oid/date.rb +2 -2
  88. data/lib/active_record/connection_adapters/postgresql/oid/date_time.rb +10 -2
  89. data/lib/active_record/connection_adapters/postgresql/oid/enum.rb +0 -1
  90. data/lib/active_record/connection_adapters/postgresql/oid/hstore.rb +1 -2
  91. data/lib/active_record/connection_adapters/postgresql/oid/interval.rb +49 -0
  92. data/lib/active_record/connection_adapters/postgresql/oid/legacy_point.rb +3 -4
  93. data/lib/active_record/connection_adapters/postgresql/oid/macaddr.rb +25 -0
  94. data/lib/active_record/connection_adapters/postgresql/oid/oid.rb +1 -1
  95. data/lib/active_record/connection_adapters/postgresql/oid/point.rb +3 -4
  96. data/lib/active_record/connection_adapters/postgresql/oid/range.rb +25 -7
  97. data/lib/active_record/connection_adapters/postgresql/oid/specialized_string.rb +1 -1
  98. data/lib/active_record/connection_adapters/postgresql/oid/type_map_initializer.rb +9 -7
  99. data/lib/active_record/connection_adapters/postgresql/oid/uuid.rb +15 -3
  100. data/lib/active_record/connection_adapters/postgresql/quoting.rb +47 -10
  101. data/lib/active_record/connection_adapters/postgresql/referential_integrity.rb +2 -2
  102. data/lib/active_record/connection_adapters/postgresql/schema_creation.rb +19 -4
  103. data/lib/active_record/connection_adapters/postgresql/schema_definitions.rb +107 -91
  104. data/lib/active_record/connection_adapters/postgresql/schema_dumper.rb +0 -1
  105. data/lib/active_record/connection_adapters/postgresql/schema_statements.rb +120 -100
  106. data/lib/active_record/connection_adapters/postgresql/type_metadata.rb +31 -26
  107. data/lib/active_record/connection_adapters/postgresql/utils.rb +0 -1
  108. data/lib/active_record/connection_adapters/postgresql_adapter.rb +224 -120
  109. data/lib/active_record/connection_adapters/schema_cache.rb +127 -21
  110. data/lib/active_record/connection_adapters/sql_type_metadata.rb +19 -6
  111. data/lib/active_record/connection_adapters/sqlite3/database_statements.rb +144 -0
  112. data/lib/active_record/connection_adapters/sqlite3/quoting.rb +42 -7
  113. data/lib/active_record/connection_adapters/sqlite3/schema_creation.rb +5 -1
  114. data/lib/active_record/connection_adapters/sqlite3/schema_statements.rb +77 -13
  115. data/lib/active_record/connection_adapters/sqlite3_adapter.rb +174 -186
  116. data/lib/active_record/connection_adapters/statement_pool.rb +0 -1
  117. data/lib/active_record/connection_handling.rb +293 -33
  118. data/lib/active_record/core.rb +323 -97
  119. data/lib/active_record/counter_cache.rb +8 -30
  120. data/lib/active_record/database_configurations.rb +272 -0
  121. data/lib/active_record/database_configurations/connection_url_resolver.rb +98 -0
  122. data/lib/active_record/database_configurations/database_config.rb +80 -0
  123. data/lib/active_record/database_configurations/hash_config.rb +96 -0
  124. data/lib/active_record/database_configurations/url_config.rb +53 -0
  125. data/lib/active_record/delegated_type.rb +209 -0
  126. data/lib/active_record/destroy_association_async_job.rb +36 -0
  127. data/lib/active_record/dynamic_matchers.rb +3 -4
  128. data/lib/active_record/enum.rb +111 -37
  129. data/lib/active_record/errors.rb +62 -19
  130. data/lib/active_record/explain.rb +10 -6
  131. data/lib/active_record/explain_subscriber.rb +1 -1
  132. data/lib/active_record/fixture_set/file.rb +10 -17
  133. data/lib/active_record/fixture_set/model_metadata.rb +32 -0
  134. data/lib/active_record/fixture_set/render_context.rb +17 -0
  135. data/lib/active_record/fixture_set/table_row.rb +152 -0
  136. data/lib/active_record/fixture_set/table_rows.rb +46 -0
  137. data/lib/active_record/fixtures.rb +200 -481
  138. data/lib/active_record/gem_version.rb +4 -4
  139. data/lib/active_record/inheritance.rb +53 -24
  140. data/lib/active_record/insert_all.rb +208 -0
  141. data/lib/active_record/integration.rb +67 -17
  142. data/lib/active_record/internal_metadata.rb +26 -9
  143. data/lib/active_record/legacy_yaml_adapter.rb +7 -3
  144. data/lib/active_record/locking/optimistic.rb +37 -23
  145. data/lib/active_record/locking/pessimistic.rb +9 -5
  146. data/lib/active_record/log_subscriber.rb +35 -35
  147. data/lib/active_record/middleware/database_selector.rb +77 -0
  148. data/lib/active_record/middleware/database_selector/resolver.rb +92 -0
  149. data/lib/active_record/middleware/database_selector/resolver/session.rb +48 -0
  150. data/lib/active_record/migration.rb +206 -157
  151. data/lib/active_record/migration/command_recorder.rb +96 -44
  152. data/lib/active_record/migration/compatibility.rb +142 -64
  153. data/lib/active_record/migration/join_table.rb +0 -1
  154. data/lib/active_record/model_schema.rb +148 -22
  155. data/lib/active_record/nested_attributes.rb +4 -7
  156. data/lib/active_record/no_touching.rb +8 -1
  157. data/lib/active_record/null_relation.rb +0 -1
  158. data/lib/active_record/persistence.rb +267 -59
  159. data/lib/active_record/query_cache.rb +21 -4
  160. data/lib/active_record/querying.rb +40 -23
  161. data/lib/active_record/railtie.rb +115 -58
  162. data/lib/active_record/railties/console_sandbox.rb +2 -4
  163. data/lib/active_record/railties/controller_runtime.rb +30 -35
  164. data/lib/active_record/railties/databases.rake +408 -78
  165. data/lib/active_record/readonly_attributes.rb +4 -0
  166. data/lib/active_record/reflection.rb +109 -93
  167. data/lib/active_record/relation.rb +374 -104
  168. data/lib/active_record/relation/batches.rb +44 -35
  169. data/lib/active_record/relation/batches/batch_enumerator.rb +25 -9
  170. data/lib/active_record/relation/calculations.rb +153 -90
  171. data/lib/active_record/relation/delegation.rb +35 -50
  172. data/lib/active_record/relation/finder_methods.rb +64 -39
  173. data/lib/active_record/relation/from_clause.rb +5 -1
  174. data/lib/active_record/relation/merger.rb +32 -40
  175. data/lib/active_record/relation/predicate_builder.rb +62 -45
  176. data/lib/active_record/relation/predicate_builder/array_handler.rb +13 -13
  177. data/lib/active_record/relation/predicate_builder/association_query_value.rb +5 -9
  178. data/lib/active_record/relation/predicate_builder/basic_object_handler.rb +1 -2
  179. data/lib/active_record/relation/predicate_builder/polymorphic_array_value.rb +11 -10
  180. data/lib/active_record/relation/predicate_builder/range_handler.rb +3 -23
  181. data/lib/active_record/relation/predicate_builder/relation_handler.rb +1 -1
  182. data/lib/active_record/relation/query_attribute.rb +13 -8
  183. data/lib/active_record/relation/query_methods.rb +475 -186
  184. data/lib/active_record/relation/record_fetch_warning.rb +3 -3
  185. data/lib/active_record/relation/spawn_methods.rb +9 -9
  186. data/lib/active_record/relation/where_clause.rb +111 -61
  187. data/lib/active_record/result.rb +64 -38
  188. data/lib/active_record/runtime_registry.rb +2 -2
  189. data/lib/active_record/sanitization.rb +22 -41
  190. data/lib/active_record/schema.rb +2 -11
  191. data/lib/active_record/schema_dumper.rb +54 -9
  192. data/lib/active_record/schema_migration.rb +7 -9
  193. data/lib/active_record/scoping.rb +8 -9
  194. data/lib/active_record/scoping/default.rb +4 -6
  195. data/lib/active_record/scoping/named.rb +17 -24
  196. data/lib/active_record/secure_token.rb +16 -8
  197. data/lib/active_record/serialization.rb +5 -3
  198. data/lib/active_record/signed_id.rb +116 -0
  199. data/lib/active_record/statement_cache.rb +49 -6
  200. data/lib/active_record/store.rb +88 -9
  201. data/lib/active_record/suppressor.rb +2 -2
  202. data/lib/active_record/table_metadata.rb +42 -43
  203. data/lib/active_record/tasks/database_tasks.rb +277 -81
  204. data/lib/active_record/tasks/mysql_database_tasks.rb +37 -39
  205. data/lib/active_record/tasks/postgresql_database_tasks.rb +27 -32
  206. data/lib/active_record/tasks/sqlite_database_tasks.rb +14 -17
  207. data/lib/active_record/test_databases.rb +24 -0
  208. data/lib/active_record/test_fixtures.rb +246 -0
  209. data/lib/active_record/timestamp.rb +43 -32
  210. data/lib/active_record/touch_later.rb +23 -22
  211. data/lib/active_record/transactions.rb +62 -118
  212. data/lib/active_record/translation.rb +1 -1
  213. data/lib/active_record/type.rb +10 -5
  214. data/lib/active_record/type/adapter_specific_registry.rb +3 -13
  215. data/lib/active_record/type/hash_lookup_type_map.rb +0 -1
  216. data/lib/active_record/type/serialized.rb +6 -3
  217. data/lib/active_record/type/time.rb +10 -0
  218. data/lib/active_record/type/type_map.rb +0 -1
  219. data/lib/active_record/type/unsigned_integer.rb +0 -1
  220. data/lib/active_record/type_caster/connection.rb +15 -15
  221. data/lib/active_record/type_caster/map.rb +8 -8
  222. data/lib/active_record/validations.rb +4 -3
  223. data/lib/active_record/validations/associated.rb +1 -2
  224. data/lib/active_record/validations/numericality.rb +35 -0
  225. data/lib/active_record/validations/uniqueness.rb +38 -30
  226. data/lib/arel.rb +54 -0
  227. data/lib/arel/alias_predication.rb +9 -0
  228. data/lib/arel/attributes/attribute.rb +41 -0
  229. data/lib/arel/collectors/bind.rb +29 -0
  230. data/lib/arel/collectors/composite.rb +39 -0
  231. data/lib/arel/collectors/plain_string.rb +20 -0
  232. data/lib/arel/collectors/sql_string.rb +27 -0
  233. data/lib/arel/collectors/substitute_binds.rb +35 -0
  234. data/lib/arel/crud.rb +42 -0
  235. data/lib/arel/delete_manager.rb +18 -0
  236. data/lib/arel/errors.rb +9 -0
  237. data/lib/arel/expressions.rb +29 -0
  238. data/lib/arel/factory_methods.rb +49 -0
  239. data/lib/arel/insert_manager.rb +49 -0
  240. data/lib/arel/math.rb +45 -0
  241. data/lib/arel/nodes.rb +70 -0
  242. data/lib/arel/nodes/and.rb +32 -0
  243. data/lib/arel/nodes/ascending.rb +23 -0
  244. data/lib/arel/nodes/binary.rb +126 -0
  245. data/lib/arel/nodes/bind_param.rb +44 -0
  246. data/lib/arel/nodes/case.rb +55 -0
  247. data/lib/arel/nodes/casted.rb +62 -0
  248. data/lib/arel/nodes/comment.rb +29 -0
  249. data/lib/arel/nodes/count.rb +12 -0
  250. data/lib/arel/nodes/delete_statement.rb +45 -0
  251. data/lib/arel/nodes/descending.rb +23 -0
  252. data/lib/arel/nodes/equality.rb +15 -0
  253. data/lib/arel/nodes/extract.rb +24 -0
  254. data/lib/arel/nodes/false.rb +16 -0
  255. data/lib/arel/nodes/full_outer_join.rb +8 -0
  256. data/lib/arel/nodes/function.rb +44 -0
  257. data/lib/arel/nodes/grouping.rb +11 -0
  258. data/lib/arel/nodes/homogeneous_in.rb +72 -0
  259. data/lib/arel/nodes/in.rb +15 -0
  260. data/lib/arel/nodes/infix_operation.rb +92 -0
  261. data/lib/arel/nodes/inner_join.rb +8 -0
  262. data/lib/arel/nodes/insert_statement.rb +37 -0
  263. data/lib/arel/nodes/join_source.rb +20 -0
  264. data/lib/arel/nodes/matches.rb +18 -0
  265. data/lib/arel/nodes/named_function.rb +23 -0
  266. data/lib/arel/nodes/node.rb +51 -0
  267. data/lib/arel/nodes/node_expression.rb +13 -0
  268. data/lib/arel/nodes/ordering.rb +27 -0
  269. data/lib/arel/nodes/outer_join.rb +8 -0
  270. data/lib/arel/nodes/over.rb +15 -0
  271. data/lib/arel/nodes/regexp.rb +16 -0
  272. data/lib/arel/nodes/right_outer_join.rb +8 -0
  273. data/lib/arel/nodes/select_core.rb +67 -0
  274. data/lib/arel/nodes/select_statement.rb +41 -0
  275. data/lib/arel/nodes/sql_literal.rb +19 -0
  276. data/lib/arel/nodes/string_join.rb +11 -0
  277. data/lib/arel/nodes/table_alias.rb +31 -0
  278. data/lib/arel/nodes/terminal.rb +16 -0
  279. data/lib/arel/nodes/true.rb +16 -0
  280. data/lib/arel/nodes/unary.rb +44 -0
  281. data/lib/arel/nodes/unary_operation.rb +20 -0
  282. data/lib/arel/nodes/unqualified_column.rb +22 -0
  283. data/lib/arel/nodes/update_statement.rb +41 -0
  284. data/lib/arel/nodes/values_list.rb +9 -0
  285. data/lib/arel/nodes/window.rb +126 -0
  286. data/lib/arel/nodes/with.rb +11 -0
  287. data/lib/arel/order_predications.rb +13 -0
  288. data/lib/arel/predications.rb +250 -0
  289. data/lib/arel/select_manager.rb +270 -0
  290. data/lib/arel/table.rb +118 -0
  291. data/lib/arel/tree_manager.rb +72 -0
  292. data/lib/arel/update_manager.rb +34 -0
  293. data/lib/arel/visitors.rb +13 -0
  294. data/lib/arel/visitors/dot.rb +308 -0
  295. data/lib/arel/visitors/mysql.rb +93 -0
  296. data/lib/arel/visitors/postgresql.rb +120 -0
  297. data/lib/arel/visitors/sqlite.rb +38 -0
  298. data/lib/arel/visitors/to_sql.rb +899 -0
  299. data/lib/arel/visitors/visitor.rb +45 -0
  300. data/lib/arel/window_predications.rb +9 -0
  301. data/lib/rails/generators/active_record/application_record/application_record_generator.rb +0 -1
  302. data/lib/rails/generators/active_record/migration.rb +19 -2
  303. data/lib/rails/generators/active_record/migration/migration_generator.rb +3 -5
  304. data/lib/rails/generators/active_record/migration/templates/create_table_migration.rb.tt +3 -1
  305. data/lib/rails/generators/active_record/migration/templates/migration.rb.tt +7 -5
  306. data/lib/rails/generators/active_record/model/model_generator.rb +39 -2
  307. data/lib/rails/generators/active_record/model/templates/abstract_base_class.rb.tt +7 -0
  308. data/lib/rails/generators/active_record/model/templates/model.rb.tt +10 -1
  309. metadata +119 -34
  310. data/lib/active_record/attribute_decorators.rb +0 -90
  311. data/lib/active_record/collection_cache_key.rb +0 -53
  312. data/lib/active_record/connection_adapters/connection_specification.rb +0 -287
  313. data/lib/active_record/connection_adapters/determine_if_preparable_visitor.rb +0 -33
  314. data/lib/active_record/define_callbacks.rb +0 -22
  315. data/lib/active_record/relation/predicate_builder/base_handler.rb +0 -19
  316. data/lib/active_record/relation/where_clause_factory.rb +0 -34
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c89677cc90fc43ae97552359837dfe44ad6e1ce6334050e4b39785385b810ba3
4
- data.tar.gz: 4af06aec9bb0548a91db3b9f47376040f7dd7ba51b5826ef78ad54d7af441858
3
+ metadata.gz: 4388f56d55688f1f53d21619c1d97a976a0bf198e46813febbaf7a867fb47702
4
+ data.tar.gz: 63314ed55ab0aa06c816b9208764f00a897ec40485c23dc23659ecadf5490d91
5
5
  SHA512:
6
- metadata.gz: becac0be95270f15be72938b50450e0913f46dc8a0e64805e2d9fb1165e2b6a46d6be4df4eb6faa1f8e0cf5740a74ed05c89d8e165835488bcdaa7b42157073e
7
- data.tar.gz: 68692c07b65288b74ff1a55af76fd92846109c874cbaad1f66252461d96739865864fbf842d8e56169fddf0dd1ac935aed1e5ffc78cbac2669e20d1b478e0492
6
+ metadata.gz: d6da5c43903489b203067e4c187ffa405a91d6f35bd0d23087e225b2bc49f9b1ad4e5c4df73f72de8577ed0c044e049b5381a22a0b1c83215b1d3fc3b5b6d4dd
7
+ data.tar.gz: 3e3fffe809e00d052c6147b1e373744ac8875abf94c5225289901184447989a998cd953bbc4a0e644feac0eb4fdf33e14071bf48ac8d6b7741bd1aa962a592ea
data/CHANGELOG.md CHANGED
@@ -1,19 +1,69 @@
1
- ## Rails 5.2.6 (May 05, 2021) ##
1
+ ## Rails 6.1.3.2 (May 05, 2021) ##
2
2
 
3
3
  * No changes.
4
4
 
5
5
 
6
- ## Rails 5.2.5 (March 26, 2021) ##
6
+ ## Rails 6.1.3.1 (March 26, 2021) ##
7
7
 
8
8
  * No changes.
9
9
 
10
10
 
11
- ## Rails 5.2.4.6 (May 05, 2021) ##
11
+ ## Rails 6.1.3 (February 17, 2021) ##
12
12
 
13
- * No changes.
13
+ * Fix the MySQL adapter to always set the right collation and charset
14
+ to the connection session.
15
+
16
+ *Rafael Mendonça França*
17
+
18
+ * Fix MySQL adapter handling of time objects when prepared statements
19
+ are enabled.
20
+
21
+ *Rafael Mendonça França*
22
+
23
+ * Fix scoping in enum fields using conditions that would generate
24
+ an `IN` clause.
25
+
26
+ *Ryuta Kamizono*
27
+
28
+ * Skip optimised #exist? query when #include? is called on a relation
29
+ with a having clause
30
+
31
+ Relations that have aliased select values AND a having clause that
32
+ references an aliased select value would generate an error when
33
+ #include? was called, due to an optimisation that would generate
34
+ call #exists? on the relation instead, which effectively alters
35
+ the select values of the query (and thus removes the aliased select
36
+ values), but leaves the having clause intact. Because the having
37
+ clause is then referencing an aliased column that is no longer
38
+ present in the simplified query, an ActiveRecord::InvalidStatement
39
+ error was raised.
40
+
41
+ An sample query affected by this problem:
42
+
43
+ ```ruby
44
+ Author.select('COUNT(*) as total_posts', 'authors.*')
45
+ .joins(:posts)
46
+ .group(:id)
47
+ .having('total_posts > 2')
48
+ .include?(Author.first)
49
+ ```
50
+
51
+ This change adds an addition check to the condition that skips the
52
+ simplified #exists? query, which simply checks for the presence of
53
+ a having clause.
54
+
55
+ Fixes #41417
56
+
57
+ *Michael Smart*
14
58
 
59
+ * Increment postgres prepared statement counter before making a prepared statement, so if the statement is aborted
60
+ without Rails knowledge (e.g., if app gets kill -9d during long-running query or due to Rack::Timeout), app won't end
61
+ up in perpetual crash state for being inconsistent with Postgres.
15
62
 
16
- ## Rails 5.2.4.5 (February 10, 2021) ##
63
+ *wbharding*, *Martin Tepper*
64
+
65
+
66
+ ## Rails 6.1.2.1 (February 10, 2021) ##
17
67
 
18
68
  * Fix possible DoS vector in PostgreSQL money type
19
69
 
@@ -28,999 +78,1416 @@
28
78
  *Aaron Patterson*
29
79
 
30
80
 
31
- ## Rails 5.2.4.4 (September 09, 2020) ##
81
+ ## Rails 6.1.2 (February 09, 2021) ##
32
82
 
33
- * No changes.
83
+ * Fix timestamp type for sqlite3.
34
84
 
85
+ *Eileen M. Uchitelle*
35
86
 
36
- ## Rails 5.2.4.3 (May 18, 2020) ##
87
+ * Make destroy async transactional.
37
88
 
38
- * No changes.
89
+ An active record rollback could occur while enqueuing a job. In this
90
+ case the job would enqueue even though the database deletion
91
+ rolledback putting things in a funky state.
39
92
 
40
- ## Rails 5.2.4.2 (March 19, 2020) ##
93
+ Now the jobs are only enqueued until after the db transaction has been committed.
41
94
 
42
- * No changes.
95
+ *Cory Gwin*
43
96
 
97
+ * Fix malformed packet error in MySQL statement for connection configuration.
44
98
 
45
- ## Rails 5.2.4.1 (December 18, 2019) ##
99
+ *robinroestenburg*
46
100
 
47
- * No changes.
101
+ * Connection specification now passes the "url" key as a configuration for the
102
+ adapter if the "url" protocol is "jdbc", "http", or "https". Previously only
103
+ urls with the "jdbc" prefix were passed to the Active Record Adapter, others
104
+ are assumed to be adapter specification urls.
48
105
 
106
+ Fixes #41137.
49
107
 
50
- ## Rails 5.2.4 (November 27, 2019) ##
108
+ *Jonathan Bracy*
51
109
 
52
- * Fix circular `autosave: true` causes invalid records to be saved.
110
+ * Fix granular connection swapping when there are multiple abstract classes.
53
111
 
54
- Prior to the fix, when there was a circular series of `autosave: true`
55
- associations, the callback for a `has_many` association was run while
56
- another instance of the same callback on the same association hadn't
57
- finished running. When control returned to the first instance of the
58
- callback, the instance variable had changed, and subsequent associated
59
- records weren't saved correctly. Specifically, the ID field for the
60
- `belongs_to` corresponding to the `has_many` was `nil`.
112
+ *Eileen M. Uchitelle*
61
113
 
62
- Fixes #28080.
114
+ * Fix `find_by` with custom primary key for belongs_to association.
63
115
 
64
- *Larry Reid*
116
+ *Ryuta Kamizono*
65
117
 
66
- * PostgreSQL: Fix GROUP BY with ORDER BY virtual count attribute.
118
+ * Add support for `rails console --sandbox` for multiple database applications.
67
119
 
68
- Fixes #36022.
120
+ *alpaca-tc*
69
121
 
70
- *Ryuta Kamizono*
122
+ * Fix `where` on polymorphic association with empty array.
71
123
 
72
- * Fix sqlite3 collation parsing when using decimal columns.
124
+ *Ryuta Kamizono*
73
125
 
74
- *Martin R. Schuster*
126
+ * Fix preventing writes for `ApplicationRecord`.
75
127
 
76
- * Make ActiveRecord `ConnectionPool.connections` method thread-safe.
128
+ *Eileen M. Uchitelle*
77
129
 
78
- Fixes #36465.
79
130
 
80
- *Jeff Doering*
131
+ ## Rails 6.1.1 (January 07, 2021) ##
81
132
 
82
- * Assign all attributes before calling `build` to ensure the child record is visible in
83
- `before_add` and `after_add` callbacks for `has_many :through` associations.
133
+ * Fix fixtures loading when strict loading is enabled for the association.
84
134
 
85
- Fixes #33249.
135
+ *Alex Ghiculescu*
86
136
 
87
- *Ryan H. Kerr*
137
+ * Fix `where` with custom primary key for belongs_to association.
88
138
 
139
+ *Ryuta Kamizono*
89
140
 
90
- ## Rails 5.2.3 (March 27, 2019) ##
141
+ * Fix `where` with aliased associations.
91
142
 
92
- * Fix different `count` calculation when using `size` with manual `select` with DISTINCT.
143
+ *Ryuta Kamizono*
93
144
 
94
- Fixes #35214.
145
+ * Fix `composed_of` with symbol mapping.
95
146
 
96
- *Juani Villarejo*
147
+ *Ryuta Kamizono*
97
148
 
98
- * Fix prepared statements caching to be enabled even when query caching is enabled.
149
+ * Don't skip money's type cast for pluck and calculations.
99
150
 
100
151
  *Ryuta Kamizono*
101
152
 
102
- * Don't allow `where` with invalid value matches to nil values.
103
-
104
- Fixes #33624.
153
+ * Fix `where` on polymorphic association with non Active Record object.
105
154
 
106
155
  *Ryuta Kamizono*
107
156
 
108
- * Restore an ability that class level `update` without giving ids.
157
+ * Make sure `db:prepare` works even the schema file doesn't exist.
109
158
 
110
- Fixes #34743.
159
+ *Rafael Mendonça França*
160
+
161
+ * Fix complicated `has_many :through` with nested where condition.
111
162
 
112
163
  *Ryuta Kamizono*
113
164
 
114
- * Fix join table column quoting with SQLite.
165
+ * Handle STI models for `has_many dependent: :destroy_async`.
115
166
 
116
- *Gannon McGibbon*
167
+ *Muhammad Usman*
117
168
 
118
- * Ensure that `delete_all` on collection proxy returns affected count.
169
+ * Restore possibility of passing `false` to :polymorphic option of `belongs_to`.
119
170
 
120
- *Ryuta Kamizono*
171
+ Previously, passing `false` would trigger the option validation logic
172
+ to throw an error saying :polymorphic would not be a valid option.
121
173
 
122
- * Reset scope after delete on collection association to clear stale offsets of removed records.
174
+ *glaszig*
123
175
 
124
- *Gannon McGibbon*
176
+ * Allow adding nonnamed expression indexes to be revertible.
125
177
 
178
+ Fixes #40732.
126
179
 
127
- ## Rails 5.2.2.1 (March 11, 2019) ##
180
+ Previously, the following code would raise an error, when executed while rolling back,
181
+ and the index name should be specified explicitly. Now, the index name is inferred
182
+ automatically.
128
183
 
129
- * No changes.
184
+ ```ruby
185
+ add_index(:items, "to_tsvector('english', description)")
186
+ ```
130
187
 
188
+ *fatkodima*
131
189
 
132
- ## Rails 5.2.2 (December 04, 2018) ##
133
190
 
134
- * Do not ignore the scoping with query methods in the scope block.
191
+ ## Rails 6.1.0 (December 09, 2020) ##
135
192
 
136
- *Ryuta Kamizono*
193
+ * Only warn about negative enums if a positive form that would cause conflicts exists.
137
194
 
138
- * Allow aliased attributes to be used in `#update_columns` and `#update`.
195
+ Fixes #39065.
139
196
 
140
- *Gannon McGibbon*
197
+ *Alex Ghiculescu*
141
198
 
142
- * Allow spaces in postgres table names.
199
+ * Change `attribute_for_inspect` to take `filter_attributes` in consideration.
143
200
 
144
- Fixes issue where "user post" is misinterpreted as "\"user\".\"post\"" when quoting table names with the postgres
145
- adapter.
201
+ *Rafael Mendonça França*
146
202
 
147
- *Gannon McGibbon*
203
+ * Fix odd behavior of inverse_of with multiple belongs_to to same class.
148
204
 
149
- * Cached columns_hash fields should be excluded from ResultSet#column_types
205
+ Fixes #35204.
150
206
 
151
- PR #34528 addresses the inconsistent behaviour when attribute is defined for an ignored column. The following test
152
- was passing for SQLite and MySQL, but failed for PostgreSQL:
207
+ *Tomoyuki Kai*
208
+
209
+ * Build predicate conditions with objects that delegate `#id` and primary key:
153
210
 
154
211
  ```ruby
155
- class DeveloperName < ActiveRecord::Type::String
156
- def deserialize(value)
157
- "Developer: #{value}"
212
+ class AdminAuthor
213
+ delegate_missing_to :@author
214
+
215
+ def initialize(author)
216
+ @author = author
158
217
  end
159
218
  end
160
219
 
161
- class AttributedDeveloper < ActiveRecord::Base
162
- self.table_name = "developers"
220
+ Post.where(author: AdminAuthor.new(author))
221
+ ```
163
222
 
164
- attribute :name, DeveloperName.new
223
+ *Sean Doyle*
165
224
 
166
- self.ignored_columns += ["name"]
167
- end
225
+ * Add `connected_to_many` API.
168
226
 
169
- developer = AttributedDeveloper.create
170
- developer.update_column :name, "name"
227
+ This API allows applications to connect to multiple databases at once without switching all of them or implementing a deeply nested stack.
171
228
 
172
- loaded_developer = AttributedDeveloper.where(id: developer.id).select("*").first
173
- puts loaded_developer.name # should be "Developer: name" but it's just "name"
174
- ```
175
-
176
- *Dmitry Tsepelev*
229
+ Before:
177
230
 
178
- * Values of enum are frozen, raising an error when attempting to modify them.
231
+ AnimalsRecord.connected_to(role: :reading) do
232
+ MealsRecord.connected_to(role: :reading) do
233
+ Dog.first # read from animals replica
234
+ Dinner.first # read from meals replica
235
+ Person.first # read from primary writer
236
+ end
237
+ end
179
238
 
180
- *Emmanuel Byrd*
239
+ After:
181
240
 
182
- * `update_columns` now correctly raises `ActiveModel::MissingAttributeError`
183
- if the attribute does not exist.
241
+ ActiveRecord::Base.connected_to_many([AnimalsRecord, MealsRecord], role: :reading) do
242
+ Dog.first # read from animals replica
243
+ Dinner.first # read from meals replica
244
+ Person.first # read from primary writer
245
+ end
184
246
 
185
- *Sean Griffin*
247
+ *Eileen M. Uchitelle*, *John Crepezzi*
186
248
 
187
- * Do not use prepared statement in queries that have a large number of binds.
249
+ * Add option to raise or log for `ActiveRecord::StrictLoadingViolationError`.
188
250
 
189
- *Ryuta Kamizono*
251
+ 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.
190
252
 
191
- * Fix query cache to load before first request.
253
+ Set `config.active_record.action_on_strict_loading_violation` to `:log` errors instead of raising.
192
254
 
193
255
  *Eileen M. Uchitelle*
194
256
 
195
- * Fix collection cache key with limit and custom select to avoid ambiguous timestamp column error.
257
+ * Allow the inverse of a `has_one` association that was previously autosaved to be loaded.
196
258
 
197
- Fixes #33056.
259
+ Fixes #34255.
198
260
 
199
- *Federico Martinez*
261
+ *Steven Weber*
200
262
 
201
- * Fix duplicated record creation when using nested attributes with `create_with`.
263
+ * Optimise the length of index names for polymorphic references by using the reference name rather than the type and id column names.
202
264
 
203
- *Darwin Wu*
265
+ 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.
204
266
 
205
- * Fix regression setting children record in parent `before_save` callback.
267
+ This change reduces the chance of that happening by using the reference name, e.g. `index_my_table_on_my_reference`.
206
268
 
207
- *Guo Xiang Tan*
269
+ Fixes #38655.
208
270
 
209
- * Prevent leaking of user's DB credentials on `rails db:create` failure.
271
+ *Luke Redpath*
210
272
 
211
- *bogdanvlviv*
273
+ * MySQL: Uniqueness validator now respects default database collation,
274
+ no longer enforce case sensitive comparison by default.
212
275
 
213
- * Clear mutation tracker before continuing the around callbacks.
276
+ *Ryuta Kamizono*
214
277
 
215
- *Yuya Tanaka*
278
+ * Remove deprecated methods from `ActiveRecord::ConnectionAdapters::DatabaseLimits`.
216
279
 
217
- * Prevent deadlocks when waiting for connection from pool.
280
+ `column_name_length`
281
+ `table_name_length`
282
+ `columns_per_table`
283
+ `indexes_per_table`
284
+ `columns_per_multicolumn_index`
285
+ `sql_query_length`
286
+ `joins_per_query`
218
287
 
219
- *Brent Wheeldon*
288
+ *Rafael Mendonça França*
220
289
 
221
- * Avoid extra scoping when using `Relation#update` that was causing this method to change the current scope.
290
+ * Remove deprecated `ActiveRecord::ConnectionAdapters::AbstractAdapter#supports_multi_insert?`.
222
291
 
223
- *Ryuta Kamizono*
292
+ *Rafael Mendonça França*
224
293
 
225
- * Fix numericality validator not to be affected by custom getter.
294
+ * Remove deprecated `ActiveRecord::ConnectionAdapters::AbstractAdapter#supports_foreign_keys_in_create?`.
226
295
 
227
- *Ryuta Kamizono*
296
+ *Rafael Mendonça França*
228
297
 
229
- * Fix bulk change table ignores comment option on PostgreSQL.
298
+ * Remove deprecated `ActiveRecord::ConnectionAdapters::PostgreSQLAdapter#supports_ranges?`.
230
299
 
231
- *Yoshiyuki Kinjo*
300
+ *Rafael Mendonça França*
232
301
 
302
+ * Remove deprecated `ActiveRecord::Base#update_attributes` and `ActiveRecord::Base#update_attributes!`.
233
303
 
234
- ## Rails 5.2.1.1 (November 27, 2018) ##
304
+ *Rafael Mendonça França*
235
305
 
236
- * No changes.
306
+ * Remove deprecated `migrations_path` argument in `ActiveRecord::ConnectionAdapter::SchemaStatements#assume_migrated_upto_version`.
237
307
 
308
+ *Rafael Mendonça França*
309
+
310
+ * Remove deprecated `config.active_record.sqlite3.represent_boolean_as_integer`.
311
+
312
+ *Rafael Mendonça França*
238
313
 
239
- ## Rails 5.2.1 (August 07, 2018) ##
314
+ * `relation.create` does no longer leak scope to class level querying methods
315
+ in initialization block and callbacks.
240
316
 
241
- * PostgreSQL: Support new relkind for partitioned tables.
317
+ Before:
242
318
 
243
- Fixes #33008.
319
+ User.where(name: "John").create do |john|
320
+ User.find_by(name: "David") # => nil
321
+ end
244
322
 
245
- *Yannick Schutz*
323
+ After:
246
324
 
247
- * Rollback parent transaction when children fails to update.
325
+ User.where(name: "John").create do |john|
326
+ User.find_by(name: "David") # => #<User name: "David", ...>
327
+ end
248
328
 
249
- *Guillaume Malette*
329
+ *Ryuta Kamizono*
250
330
 
251
- * Fix default value for MySQL time types with specified precision.
331
+ * Named scope chain does no longer leak scope to class level querying methods.
252
332
 
253
- *Nikolay Kondratyev*
333
+ class User < ActiveRecord::Base
334
+ scope :david, -> { User.where(name: "David") }
335
+ end
254
336
 
255
- * Fix `touch` option to behave consistently with `Persistence#touch` method.
337
+ Before:
256
338
 
257
- *Ryuta Kamizono*
339
+ User.where(name: "John").david
340
+ # SELECT * FROM users WHERE name = 'John' AND name = 'David'
258
341
 
259
- * Fix `save` in `after_create_commit` won't invoke extra `after_create_commit`.
342
+ After:
260
343
 
261
- Fixes #32831.
344
+ User.where(name: "John").david
345
+ # SELECT * FROM users WHERE name = 'David'
262
346
 
263
347
  *Ryuta Kamizono*
264
348
 
265
- * Fix logic on disabling commit callbacks so they are not called unexpectedly when errors occur.
349
+ * Remove deprecated methods from `ActiveRecord::DatabaseConfigurations`.
266
350
 
267
- *Brian Durand*
351
+ `fetch`
352
+ `each`
353
+ `first`
354
+ `values`
355
+ `[]=`
268
356
 
269
- * Fix parent record should not get saved with duplicate children records.
357
+ *Rafael Mendonça França*
270
358
 
271
- Fixes #32940.
359
+ * `where.not` now generates NAND predicates instead of NOR.
272
360
 
273
- *Santosh Wadghule*
361
+ Before:
274
362
 
275
- * Fix that association's after_touch is not called with counter cache.
363
+ User.where.not(name: "Jon", role: "admin")
364
+ # SELECT * FROM users WHERE name != 'Jon' AND role != 'admin'
276
365
 
277
- Fixes #31559.
366
+ After:
278
367
 
279
- *Ryuta Kamizono*
368
+ User.where.not(name: "Jon", role: "admin")
369
+ # SELECT * FROM users WHERE NOT (name == 'Jon' AND role == 'admin')
280
370
 
281
- * `becomes` should clear the mutation tracker which is created in `after_initialize`.
371
+ *Rafael Mendonça França*
282
372
 
283
- Fixes #32867.
373
+ * Remove deprecated `ActiveRecord::Result#to_hash` method.
284
374
 
285
- *Ryuta Kamizono*
375
+ *Rafael Mendonça França*
286
376
 
287
- * Allow a belonging to parent object to be created from a new record.
377
+ * Deprecate `ActiveRecord::Base.allow_unsafe_raw_sql`.
288
378
 
289
- *Jolyon Pawlyn*
379
+ *Rafael Mendonça França*
290
380
 
291
- * Fix that building record with assigning multiple has_one associations
292
- wrongly persists through record.
381
+ * Remove deprecated support for using unsafe raw SQL in `ActiveRecord::Relation` methods.
293
382
 
294
- Fixes #32511.
383
+ *Rafael Mendonça França*
295
384
 
296
- *Sam DeCesare*
385
+ * Allow users to silence the "Rails couldn't infer whether you are using multiple databases..."
386
+ message using `config.active_record.suppress_multiple_database_warning`.
297
387
 
298
- * Fix relation merging when one of the relations is going to skip the
299
- query cache.
388
+ *Omri Gabay*
300
389
 
301
- *James Williams*
390
+ * Connections can be granularly switched for abstract classes when `connected_to` is called.
302
391
 
392
+ 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.
303
393
 
304
- ## Rails 5.2.0 (April 09, 2018) ##
394
+ Example usage:
305
395
 
306
- * MySQL: Support mysql2 0.5.x.
396
+ 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`.
307
397
 
308
- *Aaron Stone*
398
+ ```ruby
399
+ ActiveRecord::Base.connected_to(role: :reading) do
400
+ User.first # reads from default replica
401
+ Dog.first # reads from default replica
309
402
 
310
- * Apply time column precision on assignment.
403
+ AnimalsRecord.connected_to(role: :writing, shard: :one) do
404
+ User.first # reads from default replica
405
+ Dog.first # reads from shard one primary
406
+ end
311
407
 
312
- PR #20317 changed the behavior of datetime columns so that when they
313
- have a specified precision then on assignment the value is rounded to
314
- that precision. This behavior is now applied to time columns as well.
408
+ User.first # reads from default replica
409
+ Dog.first # reads from default replica
315
410
 
316
- Fixes #30301.
411
+ ApplicationRecord.connected_to(role: :writing, shard: :two) do
412
+ User.first # reads from shard two primary
413
+ Dog.first # reads from default replica
414
+ end
415
+ end
416
+ ```
317
417
 
318
- *Andrew White*
418
+ *Eileen M. Uchitelle*, *John Crepezzi*
319
419
 
320
- * Normalize time column values for SQLite database.
420
+ * Allow double-dash comment syntax when querying read-only databases
321
421
 
322
- For legacy reasons, time columns in SQLite are stored as full datetimes
323
- because until #24542 the quoting for time columns didn't remove the date
324
- component. To ensure that values are consistent we now normalize the
325
- date component to 2001-01-01 on reading and writing.
422
+ *James Adam*
326
423
 
327
- *Andrew White*
424
+ * Add `values_at` method.
328
425
 
329
- * Ensure that the date component is removed when quoting times.
426
+ Returns an array containing the values associated with the given methods.
330
427
 
331
- PR #24542 altered the quoting for time columns so that the date component
332
- was removed however it only removed it when it was 2001-01-01. Now the
333
- date component is removed irrespective of what the date is.
428
+ ```ruby
429
+ topic = Topic.first
430
+ topic.values_at(:title, :author_name)
431
+ # => ["Budget", "Jason"]
432
+ ```
334
433
 
335
- *Andrew White*
434
+ Similar to `Hash#values_at` but on an Active Record instance.
336
435
 
337
- * Fix `dependent: :destroy` issue for has_one/belongs_to relationship where
338
- the parent class was getting deleted when the child was not.
436
+ *Guillaume Briday*
339
437
 
340
- Fixes #32022.
438
+ * Fix `read_attribute_before_type_cast` to consider attribute aliases.
341
439
 
342
- *Fernando Gorodscy*
440
+ *Marcelo Lauxen*
343
441
 
344
- * Whitelist `NULLS FIRST` and `NULLS LAST` in order clauses too.
442
+ * Support passing record to uniqueness validator `:conditions` callable:
345
443
 
346
- *Xavier Noria*
444
+ ```ruby
445
+ class Article < ApplicationRecord
446
+ validates_uniqueness_of :title, conditions: ->(article) {
447
+ published_at = article.published_at
448
+ where(published_at: published_at.beginning_of_year..published_at.end_of_year)
449
+ }
450
+ end
451
+ ```
347
452
 
348
- * Fix that after commit callbacks on update does not triggered when optimistic locking is enabled.
453
+ *Eliot Sykes*
349
454
 
350
- *Ryuta Kamizono*
455
+ * `BatchEnumerator#update_all` and `BatchEnumerator#delete_all` now return the
456
+ total number of rows affected, just like their non-batched counterparts.
351
457
 
352
- * Fix `#columns_for_distinct` of MySQL and PostgreSQL to make
353
- `ActiveRecord::FinderMethods#limited_ids_for` use correct primary key values
354
- even if `ORDER BY` columns include other table's primary key.
458
+ ```ruby
459
+ Person.in_batches.update_all("first_name = 'Eugene'") # => 42
460
+ Person.in_batches.delete_all # => 42
461
+ ```
355
462
 
356
- Fixes #28364.
463
+ Fixes #40287.
357
464
 
358
- *Takumi Kagiyama*
465
+ *Eugene Kenny*
359
466
 
360
- * Make `reflection.klass` raise if `polymorphic?` not to be misused.
467
+ * Add support for PostgreSQL `interval` data type with conversion to
468
+ `ActiveSupport::Duration` when loading records from database and
469
+ serialization to ISO 8601 formatted duration string on save.
470
+ Add support to define a column in migrations and get it in a schema dump.
471
+ Optional column precision is supported.
361
472
 
362
- Fixes #31876.
473
+ To use this in 6.1, you need to place the next string to your model file:
363
474
 
364
- *Ryuta Kamizono*
475
+ attribute :duration, :interval
365
476
 
366
- * PostgreSQL: Allow pg-1.0 gem to be used with Active Record.
477
+ To keep old behavior until 6.2 is released:
367
478
 
368
- *Lars Kanis*
479
+ attribute :duration, :string
369
480
 
370
- * Deprecate `expand_hash_conditions_for_aggregates` without replacement.
371
- Using a `Relation` for performing queries is the prefered API.
481
+ Example:
372
482
 
373
- *Ryuta Kamizono*
483
+ create_table :events do |t|
484
+ t.string :name
485
+ t.interval :duration
486
+ end
374
487
 
375
- * Fix not expanded problem when passing an Array object as argument to the where method using `composed_of` column.
488
+ class Event < ApplicationRecord
489
+ attribute :duration, :interval
490
+ end
376
491
 
377
- ```
378
- david_balance = customers(:david).balance
379
- Customer.where(balance: [david_balance]).to_sql
492
+ Event.create!(name: 'Rock Fest', duration: 2.days)
493
+ Event.last.duration # => 2 days
494
+ Event.last.duration.iso8601 # => "P2D"
495
+ Event.new(duration: 'P1DT12H3S').duration # => 1 day, 12 hours, and 3 seconds
496
+ Event.new(duration: '1 day') # Unknown value will be ignored and NULL will be written to database
380
497
 
381
- # Before: WHERE `customers`.`balance` = NULL
382
- # After : WHERE `customers`.`balance` = 50
498
+ *Andrey Novikov*
499
+
500
+ * Allow associations supporting the `dependent:` key to take `dependent: :destroy_async`.
501
+
502
+ ```ruby
503
+ class Account < ActiveRecord::Base
504
+ belongs_to :supplier, dependent: :destroy_async
505
+ end
383
506
  ```
384
507
 
385
- Fixes #31723.
508
+ `:destroy_async` will enqueue a job to destroy associated records in the background.
386
509
 
387
- *Yutaro Kanagawa*
510
+ *DHH*, *George Claghorn*, *Cory Gwin*, *Rafael Mendonça França*, *Adrianna Chang*
388
511
 
389
- * Fix `count(:all)` with eager loading and having an order other than the driving table.
512
+ * Add `SKIP_TEST_DATABASE` environment variable to disable modifying the test database when `rails db:create` and `rails db:drop` are called.
390
513
 
391
- Fixes #31783.
514
+ *Jason Schweier*
392
515
 
393
- *Ryuta Kamizono*
516
+ * `connects_to` can only be called on `ActiveRecord::Base` or abstract classes.
394
517
 
395
- * Clear the transaction state when an Active Record object is duped.
518
+ 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.
396
519
 
397
- Fixes #31670.
520
+ *Eileen M. Uchitelle*, *John Crepezzi*
398
521
 
399
- *Yuriy Ustushenko*
522
+ * All connection adapters `execute` now raises `ActiveRecord::ConnectionNotEstablished` rather than
523
+ `ActiveRecord::StatementInvalid` when they encounter a connection error.
400
524
 
401
- * Support for PostgreSQL foreign tables.
525
+ *Jean Boussier*
402
526
 
403
- *fatkodima*
527
+ * `Mysql2Adapter#quote_string` now raises `ActiveRecord::ConnectionNotEstablished` rather than
528
+ `ActiveRecord::StatementInvalid` when it can't connect to the MySQL server.
404
529
 
405
- * Fix relation merger issue with `left_outer_joins`.
530
+ *Jean Boussier*
406
531
 
407
- *Mehmet Emin İNAÇ*
532
+ * Add support for check constraints that are `NOT VALID` via `validate: false` (PostgreSQL-only).
408
533
 
409
- * Don't allow destroyed object mutation after `save` or `save!` is called.
534
+ *Alex Robbin*
410
535
 
411
- *Ryuta Kamizono*
536
+ * Ensure the default configuration is considered primary or first for an environment
412
537
 
413
- * Take into account association conditions when deleting through records.
538
+ 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.
414
539
 
415
- Fixes #18424.
540
+ *Eileen M. Uchitelle*
416
541
 
417
- *Piotr Jakubowski*
542
+ * Allow `where` references association names as joined table name aliases.
418
543
 
419
- * Fix nested `has_many :through` associations on unpersisted parent instances.
544
+ ```ruby
545
+ class Comment < ActiveRecord::Base
546
+ enum label: [:default, :child]
547
+ has_many :children, class_name: "Comment", foreign_key: :parent_id
548
+ end
420
549
 
421
- For example, if you have
550
+ # ... FROM comments LEFT OUTER JOIN comments children ON ... WHERE children.label = 1
551
+ Comment.includes(:children).where("children.label": "child")
552
+ ```
422
553
 
423
- class Post < ActiveRecord::Base
424
- belongs_to :author
425
- has_many :books, through: :author
426
- has_many :subscriptions, through: :books
427
- end
554
+ *Ryuta Kamizono*
428
555
 
429
- class Author < ActiveRecord::Base
430
- has_one :post
431
- has_many :books
432
- has_many :subscriptions, through: :books
433
- end
556
+ * Support storing demodulized class name for polymorphic type.
434
557
 
435
- class Book < ActiveRecord::Base
436
- belongs_to :author
437
- has_many :subscriptions
438
- end
558
+ Before Rails 6.1, storing demodulized class name is supported only for STI type
559
+ by `store_full_sti_class` class attribute.
439
560
 
440
- class Subscription < ActiveRecord::Base
441
- belongs_to :book
442
- end
561
+ Now `store_full_class_name` class attribute can handle both STI and polymorphic types.
443
562
 
444
- Before:
563
+ *Ryuta Kamizono*
445
564
 
446
- If `post` is not persisted, then `post.subscriptions` will be empty.
565
+ * Deprecate `rails db:structure:{load, dump}` tasks and extend
566
+ `rails db:schema:{load, dump}` tasks to work with either `:ruby` or `:sql` format,
567
+ depending on `config.active_record.schema_format` configuration value.
447
568
 
448
- After:
569
+ *fatkodima*
449
570
 
450
- If `post` is not persisted, then `post.subscriptions` can be set and used
451
- just like it would if `post` were persisted.
571
+ * Respect the `select` values for eager loading.
452
572
 
453
- Fixes #16313.
573
+ ```ruby
574
+ post = Post.select("UPPER(title) AS title").first
575
+ post.title # => "WELCOME TO THE WEBLOG"
576
+ post.body # => ActiveModel::MissingAttributeError
577
+
578
+ # Rails 6.0 (ignore the `select` values)
579
+ post = Post.select("UPPER(title) AS title").eager_load(:comments).first
580
+ post.title # => "Welcome to the weblog"
581
+ post.body # => "Such a lovely day"
582
+
583
+ # Rails 6.1 (respect the `select` values)
584
+ post = Post.select("UPPER(title) AS title").eager_load(:comments).first
585
+ post.title # => "WELCOME TO THE WEBLOG"
586
+ post.body # => ActiveModel::MissingAttributeError
587
+ ```
454
588
 
455
- *Zoltan Kiss*
589
+ *Ryuta Kamizono*
456
590
 
457
- * Fixed inconsistency with `first(n)` when used with `limit()`.
458
- The `first(n)` finder now respects the `limit()`, making it consistent
459
- with `relation.to_a.first(n)`, and also with the behavior of `last(n)`.
591
+ * Allow attribute's default to be configured but keeping its own type.
460
592
 
461
- Fixes #23979.
593
+ ```ruby
594
+ class Post < ActiveRecord::Base
595
+ attribute :written_at, default: -> { Time.now.utc }
596
+ end
462
597
 
463
- *Brian Christian*
598
+ # Rails 6.0
599
+ Post.type_for_attribute(:written_at) # => #<Type::Value ... precision: nil, ...>
464
600
 
465
- * Use `count(:all)` in `HasManyAssociation#count_records` to prevent invalid
466
- SQL queries for association counting.
601
+ # Rails 6.1
602
+ Post.type_for_attribute(:written_at) # => #<Type::DateTime ... precision: 6, ...>
603
+ ```
467
604
 
468
- *Klas Eskilson*
605
+ *Ryuta Kamizono*
469
606
 
470
- * Fix to invoke callbacks when using `update_attribute`.
607
+ * Allow default to be configured for Enum.
471
608
 
472
- *Mike Busch*
609
+ ```ruby
610
+ class Book < ActiveRecord::Base
611
+ enum status: [:proposed, :written, :published], _default: :published
612
+ end
473
613
 
474
- * Fix `count(:all)` to correctly work `distinct` with custom SELECT list.
614
+ Book.new.status # => "published"
615
+ ```
475
616
 
476
617
  *Ryuta Kamizono*
477
618
 
478
- * Using subselect for `delete_all` with `limit` or `offset`.
619
+ * Deprecate YAML loading from legacy format older than Rails 5.0.
479
620
 
480
621
  *Ryuta Kamizono*
481
622
 
482
- * Undefine attribute methods on descendants when resetting column
483
- information.
623
+ * Added the setting `ActiveRecord::Base.immutable_strings_by_default`, which
624
+ allows you to specify that all string columns should be frozen unless
625
+ otherwise specified. This will reduce memory pressure for applications which
626
+ do not generally mutate string properties of Active Record objects.
484
627
 
485
- *Chris Salzberg*
628
+ *Sean Griffin*, *Ryuta Kamizono*
486
629
 
487
- * Log database query callers.
630
+ * Deprecate `map!` and `collect!` on `ActiveRecord::Result`.
488
631
 
489
- Add `verbose_query_logs` configuration option to display the caller
490
- of database queries in the log to facilitate N+1 query resolution
491
- and other debugging.
632
+ *Ryuta Kamizono*
492
633
 
493
- Enabled in development only for new and upgraded applications. Not
494
- recommended for use in the production environment since it relies
495
- on Ruby's `Kernel#caller_locations` which is fairly slow.
634
+ * Support `relation.and` for intersection as Set theory.
496
635
 
497
- *Olivier Lacan*
636
+ ```ruby
637
+ david_and_mary = Author.where(id: [david, mary])
638
+ mary_and_bob = Author.where(id: [mary, bob])
498
639
 
499
- * Fix conflicts `counter_cache` with `touch: true` by optimistic locking.
640
+ david_and_mary.merge(mary_and_bob) # => [mary, bob]
500
641
 
642
+ david_and_mary.and(mary_and_bob) # => [mary]
643
+ david_and_mary.or(mary_and_bob) # => [david, mary, bob]
501
644
  ```
502
- # create_table :posts do |t|
503
- # t.integer :comments_count, default: 0
504
- # t.integer :lock_version
505
- # t.timestamps
506
- # end
507
- class Post < ApplicationRecord
645
+
646
+ *Ryuta Kamizono*
647
+
648
+ * Merging conditions on the same column no longer maintain both conditions,
649
+ and will be consistently replaced by the latter condition in Rails 6.2.
650
+ To migrate to Rails 6.2's behavior, use `relation.merge(other, rewhere: true)`.
651
+
652
+ ```ruby
653
+ # Rails 6.1 (IN clause is replaced by merger side equality condition)
654
+ Author.where(id: [david.id, mary.id]).merge(Author.where(id: bob)) # => [bob]
655
+
656
+ # Rails 6.1 (both conflict conditions exists, deprecated)
657
+ Author.where(id: david.id..mary.id).merge(Author.where(id: bob)) # => []
658
+
659
+ # Rails 6.1 with rewhere to migrate to Rails 6.2's behavior
660
+ Author.where(id: david.id..mary.id).merge(Author.where(id: bob), rewhere: true) # => [bob]
661
+
662
+ # Rails 6.2 (same behavior with IN clause, mergee side condition is consistently replaced)
663
+ Author.where(id: [david.id, mary.id]).merge(Author.where(id: bob)) # => [bob]
664
+ Author.where(id: david.id..mary.id).merge(Author.where(id: bob)) # => [bob]
665
+ ```
666
+
667
+ *Ryuta Kamizono*
668
+
669
+ * Do not mark Postgresql MAC address and UUID attributes as changed when the assigned value only varies by case.
670
+
671
+ *Peter Fry*
672
+
673
+ * Resolve issue with insert_all unique_by option when used with expression index.
674
+
675
+ When the `:unique_by` option of `ActiveRecord::Persistence.insert_all` and
676
+ `ActiveRecord::Persistence.upsert_all` was used with the name of an expression index, an error
677
+ was raised. Adding a guard around the formatting behavior for the `:unique_by` corrects this.
678
+
679
+ Usage:
680
+
681
+ ```ruby
682
+ create_table :books, id: :integer, force: true do |t|
683
+ t.column :name, :string
684
+ t.index "lower(name)", unique: true
508
685
  end
509
686
 
510
- # create_table :comments do |t|
511
- # t.belongs_to :post
512
- # end
513
- class Comment < ApplicationRecord
514
- belongs_to :post, touch: true, counter_cache: true
687
+ Book.insert_all [{ name: "MyTest" }], unique_by: :index_books_on_lower_name
688
+ ```
689
+
690
+ Fixes #39516.
691
+
692
+ *Austen Madden*
693
+
694
+ * Add basic support for CHECK constraints to database migrations.
695
+
696
+ Usage:
697
+
698
+ ```ruby
699
+ add_check_constraint :products, "price > 0", name: "price_check"
700
+ remove_check_constraint :products, name: "price_check"
701
+ ```
702
+
703
+ *fatkodima*
704
+
705
+ * Add `ActiveRecord::Base.strict_loading_by_default` and `ActiveRecord::Base.strict_loading_by_default=`
706
+ to enable/disable strict_loading mode by default for a model. The configuration's value is
707
+ inheritable by subclasses, but they can override that value and it will not impact parent class.
708
+
709
+ Usage:
710
+
711
+ ```ruby
712
+ class Developer < ApplicationRecord
713
+ self.strict_loading_by_default = true
714
+
715
+ has_many :projects
515
716
  end
717
+
718
+ dev = Developer.first
719
+ dev.projects.first
720
+ # => ActiveRecord::StrictLoadingViolationError Exception: Developer is marked as strict_loading and Project cannot be lazily loaded.
516
721
  ```
517
722
 
723
+ *bogdanvlviv*
724
+
725
+ * Deprecate passing an Active Record object to `quote`/`type_cast` directly.
726
+
727
+ *Ryuta Kamizono*
728
+
729
+ * Default engine `ENGINE=InnoDB` is no longer dumped to make schema more agnostic.
730
+
518
731
  Before:
519
- ```
520
- post = Post.create!
521
- # => begin transaction
522
- INSERT INTO "posts" ("created_at", "updated_at", "lock_version")
523
- VALUES ("2017-12-11 21:27:11.387397", "2017-12-11 21:27:11.387397", 0)
524
- commit transaction
525
-
526
- comment = Comment.create!(post: post)
527
- # => begin transaction
528
- INSERT INTO "comments" ("post_id") VALUES (1)
529
-
530
- UPDATE "posts" SET "comments_count" = COALESCE("comments_count", 0) + 1,
531
- "lock_version" = COALESCE("lock_version", 0) + 1 WHERE "posts"."id" = 1
532
-
533
- UPDATE "posts" SET "updated_at" = '2017-12-11 21:27:11.398330',
534
- "lock_version" = 1 WHERE "posts"."id" = 1 AND "posts"."lock_version" = 0
535
- rollback transaction
536
- # => ActiveRecord::StaleObjectError: Attempted to touch a stale object: Post.
537
-
538
- Comment.take.destroy!
539
- # => begin transaction
540
- DELETE FROM "comments" WHERE "comments"."id" = 1
541
-
542
- UPDATE "posts" SET "comments_count" = COALESCE("comments_count", 0) - 1,
543
- "lock_version" = COALESCE("lock_version", 0) + 1 WHERE "posts"."id" = 1
544
-
545
- UPDATE "posts" SET "updated_at" = '2017-12-11 21:42:47.785901',
546
- "lock_version" = 1 WHERE "posts"."id" = 1 AND "posts"."lock_version" = 0
547
- rollback transaction
548
- # => ActiveRecord::StaleObjectError: Attempted to touch a stale object: Post.
732
+
733
+ ```ruby
734
+ create_table "accounts", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci", force: :cascade do |t|
735
+ end
549
736
  ```
550
737
 
551
738
  After:
552
- ```
553
- post = Post.create!
554
- # => begin transaction
555
- INSERT INTO "posts" ("created_at", "updated_at", "lock_version")
556
- VALUES ("2017-12-11 21:27:11.387397", "2017-12-11 21:27:11.387397", 0)
557
- commit transaction
558
-
559
- comment = Comment.create!(post: post)
560
- # => begin transaction
561
- INSERT INTO "comments" ("post_id") VALUES (1)
562
-
563
- UPDATE "posts" SET "comments_count" = COALESCE("comments_count", 0) + 1,
564
- "lock_version" = COALESCE("lock_version", 0) + 1,
565
- "updated_at" = '2017-12-11 21:37:09.802642' WHERE "posts"."id" = 1
566
- commit transaction
567
-
568
- comment.destroy!
569
- # => begin transaction
570
- DELETE FROM "comments" WHERE "comments"."id" = 1
571
-
572
- UPDATE "posts" SET "comments_count" = COALESCE("comments_count", 0) - 1,
573
- "lock_version" = COALESCE("lock_version", 0) + 1,
574
- "updated_at" = '2017-12-11 21:39:02.685520' WHERE "posts"."id" = 1
575
- commit transaction
739
+
740
+ ```ruby
741
+ create_table "accounts", charset: "utf8mb4", collation: "utf8mb4_0900_ai_ci", force: :cascade do |t|
742
+ end
576
743
  ```
577
744
 
578
- Fixes #31199.
745
+ *Ryuta Kamizono*
579
746
 
580
- *bogdanvlviv*
747
+ * Added delegated type as an alternative to single-table inheritance for representing class hierarchies.
748
+ See ActiveRecord::DelegatedType for the full description.
581
749
 
582
- * Add support for PostgreSQL operator classes to `add_index`.
750
+ *DHH*
583
751
 
584
- Example:
752
+ * Deprecate aggregations with group by duplicated fields.
585
753
 
586
- add_index :users, :name, using: :gist, opclass: { name: :gist_trgm_ops }
754
+ To migrate to Rails 6.2's behavior, use `uniq!(:group)` to deduplicate group fields.
587
755
 
588
- *Greg Navis*
756
+ ```ruby
757
+ accounts = Account.group(:firm_id)
758
+
759
+ # duplicated group fields, deprecated.
760
+ accounts.merge(accounts.where.not(credit_limit: nil)).sum(:credit_limit)
761
+ # => {
762
+ # [1, 1] => 50,
763
+ # [2, 2] => 60
764
+ # }
765
+
766
+ # use `uniq!(:group)` to deduplicate group fields.
767
+ accounts.merge(accounts.where.not(credit_limit: nil)).uniq!(:group).sum(:credit_limit)
768
+ # => {
769
+ # 1 => 50,
770
+ # 2 => 60
771
+ # }
772
+ ```
589
773
 
590
- * Don't allow scopes to be defined which conflict with instance methods on `Relation`.
774
+ *Ryuta Kamizono*
591
775
 
592
- Fixes #31120.
776
+ * Deprecate duplicated query annotations.
593
777
 
594
- *kinnrot*
778
+ To migrate to Rails 6.2's behavior, use `uniq!(:annotate)` to deduplicate query annotations.
595
779
 
596
- * Add new error class `QueryCanceled` which will be raised
597
- when canceling statement due to user request.
780
+ ```ruby
781
+ accounts = Account.where(id: [1, 2]).annotate("david and mary")
782
+
783
+ # duplicated annotations, deprecated.
784
+ accounts.merge(accounts.rewhere(id: 3))
785
+ # SELECT accounts.* FROM accounts WHERE accounts.id = 3 /* david and mary */ /* david and mary */
786
+
787
+ # use `uniq!(:annotate)` to deduplicate annotations.
788
+ accounts.merge(accounts.rewhere(id: 3)).uniq!(:annotate)
789
+ # SELECT accounts.* FROM accounts WHERE accounts.id = 3 /* david and mary */
790
+ ```
598
791
 
599
792
  *Ryuta Kamizono*
600
793
 
601
- * Add `#up_only` to database migrations for code that is only relevant when
602
- migrating up, e.g. populating a new column.
794
+ * Resolve conflict between counter cache and optimistic locking.
603
795
 
604
- *Rich Daley*
796
+ Bump an Active Record instance's lock version after updating its counter
797
+ cache. This avoids raising an unnecessary `ActiveRecord::StaleObjectError`
798
+ upon subsequent transactions by maintaining parity with the corresponding
799
+ database record's `lock_version` column.
605
800
 
606
- * Require raw SQL fragments to be explicitly marked when used in
607
- relation query methods.
801
+ Fixes #16449.
608
802
 
609
- Before:
610
- ```
611
- Article.order("LENGTH(title)")
803
+ *Aaron Lipman*
804
+
805
+ * Support merging option `:rewhere` to allow mergee side condition to be replaced exactly.
806
+
807
+ ```ruby
808
+ david_and_mary = Author.where(id: david.id..mary.id)
809
+
810
+ # both conflict conditions exists
811
+ david_and_mary.merge(Author.where(id: bob)) # => []
812
+
813
+ # mergee side condition is replaced by rewhere
814
+ david_and_mary.merge(Author.rewhere(id: bob)) # => [bob]
815
+
816
+ # mergee side condition is replaced by rewhere option
817
+ david_and_mary.merge(Author.where(id: bob), rewhere: true) # => [bob]
612
818
  ```
613
819
 
614
- After:
820
+ *Ryuta Kamizono*
821
+
822
+ * Add support for finding records based on signed ids, which are tamper-proof, verified ids that can be
823
+ set to expire and scoped with a purpose. This is particularly useful for things like password reset
824
+ or email verification, where you want the bearer of the signed id to be able to interact with the
825
+ underlying record, but usually only within a certain time period.
826
+
827
+ ```ruby
828
+ signed_id = User.first.signed_id expires_in: 15.minutes, purpose: :password_reset
829
+
830
+ User.find_signed signed_id # => nil, since the purpose does not match
831
+
832
+ travel 16.minutes
833
+ User.find_signed signed_id, purpose: :password_reset # => nil, since the signed id has expired
834
+
835
+ travel_back
836
+ User.find_signed signed_id, purpose: :password_reset # => User.first
837
+
838
+ User.find_signed! "bad data" # => ActiveSupport::MessageVerifier::InvalidSignature
615
839
  ```
616
- Article.order(Arel.sql("LENGTH(title)"))
840
+
841
+ *DHH*
842
+
843
+ * Support `ALGORITHM = INSTANT` DDL option for index operations on MySQL.
844
+
845
+ *Ryuta Kamizono*
846
+
847
+ * Fix index creation to preserve index comment in bulk change table on MySQL.
848
+
849
+ *Ryuta Kamizono*
850
+
851
+ * Allow `unscope` to be aware of table name qualified values.
852
+
853
+ It is possible to unscope only the column in the specified table.
854
+
855
+ ```ruby
856
+ posts = Post.joins(:comments).group(:"posts.hidden")
857
+ posts = posts.where("posts.hidden": false, "comments.hidden": false)
858
+
859
+ posts.count
860
+ # => { false => 10 }
861
+
862
+ # unscope both hidden columns
863
+ posts.unscope(where: :hidden).count
864
+ # => { false => 11, true => 1 }
865
+
866
+ # unscope only comments.hidden column
867
+ posts.unscope(where: :"comments.hidden").count
868
+ # => { false => 11 }
617
869
  ```
618
870
 
619
- This prevents SQL injection if applications use the [strongly
620
- discouraged] form `Article.order(params[:my_order])`, under the
621
- mistaken belief that only column names will be accepted.
871
+ *Ryuta Kamizono*, *Slava Korolev*
872
+
873
+ * Fix `rewhere` to truly overwrite collided where clause by new where clause.
874
+
875
+ ```ruby
876
+ steve = Person.find_by(name: "Steve")
877
+ david = Author.find_by(name: "David")
878
+
879
+ relation = Essay.where(writer: steve)
622
880
 
623
- Raw SQL strings will now cause a deprecation warning, which will
624
- become an UnknownAttributeReference error in Rails 6.0. Applications
625
- can opt in to the future behavior by setting `allow_unsafe_raw_sql`
626
- to `:disabled`.
881
+ # Before
882
+ relation.rewhere(writer: david).to_a # => []
627
883
 
628
- Common and judged-safe string values (such as simple column
629
- references) are unaffected:
884
+ # After
885
+ relation.rewhere(writer: david).to_a # => [david]
630
886
  ```
631
- Article.order("title DESC")
887
+
888
+ *Ryuta Kamizono*
889
+
890
+ * Inspect time attributes with subsec and time zone offset.
891
+
892
+ ```ruby
893
+ p Knot.create
894
+ => #<Knot id: 1, created_at: "2016-05-05 01:29:47.116928000 +0000">
632
895
  ```
633
896
 
634
- *Ben Toews*
897
+ *akinomaeni*, *Jonathan Hefner*
635
898
 
636
- * `update_all` will now pass its values to `Type#cast` before passing them to
637
- `Type#serialize`. This means that `update_all(foo: 'true')` will properly
638
- persist a boolean.
899
+ * Deprecate passing a column to `type_cast`.
639
900
 
640
- *Sean Griffin*
901
+ *Ryuta Kamizono*
641
902
 
642
- * Add new error class `StatementTimeout` which will be raised
643
- when statement timeout exceeded.
903
+ * Deprecate `in_clause_length` and `allowed_index_name_length` in `DatabaseLimits`.
644
904
 
645
905
  *Ryuta Kamizono*
646
906
 
647
- * Fix `bin/rails db:migrate` with specified `VERSION`.
648
- `bin/rails db:migrate` with empty VERSION behaves as without `VERSION`.
649
- Check a format of `VERSION`: Allow a migration version number
650
- or name of a migration file. Raise error if format of `VERSION` is invalid.
651
- Raise error if target migration doesn't exist.
907
+ * Support bulk insert/upsert on relation to preserve scope values.
652
908
 
653
- *bogdanvlviv*
909
+ *Josef Šimánek*, *Ryuta Kamizono*
654
910
 
655
- * Fixed a bug where column orders for an index weren't written to
656
- `db/schema.rb` when using the sqlite adapter.
911
+ * Preserve column comment value on changing column name on MySQL.
657
912
 
658
- Fixes #30902.
913
+ *Islam Taha*
659
914
 
660
- *Paul Kuruvilla*
915
+ * Add support for `if_exists` option for removing an index.
661
916
 
662
- * Remove deprecated method `#sanitize_conditions`.
917
+ 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.
663
918
 
664
- *Rafael Mendonça França*
919
+ *Eileen M. Uchitelle*
665
920
 
666
- * Remove deprecated method `#scope_chain`.
921
+ * Remove ibm_db, informix, mssql, oracle, and oracle12 Arel visitors which are not used in the code base.
667
922
 
668
- *Rafael Mendonça França*
923
+ *Ryuta Kamizono*
669
924
 
670
- * Remove deprecated configuration `.error_on_ignored_order_or_limit`.
925
+ * Prevent `build_association` from `touching` a parent record if the record isn't persisted for `has_one` associations.
671
926
 
672
- *Rafael Mendonça França*
927
+ Fixes #38219.
673
928
 
674
- * Remove deprecated arguments from `#verify!`.
929
+ *Josh Brody*
675
930
 
676
- *Rafael Mendonça França*
931
+ * Add support for `if_not_exists` option for adding index.
677
932
 
678
- * Remove deprecated argument `name` from `#indexes`.
933
+ The `add_index` method respects `if_not_exists` option. If it is set to true
934
+ index won't be added.
679
935
 
680
- *Rafael Mendonça França*
936
+ Usage:
681
937
 
682
- * Remove deprecated method `ActiveRecord::Migrator.schema_migrations_table_name`.
938
+ ```ruby
939
+ add_index :users, :account_id, if_not_exists: true
940
+ ```
683
941
 
684
- *Rafael Mendonça França*
942
+ The `if_not_exists` option passed to `create_table` also gets propagated to indexes
943
+ created within that migration so that if table and its indexes exist then there is no
944
+ attempt to create them again.
685
945
 
686
- * Remove deprecated method `supports_primary_key?`.
946
+ *Prathamesh Sonpatki*
687
947
 
688
- *Rafael Mendonça França*
948
+ * Add `ActiveRecord::Base#previously_new_record?` to show if a record was new before the last save.
689
949
 
690
- * Remove deprecated method `supports_migrations?`.
950
+ *Tom Ward*
691
951
 
692
- *Rafael Mendonça França*
952
+ * Support descending order for `find_each`, `find_in_batches`, and `in_batches`.
693
953
 
694
- * Remove deprecated methods `initialize_schema_migrations_table` and `initialize_internal_metadata_table`.
954
+ 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.
695
955
 
696
- *Rafael Mendonça França*
956
+ This change allows reversing the order, batching from newest to oldest. This is useful when you need to process newer batches of records first.
697
957
 
698
- * Raises when calling `lock!` in a dirty record.
958
+ Pass `order: :desc` to yield batches in descending order. The default remains `order: :asc`.
699
959
 
700
- *Rafael Mendonça França*
960
+ ```ruby
961
+ Person.find_each(order: :desc) do |person|
962
+ person.party_all_night!
963
+ end
964
+ ```
701
965
 
702
- * Remove deprecated support to passing a class to `:class_name` on associations.
966
+ *Alexey Vasiliev*
703
967
 
704
- *Rafael Mendonça França*
968
+ * Fix `insert_all` with enum values.
705
969
 
706
- * Remove deprecated argument `default` from `index_name_exists?`.
970
+ Fixes #38716.
707
971
 
708
- *Rafael Mendonça França*
972
+ *Joel Blum*
709
973
 
710
- * Remove deprecated support to `quoted_id` when typecasting an Active Record object.
974
+ * Add support for `db:rollback:name` for multiple database applications.
711
975
 
712
- *Rafael Mendonça França*
976
+ Multiple database applications will now raise if `db:rollback` is call and recommend using the `db:rollback:[NAME]` to rollback migrations.
977
+
978
+ *Eileen M. Uchitelle*
713
979
 
714
- * Fix `bin/rails db:setup` and `bin/rails db:test:prepare` create wrong
715
- ar_internal_metadata's data for a test database.
980
+ * `Relation#pick` now uses already loaded results instead of making another query.
716
981
 
717
- Before:
982
+ *Eugene Kenny*
983
+
984
+ * Deprecate using `return`, `break` or `throw` to exit a transaction block after writes.
985
+
986
+ *Dylan Thacker-Smith*
987
+
988
+ * Dump the schema or structure of a database when calling `db:migrate:name`.
989
+
990
+ 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.
991
+
992
+ Going forward, calls to `rails db:migrate:name` will dump the schema (or structure) of the database being migrated.
993
+
994
+ *Kyle Thompson*
995
+
996
+ * Reset the `ActiveRecord::Base` connection after `rails db:migrate:name`.
997
+
998
+ 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.
999
+
1000
+ *Kyle Thompson*
1001
+
1002
+ * Disallow calling `connected_to` on subclasses of `ActiveRecord::Base`.
1003
+
1004
+ 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.
1005
+
1006
+ *Eileen M. Uchitelle*, *John Crepezzi*
1007
+
1008
+ * Add support for horizontal sharding to `connects_to` and `connected_to`.
1009
+
1010
+ 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.
1011
+
1012
+ Usage:
1013
+
1014
+ Given the following configuration:
1015
+
1016
+ ```yaml
1017
+ # config/database.yml
1018
+ production:
1019
+ primary:
1020
+ database: my_database
1021
+ primary_shard_one:
1022
+ database: my_database_shard_one
718
1023
  ```
719
- $ RAILS_ENV=test rails dbconsole
720
- > SELECT * FROM ar_internal_metadata;
721
- key|value|created_at|updated_at
722
- environment|development|2017-09-11 23:14:10.815679|2017-09-11 23:14:10.815679
1024
+
1025
+ Connect to multiple shards:
1026
+
1027
+ ```ruby
1028
+ class ApplicationRecord < ActiveRecord::Base
1029
+ self.abstract_class = true
1030
+
1031
+ connects_to shards: {
1032
+ default: { writing: :primary },
1033
+ shard_one: { writing: :primary_shard_one }
1034
+ }
723
1035
  ```
724
1036
 
725
- After:
1037
+ Swap between shards in your controller / model code:
1038
+
1039
+ ```ruby
1040
+ ActiveRecord::Base.connected_to(shard: :shard_one) do
1041
+ # Read from shard one
1042
+ end
726
1043
  ```
727
- $ RAILS_ENV=test rails dbconsole
728
- > SELECT * FROM ar_internal_metadata;
729
- key|value|created_at|updated_at
730
- environment|test|2017-09-11 23:14:10.815679|2017-09-11 23:14:10.815679
1044
+
1045
+ The horizontal sharding API also supports read replicas. See guides for more details.
1046
+
1047
+ *Eileen M. Uchitelle*, *John Crepezzi*
1048
+
1049
+ * Deprecate `spec_name` in favor of `name` on database configurations.
1050
+
1051
+ The accessors for `spec_name` on `configs_for` and `DatabaseConfig` are deprecated. Please use `name` instead.
1052
+
1053
+ Deprecated behavior:
1054
+
1055
+ ```ruby
1056
+ db_config = ActiveRecord::Base.configs_for(env_name: "development", spec_name: "primary")
1057
+ db_config.spec_name
731
1058
  ```
732
1059
 
733
- Fixes #26731.
1060
+ New behavior:
734
1061
 
735
- *bogdanvlviv*
1062
+ ```ruby
1063
+ db_config = ActiveRecord::Base.configs_for(env_name: "development", name: "primary")
1064
+ db_config.name
1065
+ ```
736
1066
 
737
- * Fix longer sequence name detection for serial columns.
1067
+ *Eileen M. Uchitelle*
738
1068
 
739
- Fixes #28332.
1069
+ * Add additional database-specific rake tasks for multi-database users.
740
1070
 
741
- *Ryuta Kamizono*
1071
+ Previously, `rails db:create`, `rails db:drop`, and `rails db:migrate` were the only rails tasks that could operate on a single
1072
+ database. For example:
742
1073
 
743
- * MySQL: Don't lose `auto_increment: true` in the `db/schema.rb`.
1074
+ ```
1075
+ rails db:create
1076
+ rails db:create:primary
1077
+ rails db:create:animals
1078
+ rails db:drop
1079
+ rails db:drop:primary
1080
+ rails db:drop:animals
1081
+ rails db:migrate
1082
+ rails db:migrate:primary
1083
+ rails db:migrate:animals
1084
+ ```
744
1085
 
745
- Fixes #30894.
1086
+ With these changes, `rails db:schema:dump`, `rails db:schema:load`, `rails db:structure:dump`, `rails db:structure:load` and
1087
+ `rails db:test:prepare` can additionally operate on a single database. For example:
746
1088
 
747
- *Ryuta Kamizono*
1089
+ ```
1090
+ rails db:schema:dump
1091
+ rails db:schema:dump:primary
1092
+ rails db:schema:dump:animals
1093
+ rails db:schema:load
1094
+ rails db:schema:load:primary
1095
+ rails db:schema:load:animals
1096
+ rails db:structure:dump
1097
+ rails db:structure:dump:primary
1098
+ rails db:structure:dump:animals
1099
+ rails db:structure:load
1100
+ rails db:structure:load:primary
1101
+ rails db:structure:load:animals
1102
+ rails db:test:prepare
1103
+ rails db:test:prepare:primary
1104
+ rails db:test:prepare:animals
1105
+ ```
748
1106
 
749
- * Fix `COUNT(DISTINCT ...)` for `GROUP BY` with `ORDER BY` and `LIMIT`.
1107
+ *Kyle Thompson*
750
1108
 
751
- Fixes #30886.
1109
+ * Add support for `strict_loading` mode on association declarations.
752
1110
 
753
- *Ryuta Kamizono*
1111
+ 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.
754
1112
 
755
- * PostgreSQL `tsrange` now preserves subsecond precision.
1113
+ Usage:
756
1114
 
757
- PostgreSQL 9.1+ introduced range types, and Rails added support for using
758
- this datatype in Active Record. However, the serialization of
759
- `PostgreSQL::OID::Range` was incomplete, because it did not properly
760
- cast the bounds that make up the range. This led to subseconds being
761
- dropped in SQL commands:
1115
+ ```ruby
1116
+ class Developer < ApplicationRecord
1117
+ has_many :projects, strict_loading: true
1118
+ end
762
1119
 
763
- Before:
1120
+ dev = Developer.first
1121
+ dev.projects.first
1122
+ # => ActiveRecord::StrictLoadingViolationError: The projects association is marked as strict_loading and cannot be lazily loaded.
1123
+ ```
1124
+
1125
+ *Kevin Deisz*
764
1126
 
765
- connection.type_cast(tsrange.serialize(range_value))
766
- # => "[2010-01-01 13:30:00 UTC,2011-02-02 19:30:00 UTC)"
1127
+ * Add support for `strict_loading` mode to prevent lazy loading of records.
767
1128
 
768
- Now:
1129
+ 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.
769
1130
 
770
- connection.type_cast(tsrange.serialize(range_value))
771
- # => "[2010-01-01 13:30:00.670277,2011-02-02 19:30:00.745125)"
1131
+ Usage:
772
1132
 
773
- *Thomas Cannon*
1133
+ ```ruby
1134
+ dev = Developer.strict_loading.first
1135
+ dev.audit_logs.to_a
1136
+ # => ActiveRecord::StrictLoadingViolationError: Developer is marked as strict_loading and AuditLog cannot be lazily loaded.
1137
+ ```
774
1138
 
775
- * Passing a `Set` to `Relation#where` now behaves the same as passing an
776
- array.
1139
+ *Eileen M. Uchitelle*, *Aaron Patterson*
777
1140
 
778
- *Sean Griffin*
1141
+ * Add support for PostgreSQL 11+ partitioned indexes when using `upsert_all`.
779
1142
 
780
- * Use given algorithm while removing index from database.
1143
+ *Sebastián Palma*
781
1144
 
782
- Fixes #24190.
1145
+ * Adds support for `if_not_exists` to `add_column` and `if_exists` to `remove_column`.
783
1146
 
784
- *Mehmet Emin İNAÇ*
1147
+ 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.
785
1148
 
786
- * Update payload names for `sql.active_record` instrumentation to be
787
- more descriptive.
1149
+ Example Usage:
788
1150
 
789
- Fixes #30586.
1151
+ ```ruby
1152
+ class AddColumnTitle < ActiveRecord::Migration[6.1]
1153
+ def change
1154
+ add_column :posts, :title, :string, if_not_exists: true
1155
+ end
1156
+ end
1157
+ ```
790
1158
 
791
- *Jeremy Green*
1159
+ ```ruby
1160
+ class RemoveColumnTitle < ActiveRecord::Migration[6.1]
1161
+ def change
1162
+ remove_column :posts, :title, if_exists: true
1163
+ end
1164
+ end
1165
+ ```
792
1166
 
793
- * Add new error class `LockWaitTimeout` which will be raised
794
- when lock wait timeout exceeded.
1167
+ *Eileen M. Uchitelle*
795
1168
 
796
- *Gabriel Courtemanche*
1169
+ * Regexp-escape table name for MS SQL Server.
797
1170
 
798
- * Remove deprecated `#migration_keys`.
1171
+ 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.
799
1172
 
800
- *Ryuta Kamizono*
1173
+ *Larry Reid*
801
1174
 
802
- * Automatically guess the inverse associations for STI.
1175
+ * Store advisory locks on their own named connection.
803
1176
 
804
- *Yuichiro Kaneko*
1177
+ 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.
805
1178
 
806
- * Ensure `sum` honors `distinct` on `has_many :through` associations.
1179
+ 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.
807
1180
 
808
- Fixes #16791.
1181
+ *Eileen M. Uchitelle*, *John Crepezzi*
809
1182
 
810
- *Aaron Wortham*
1183
+ * Allow schema cache path to be defined in the database configuration file.
811
1184
 
812
- * Add `binary` fixture helper method.
1185
+ For example:
813
1186
 
814
- *Atsushi Yoshida*
1187
+ ```yaml
1188
+ development:
1189
+ adapter: postgresql
1190
+ database: blog_development
1191
+ pool: 5
1192
+ schema_cache_path: tmp/schema/main.yml
1193
+ ```
815
1194
 
816
- * When using `Relation#or`, extract the common conditions and put them before the OR condition.
1195
+ *Katrina Owen*
817
1196
 
818
- *Maxime Handfield Lapointe*
1197
+ * Deprecate `#remove_connection` in favor of `#remove_connection_pool` when called on the handler.
819
1198
 
820
- * `Relation#or` now accepts two relations who have different values for
821
- `references` only, as `references` can be implicitly called by `where`.
1199
+ `#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 6.2.
822
1200
 
823
- Fixes #29411.
1201
+ *Eileen M. Uchitelle*, *John Crepezzi*
824
1202
 
825
- *Sean Griffin*
1203
+ * Deprecate `#default_hash` and it's alias `#[]` on database configurations.
826
1204
 
827
- * `ApplicationRecord` is no longer generated when generating models. If you
828
- need to generate it, it can be created with `rails g application_record`.
1205
+ Applications should use `configs_for`. `#default_hash` and `#[]` will be removed in 6.2.
829
1206
 
830
- *Lisa Ugray*
1207
+ *Eileen M. Uchitelle*, *John Crepezzi*
831
1208
 
832
- * Fix `COUNT(DISTINCT ...)` with `ORDER BY` and `LIMIT` to keep the existing select list.
1209
+ * Add scale support to `ActiveRecord::Validations::NumericalityValidator`.
833
1210
 
834
- *Ryuta Kamizono*
1211
+ *Gannon McGibbon*
835
1212
 
836
- * When a `has_one` association is destroyed by `dependent: destroy`,
837
- `destroyed_by_association` will now be set to the reflection, matching the
838
- behaviour of `has_many` associations.
1213
+ * Find orphans by looking for missing relations through chaining `where.missing`:
839
1214
 
840
- *Lisa Ugray*
1215
+ Before:
841
1216
 
842
- * Fix `unscoped(where: [columns])` removing the wrong bind values.
1217
+ ```ruby
1218
+ Post.left_joins(:author).where(authors: { id: nil })
1219
+ ```
843
1220
 
844
- When the `where` is called on a relation after a `or`, unscoping the column of that later `where` removed
845
- bind values used by the `or` instead. (possibly other cases too)
1221
+ After:
846
1222
 
1223
+ ```ruby
1224
+ Post.where.missing(:author)
847
1225
  ```
848
- Post.where(id: 1).or(Post.where(id: 2)).where(foo: 3).unscope(where: :foo).to_sql
849
- # Currently:
850
- # SELECT "posts".* FROM "posts" WHERE ("posts"."id" = 2 OR "posts"."id" = 3)
851
- # With fix:
852
- # SELECT "posts".* FROM "posts" WHERE ("posts"."id" = 1 OR "posts"."id" = 2)
1226
+
1227
+ *Tom Rossi*
1228
+
1229
+ * Ensure `:reading` connections always raise if a write is attempted.
1230
+
1231
+ 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`.
1232
+
1233
+ *Eileen M. Uchitelle*
1234
+
1235
+ * Deprecate `"primary"` as the `connection_specification_name` for `ActiveRecord::Base`.
1236
+
1237
+ `"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"`.
1238
+
1239
+ *Eileen M. Uchitelle*, *John Crepezzi*
1240
+
1241
+ * Add `ActiveRecord::Validations::NumericalityValidator` with
1242
+ support for casting floats using a database columns' precision value.
1243
+
1244
+ *Gannon McGibbon*
1245
+
1246
+ * Enforce fresh ETag header after a collection's contents change by adding
1247
+ ActiveRecord::Relation#cache_key_with_version. This method will be used by
1248
+ ActionController::ConditionalGet to ensure that when collection cache versioning
1249
+ is enabled, requests using ConditionalGet don't return the same ETag header
1250
+ after a collection is modified.
1251
+
1252
+ Fixes #38078.
1253
+
1254
+ *Aaron Lipman*
1255
+
1256
+ * Skip test database when running `db:create` or `db:drop` in development
1257
+ with `DATABASE_URL` set.
1258
+
1259
+ *Brian Buchalter*
1260
+
1261
+ * Don't allow mutations on the database configurations hash.
1262
+
1263
+ 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.
1264
+
1265
+ Before:
1266
+
1267
+ ```ruby
1268
+ @db_config = ActiveRecord::Base.configurations.configs_for(env_name: "test", spec_name: "primary")
1269
+ @db_config.configuration_hash.merge!(idle_timeout: "0.02")
853
1270
  ```
854
1271
 
855
- *Maxime Handfield Lapointe*
1272
+ After:
856
1273
 
857
- * Values constructed using multi-parameter assignment will now use the
858
- post-type-cast value for rendering in single-field form inputs.
1274
+ ```ruby
1275
+ @db_config = ActiveRecord::Base.configurations.configs_for(env_name: "test", spec_name: "primary")
1276
+ config = @db_config.configuration_hash.merge(idle_timeout: "0.02")
1277
+ db_config = ActiveRecord::DatabaseConfigurations::HashConfig.new(@db_config.env_name, @db_config.spec_name, config)
1278
+ ```
859
1279
 
860
- *Sean Griffin*
1280
+ *Eileen M. Uchitelle*, *John Crepezzi*
861
1281
 
862
- * `Relation#joins` is no longer affected by the target model's
863
- `current_scope`, with the exception of `unscoped`.
1282
+ * Remove `:connection_id` from the `sql.active_record` notification.
864
1283
 
865
- Fixes #29338.
1284
+ *Aaron Patterson*, *Rafael Mendonça França*
866
1285
 
867
- *Sean Griffin*
1286
+ * The `:name` key will no longer be returned as part of `DatabaseConfig#configuration_hash`. Please use `DatabaseConfig#owner_name` instead.
868
1287
 
869
- * Change sqlite3 boolean serialization to use 1 and 0.
1288
+ *Eileen M. Uchitelle*, *John Crepezzi*
870
1289
 
871
- SQLite natively recognizes 1 and 0 as true and false, but does not natively
872
- recognize 't' and 'f' as was previously serialized.
1290
+ * ActiveRecord's `belongs_to_required_by_default` flag can now be set per model.
873
1291
 
874
- This change in serialization requires a migration of stored boolean data
875
- for SQLite databases, so it's implemented behind a configuration flag
876
- whose default false value is deprecated.
1292
+ You can now opt-out/opt-in specific models from having their associations required
1293
+ by default.
877
1294
 
878
- *Lisa Ugray*
1295
+ This change is meant to ease the process of migrating all your models to have
1296
+ their association required.
879
1297
 
880
- * Skip query caching when working with batches of records (`find_each`, `find_in_batches`,
881
- `in_batches`).
1298
+ *Edouard Chin*
882
1299
 
883
- Previously, records would be fetched in batches, but all records would be retained in memory
884
- until the end of the request or job.
1300
+ * The `connection_config` method has been deprecated, please use `connection_db_config` instead which will return a `DatabaseConfigurations::DatabaseConfig` instead of a `Hash`.
885
1301
 
886
- *Eugene Kenny*
1302
+ *Eileen M. Uchitelle*, *John Crepezzi*
887
1303
 
888
- * Prevent errors raised by `sql.active_record` notification subscribers from being converted into
889
- `ActiveRecord::StatementInvalid` exceptions.
1304
+ * Retain explicit selections on the base model after applying `includes` and `joins`.
890
1305
 
891
- *Dennis Taylor*
1306
+ Resolves #34889.
892
1307
 
893
- * Fix eager loading/preloading association with scope including joins.
1308
+ *Patrick Rebsch*
894
1309
 
895
- Fixes #28324.
1310
+ * 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.
896
1311
 
897
- *Ryuta Kamizono*
1312
+ *Eileen M. Uchitelle*, *John Crepezzi*
898
1313
 
899
- * Fix transactions to apply state to child transactions.
1314
+ * Allow attributes to be fetched from Arel node groupings.
900
1315
 
901
- Previously, if you had a nested transaction and the outer transaction was rolledback, the record from the
902
- inner transaction would still be marked as persisted.
1316
+ *Jeff Emminger*, *Gannon McGibbon*
903
1317
 
904
- This change fixes that by applying the state of the parent transaction to the child transaction when the
905
- parent transaction is rolledback. This will correctly mark records from the inner transaction as not persisted.
1318
+ * A database URL can now contain a querystring value that contains an equal sign. This is needed to support passing PostgreSQL `options`.
906
1319
 
907
- *Eileen M. Uchitelle*, *Aaron Patterson*
1320
+ *Joshua Flanagan*
908
1321
 
909
- * Deprecate `set_state` method in `TransactionState`.
1322
+ * 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`.
910
1323
 
911
- Deprecated the `set_state` method in favor of setting the state via specific methods. If you need to mark the
912
- state of the transaction you can now use `rollback!`, `commit!` or `nullify!` instead of
913
- `set_state(:rolledback)`, `set_state(:committed)`, or `set_state(nil)`.
1324
+ *John Crepezzi*
914
1325
 
915
- *Eileen M. Uchitelle*, *Aaron Patterson*
1326
+ * Specifying `implicit_order_column` now subsorts the records by primary key if available to ensure deterministic results.
916
1327
 
917
- * Deprecate delegating to `arel` in `Relation`.
1328
+ *Paweł Urbanek*
918
1329
 
919
- *Ryuta Kamizono*
1330
+ * `where(attr => [])` now loads an empty result without making a query.
920
1331
 
921
- * Query cache was unavailable when entering the `ActiveRecord::Base.cache` block
922
- without being connected.
1332
+ *John Hawthorn*
923
1333
 
924
- *Tsukasa Oishi*
1334
+ * Fixed the performance regression for `primary_keys` introduced MySQL 8.0.
925
1335
 
926
- * Previously, when building records using a `has_many :through` association,
927
- if the child records were deleted before the parent was saved, they would
928
- still be persisted. Now, if child records are deleted before the parent is saved
929
- on a `has_many :through` association, the child records will not be persisted.
1336
+ *Hiroyuki Ishii*
930
1337
 
931
- *Tobias Kraze*
1338
+ * Add support for `belongs_to` to `has_many` inversing.
932
1339
 
933
- * Merging two relations representing nested joins no longer transforms the joins of
934
- the merged relation into LEFT OUTER JOIN.
1340
+ *Gannon McGibbon*
935
1341
 
936
- Example:
1342
+ * Allow length configuration for `has_secure_token` method. The minimum length
1343
+ is set at 24 characters.
937
1344
 
1345
+ Before:
1346
+
1347
+ ```ruby
1348
+ has_secure_token :auth_token
938
1349
  ```
939
- Author.joins(:posts).merge(Post.joins(:comments))
940
- # Before the change:
941
- #=> SELECT ... FROM authors INNER JOIN posts ON ... LEFT OUTER JOIN comments ON...
942
1350
 
943
- # After the change:
944
- #=> SELECT ... FROM authors INNER JOIN posts ON ... INNER JOIN comments ON...
1351
+ After:
1352
+
1353
+ ```ruby
1354
+ has_secure_token :default_token # 24 characters
1355
+ has_secure_token :auth_token, length: 36 # 36 characters
1356
+ has_secure_token :invalid_token, length: 12 # => ActiveRecord::SecureToken::MinimumLengthError
945
1357
  ```
946
1358
 
947
- *Maxime Handfield Lapointe*
1359
+ *Bernardo de Araujo*
948
1360
 
949
- * `ActiveRecord::Persistence#touch` does not work well when optimistic locking enabled and
950
- `locking_column`, without default value, is null in the database.
1361
+ * Deprecate `DatabaseConfigurations#to_h`. These connection hashes are still available via `ActiveRecord::Base.configurations.configs_for`.
951
1362
 
952
- *bogdanvlviv*
1363
+ *Eileen Uchitelle*, *John Crepezzi*
953
1364
 
954
- * Fix destroying existing object does not work well when optimistic locking enabled and
955
- `locking_column` is null in the database.
1365
+ * 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.
956
1366
 
957
- *bogdanvlviv*
1367
+ *John Crepezzi*, *Eileen Uchitelle*
1368
+
1369
+ * Allow column names to be passed to `remove_index` positionally along with other options.
1370
+
1371
+ Passing other options can be necessary to make `remove_index` correctly reversible.
958
1372
 
959
- * Use bulk INSERT to insert fixtures for better performance.
1373
+ Before:
1374
+
1375
+ add_index :reports, :report_id # => works
1376
+ add_index :reports, :report_id, unique: true # => works
1377
+ remove_index :reports, :report_id # => works
1378
+ remove_index :reports, :report_id, unique: true # => ArgumentError
1379
+
1380
+ After:
1381
+
1382
+ remove_index :reports, :report_id, unique: true # => works
1383
+
1384
+ *Eugene Kenny*
1385
+
1386
+ * Allow bulk `ALTER` statements to drop and recreate indexes with the same name.
1387
+
1388
+ *Eugene Kenny*
1389
+
1390
+ * `insert`, `insert_all`, `upsert`, and `upsert_all` now clear the query cache.
1391
+
1392
+ *Eugene Kenny*
1393
+
1394
+ * Call `while_preventing_writes` directly from `connected_to`.
1395
+
1396
+ 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)`.
1397
+
1398
+ 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.
1399
+
1400
+ *Eileen M. Uchitelle*
1401
+
1402
+ * Improve detection of ActiveRecord::StatementTimeout with mysql2 adapter in the edge case when the query is terminated during filesort.
960
1403
 
961
1404
  *Kir Shatrov*
962
1405
 
963
- * Prevent creation of bind param if casted value is nil.
1406
+ * Stop trying to read yaml file fixtures when loading Active Record fixtures.
1407
+
1408
+ *Gannon McGibbon*
1409
+
1410
+ * Deprecate `.reorder(nil)` with `.first` / `.first!` taking non-deterministic result.
1411
+
1412
+ To continue taking non-deterministic result, use `.take` / `.take!` instead.
964
1413
 
965
1414
  *Ryuta Kamizono*
966
1415
 
967
- * Deprecate passing arguments and block at the same time to `count` and `sum` in `ActiveRecord::Calculations`.
1416
+ * Preserve user supplied joins order as much as possible.
1417
+
1418
+ Fixes #36761, #34328, #24281, #12953.
968
1419
 
969
1420
  *Ryuta Kamizono*
970
1421
 
971
- * Loading model schema from database is now thread-safe.
1422
+ * Allow `matches_regex` and `does_not_match_regexp` on the MySQL Arel visitor.
972
1423
 
973
- Fixes #28589.
1424
+ *James Pearson*
974
1425
 
975
- *Vikrant Chaudhary*, *David Abdemoulaie*
1426
+ * Allow specifying fixtures to be ignored by setting `ignore` in YAML file's '_fixture' section.
976
1427
 
977
- * Add `ActiveRecord::Base#cache_version` to support recyclable cache keys via the new versioned entries
978
- in `ActiveSupport::Cache`. This also means that `ActiveRecord::Base#cache_key` will now return a stable key
979
- that does not include a timestamp any more.
1428
+ *Tongfei Gao*
980
1429
 
981
- NOTE: This feature is turned off by default, and `#cache_key` will still return cache keys with timestamps
982
- until you set `ActiveRecord::Base.cache_versioning = true`. That's the setting for all new apps on Rails 5.2+
1430
+ * Make the DATABASE_URL env variable only affect the primary connection. Add new env variables for multiple databases.
983
1431
 
984
- *DHH*
1432
+ *John Crepezzi*, *Eileen Uchitelle*
985
1433
 
986
- * Respect `SchemaDumper.ignore_tables` in rake tasks for databases structure dump.
1434
+ * Add a warning for enum elements with 'not_' prefix.
987
1435
 
988
- *Rusty Geldmacher*, *Guillermo Iguaran*
1436
+ class Foo
1437
+ enum status: [:sent, :not_sent]
1438
+ end
989
1439
 
990
- * Add type caster to `RuntimeReflection#alias_name`.
1440
+ *Edu Depetris*
991
1441
 
992
- Fixes #28959.
1442
+ * Make currency symbols optional for money column type in PostgreSQL.
993
1443
 
994
- *Jon Moss*
1444
+ *Joel Schneider*
995
1445
 
996
- * Deprecate `supports_statement_cache?`.
1446
+ * Add support for beginless ranges, introduced in Ruby 2.7.
997
1447
 
998
- *Ryuta Kamizono*
1448
+ *Josh Goodall*
999
1449
 
1000
- * Raise error `UnknownMigrationVersionError` on the movement of migrations
1001
- when the current migration does not exist.
1450
+ * Add `database_exists?` method to connection adapters to check if a database exists.
1002
1451
 
1003
- *bogdanvlviv*
1452
+ *Guilherme Mansur*
1004
1453
 
1005
- * Fix `bin/rails db:forward` first migration.
1454
+ * Loading the schema for a model that has no `table_name` raises a `TableNotSpecified` error.
1006
1455
 
1007
- *bogdanvlviv*
1456
+ *Guilherme Mansur*, *Eugene Kenny*
1008
1457
 
1009
- * Support Descending Indexes for MySQL.
1458
+ * PostgreSQL: Fix GROUP BY with ORDER BY virtual count attribute.
1010
1459
 
1011
- MySQL 8.0.1 and higher supports descending indexes: `DESC` in an index definition is no longer ignored.
1012
- See https://dev.mysql.com/doc/refman/8.0/en/descending-indexes.html.
1460
+ Fixes #36022.
1013
1461
 
1014
1462
  *Ryuta Kamizono*
1015
1463
 
1016
- * Fix inconsistency with changed attributes when overriding Active Record attribute reader.
1464
+ * Make ActiveRecord `ConnectionPool.connections` method thread-safe.
1017
1465
 
1018
- *bogdanvlviv*
1466
+ Fixes #36465.
1467
+
1468
+ *Jeff Doering*
1469
+
1470
+ * Add support for multiple databases to `rails db:abort_if_pending_migrations`.
1471
+
1472
+ *Mark Lee*
1473
+
1474
+ * Fix sqlite3 collation parsing when using decimal columns.
1475
+
1476
+ *Martin R. Schuster*
1477
+
1478
+ * Fix invalid schema when primary key column has a comment.
1479
+
1480
+ Fixes #29966.
1481
+
1482
+ *Guilherme Goettems Schneider*
1483
+
1484
+ * Fix table comment also being applied to the primary key column.
1485
+
1486
+ *Guilherme Goettems Schneider*
1019
1487
 
1020
- * When calling the dynamic fixture accessor method with no arguments, it now returns all fixtures of this type.
1021
- Previously this method always returned an empty array.
1488
+ * Allow generated `create_table` migrations to include or skip timestamps.
1022
1489
 
1023
- *Kevin McPhillips*
1490
+ *Michael Duchemin*
1024
1491
 
1025
1492
 
1026
- Please check [5-1-stable](https://github.com/rails/rails/blob/5-1-stable/activerecord/CHANGELOG.md) for previous changes.
1493
+ Please check [6-0-stable](https://github.com/rails/rails/blob/6-0-stable/activerecord/CHANGELOG.md) for previous changes.