activerecord 5.2.8.1 → 6.0.6.1

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 (294) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +938 -573
  3. data/MIT-LICENSE +3 -1
  4. data/README.rdoc +5 -3
  5. data/examples/performance.rb +1 -1
  6. data/lib/active_record/advisory_lock_base.rb +18 -0
  7. data/lib/active_record/aggregations.rb +4 -3
  8. data/lib/active_record/association_relation.rb +10 -8
  9. data/lib/active_record/associations/alias_tracker.rb +0 -1
  10. data/lib/active_record/associations/association.rb +55 -19
  11. data/lib/active_record/associations/association_scope.rb +11 -7
  12. data/lib/active_record/associations/belongs_to_association.rb +36 -42
  13. data/lib/active_record/associations/belongs_to_polymorphic_association.rb +0 -4
  14. data/lib/active_record/associations/builder/association.rb +14 -18
  15. data/lib/active_record/associations/builder/belongs_to.rb +19 -52
  16. data/lib/active_record/associations/builder/collection_association.rb +3 -13
  17. data/lib/active_record/associations/builder/has_and_belongs_to_many.rb +17 -40
  18. data/lib/active_record/associations/builder/has_many.rb +2 -0
  19. data/lib/active_record/associations/builder/has_one.rb +35 -1
  20. data/lib/active_record/associations/builder/singular_association.rb +2 -0
  21. data/lib/active_record/associations/collection_association.rb +19 -23
  22. data/lib/active_record/associations/collection_proxy.rb +14 -17
  23. data/lib/active_record/associations/foreign_association.rb +7 -0
  24. data/lib/active_record/associations/has_many_association.rb +2 -11
  25. data/lib/active_record/associations/has_many_through_association.rb +14 -14
  26. data/lib/active_record/associations/has_one_association.rb +28 -30
  27. data/lib/active_record/associations/has_one_through_association.rb +5 -5
  28. data/lib/active_record/associations/join_dependency/join_association.rb +16 -10
  29. data/lib/active_record/associations/join_dependency/join_part.rb +4 -4
  30. data/lib/active_record/associations/join_dependency.rb +47 -30
  31. data/lib/active_record/associations/preloader/association.rb +61 -41
  32. data/lib/active_record/associations/preloader/through_association.rb +48 -39
  33. data/lib/active_record/associations/preloader.rb +44 -33
  34. data/lib/active_record/associations/singular_association.rb +2 -16
  35. data/lib/active_record/associations/through_association.rb +1 -1
  36. data/lib/active_record/associations.rb +21 -16
  37. data/lib/active_record/attribute_assignment.rb +7 -11
  38. data/lib/active_record/attribute_decorators.rb +0 -2
  39. data/lib/active_record/attribute_methods/before_type_cast.rb +4 -2
  40. data/lib/active_record/attribute_methods/dirty.rb +111 -40
  41. data/lib/active_record/attribute_methods/primary_key.rb +15 -24
  42. data/lib/active_record/attribute_methods/query.rb +2 -3
  43. data/lib/active_record/attribute_methods/read.rb +15 -54
  44. data/lib/active_record/attribute_methods/serialization.rb +1 -2
  45. data/lib/active_record/attribute_methods/time_zone_conversion.rb +1 -3
  46. data/lib/active_record/attribute_methods/write.rb +17 -25
  47. data/lib/active_record/attribute_methods.rb +28 -100
  48. data/lib/active_record/attributes.rb +13 -1
  49. data/lib/active_record/autosave_association.rb +12 -14
  50. data/lib/active_record/base.rb +2 -3
  51. data/lib/active_record/callbacks.rb +6 -21
  52. data/lib/active_record/coders/yaml_column.rb +15 -6
  53. data/lib/active_record/connection_adapters/abstract/connection_pool.rb +109 -18
  54. data/lib/active_record/connection_adapters/abstract/database_limits.rb +17 -4
  55. data/lib/active_record/connection_adapters/abstract/database_statements.rb +102 -124
  56. data/lib/active_record/connection_adapters/abstract/query_cache.rb +18 -9
  57. data/lib/active_record/connection_adapters/abstract/quoting.rb +77 -17
  58. data/lib/active_record/connection_adapters/abstract/schema_creation.rb +20 -14
  59. data/lib/active_record/connection_adapters/abstract/schema_definitions.rb +105 -72
  60. data/lib/active_record/connection_adapters/abstract/schema_dumper.rb +1 -3
  61. data/lib/active_record/connection_adapters/abstract/schema_statements.rb +175 -79
  62. data/lib/active_record/connection_adapters/abstract/transaction.rb +96 -57
  63. data/lib/active_record/connection_adapters/abstract_adapter.rb +197 -43
  64. data/lib/active_record/connection_adapters/abstract_mysql_adapter.rb +149 -217
  65. data/lib/active_record/connection_adapters/column.rb +17 -13
  66. data/lib/active_record/connection_adapters/connection_specification.rb +54 -45
  67. data/lib/active_record/connection_adapters/determine_if_preparable_visitor.rb +6 -10
  68. data/lib/active_record/connection_adapters/mysql/column.rb +1 -1
  69. data/lib/active_record/connection_adapters/mysql/database_statements.rb +70 -14
  70. data/lib/active_record/connection_adapters/mysql/explain_pretty_printer.rb +0 -1
  71. data/lib/active_record/connection_adapters/mysql/quoting.rb +44 -7
  72. data/lib/active_record/connection_adapters/mysql/schema_creation.rb +4 -6
  73. data/lib/active_record/connection_adapters/mysql/schema_definitions.rb +40 -32
  74. data/lib/active_record/connection_adapters/mysql/schema_dumper.rb +14 -6
  75. data/lib/active_record/connection_adapters/mysql/schema_statements.rb +139 -19
  76. data/lib/active_record/connection_adapters/mysql/type_metadata.rb +6 -10
  77. data/lib/active_record/connection_adapters/mysql2_adapter.rb +26 -10
  78. data/lib/active_record/connection_adapters/postgresql/column.rb +17 -31
  79. data/lib/active_record/connection_adapters/postgresql/database_statements.rb +26 -1
  80. data/lib/active_record/connection_adapters/postgresql/oid/array.rb +1 -2
  81. data/lib/active_record/connection_adapters/postgresql/oid/bit.rb +1 -4
  82. data/lib/active_record/connection_adapters/postgresql/oid/date_time.rb +8 -0
  83. data/lib/active_record/connection_adapters/postgresql/oid/enum.rb +0 -1
  84. data/lib/active_record/connection_adapters/postgresql/oid/hstore.rb +1 -2
  85. data/lib/active_record/connection_adapters/postgresql/oid/legacy_point.rb +1 -2
  86. data/lib/active_record/connection_adapters/postgresql/oid/oid.rb +1 -1
  87. data/lib/active_record/connection_adapters/postgresql/oid/point.rb +1 -2
  88. data/lib/active_record/connection_adapters/postgresql/oid/range.rb +25 -7
  89. data/lib/active_record/connection_adapters/postgresql/oid/specialized_string.rb +1 -1
  90. data/lib/active_record/connection_adapters/postgresql/oid/type_map_initializer.rb +9 -7
  91. data/lib/active_record/connection_adapters/postgresql/oid/uuid.rb +5 -3
  92. data/lib/active_record/connection_adapters/postgresql/quoting.rb +44 -7
  93. data/lib/active_record/connection_adapters/postgresql/referential_integrity.rb +1 -1
  94. data/lib/active_record/connection_adapters/postgresql/schema_creation.rb +14 -3
  95. data/lib/active_record/connection_adapters/postgresql/schema_definitions.rb +107 -91
  96. data/lib/active_record/connection_adapters/postgresql/schema_dumper.rb +0 -1
  97. data/lib/active_record/connection_adapters/postgresql/schema_statements.rb +63 -75
  98. data/lib/active_record/connection_adapters/postgresql/type_metadata.rb +24 -27
  99. data/lib/active_record/connection_adapters/postgresql/utils.rb +0 -1
  100. data/lib/active_record/connection_adapters/postgresql_adapter.rb +168 -75
  101. data/lib/active_record/connection_adapters/schema_cache.rb +37 -14
  102. data/lib/active_record/connection_adapters/sql_type_metadata.rb +11 -8
  103. data/lib/active_record/connection_adapters/sqlite3/database_statements.rb +119 -0
  104. data/lib/active_record/connection_adapters/sqlite3/quoting.rb +42 -7
  105. data/lib/active_record/connection_adapters/sqlite3/schema_statements.rb +43 -12
  106. data/lib/active_record/connection_adapters/sqlite3_adapter.rb +137 -147
  107. data/lib/active_record/connection_adapters/statement_pool.rb +0 -1
  108. data/lib/active_record/connection_handling.rb +139 -26
  109. data/lib/active_record/core.rb +108 -67
  110. data/lib/active_record/counter_cache.rb +8 -30
  111. data/lib/active_record/database_configurations/database_config.rb +37 -0
  112. data/lib/active_record/database_configurations/hash_config.rb +50 -0
  113. data/lib/active_record/database_configurations/url_config.rb +78 -0
  114. data/lib/active_record/database_configurations.rb +233 -0
  115. data/lib/active_record/dynamic_matchers.rb +3 -4
  116. data/lib/active_record/enum.rb +44 -7
  117. data/lib/active_record/errors.rb +15 -7
  118. data/lib/active_record/explain.rb +1 -2
  119. data/lib/active_record/fixture_set/model_metadata.rb +33 -0
  120. data/lib/active_record/fixture_set/render_context.rb +17 -0
  121. data/lib/active_record/fixture_set/table_row.rb +152 -0
  122. data/lib/active_record/fixture_set/table_rows.rb +46 -0
  123. data/lib/active_record/fixtures.rb +144 -474
  124. data/lib/active_record/gem_version.rb +3 -3
  125. data/lib/active_record/inheritance.rb +13 -6
  126. data/lib/active_record/insert_all.rb +179 -0
  127. data/lib/active_record/integration.rb +68 -16
  128. data/lib/active_record/internal_metadata.rb +11 -3
  129. data/lib/active_record/locking/optimistic.rb +14 -7
  130. data/lib/active_record/locking/pessimistic.rb +3 -3
  131. data/lib/active_record/log_subscriber.rb +8 -27
  132. data/lib/active_record/middleware/database_selector/resolver/session.rb +45 -0
  133. data/lib/active_record/middleware/database_selector/resolver.rb +87 -0
  134. data/lib/active_record/middleware/database_selector.rb +74 -0
  135. data/lib/active_record/migration/command_recorder.rb +54 -22
  136. data/lib/active_record/migration/compatibility.rb +79 -52
  137. data/lib/active_record/migration/join_table.rb +0 -1
  138. data/lib/active_record/migration.rb +104 -85
  139. data/lib/active_record/model_schema.rb +62 -11
  140. data/lib/active_record/nested_attributes.rb +2 -4
  141. data/lib/active_record/no_touching.rb +9 -2
  142. data/lib/active_record/null_relation.rb +0 -1
  143. data/lib/active_record/persistence.rb +232 -29
  144. data/lib/active_record/query_cache.rb +11 -4
  145. data/lib/active_record/querying.rb +33 -21
  146. data/lib/active_record/railtie.rb +80 -61
  147. data/lib/active_record/railties/collection_cache_association_loading.rb +34 -0
  148. data/lib/active_record/railties/controller_runtime.rb +30 -35
  149. data/lib/active_record/railties/databases.rake +199 -46
  150. data/lib/active_record/reflection.rb +51 -51
  151. data/lib/active_record/relation/batches.rb +13 -11
  152. data/lib/active_record/relation/calculations.rb +55 -49
  153. data/lib/active_record/relation/delegation.rb +35 -50
  154. data/lib/active_record/relation/finder_methods.rb +23 -28
  155. data/lib/active_record/relation/from_clause.rb +4 -0
  156. data/lib/active_record/relation/merger.rb +12 -17
  157. data/lib/active_record/relation/predicate_builder/array_handler.rb +5 -4
  158. data/lib/active_record/relation/predicate_builder/association_query_value.rb +1 -4
  159. data/lib/active_record/relation/predicate_builder/base_handler.rb +1 -2
  160. data/lib/active_record/relation/predicate_builder/basic_object_handler.rb +1 -2
  161. data/lib/active_record/relation/predicate_builder/polymorphic_array_value.rb +1 -4
  162. data/lib/active_record/relation/predicate_builder/range_handler.rb +3 -23
  163. data/lib/active_record/relation/predicate_builder.rb +5 -11
  164. data/lib/active_record/relation/query_attribute.rb +13 -8
  165. data/lib/active_record/relation/query_methods.rb +234 -69
  166. data/lib/active_record/relation/spawn_methods.rb +1 -2
  167. data/lib/active_record/relation/where_clause.rb +14 -11
  168. data/lib/active_record/relation/where_clause_factory.rb +1 -2
  169. data/lib/active_record/relation.rb +326 -81
  170. data/lib/active_record/result.rb +30 -12
  171. data/lib/active_record/sanitization.rb +32 -40
  172. data/lib/active_record/schema.rb +2 -11
  173. data/lib/active_record/schema_dumper.rb +22 -7
  174. data/lib/active_record/schema_migration.rb +6 -2
  175. data/lib/active_record/scoping/default.rb +4 -6
  176. data/lib/active_record/scoping/named.rb +25 -16
  177. data/lib/active_record/scoping.rb +8 -9
  178. data/lib/active_record/statement_cache.rb +30 -3
  179. data/lib/active_record/store.rb +87 -8
  180. data/lib/active_record/suppressor.rb +2 -2
  181. data/lib/active_record/table_metadata.rb +23 -15
  182. data/lib/active_record/tasks/database_tasks.rb +194 -25
  183. data/lib/active_record/tasks/mysql_database_tasks.rb +5 -6
  184. data/lib/active_record/tasks/postgresql_database_tasks.rb +5 -8
  185. data/lib/active_record/tasks/sqlite_database_tasks.rb +2 -9
  186. data/lib/active_record/test_databases.rb +23 -0
  187. data/lib/active_record/test_fixtures.rb +243 -0
  188. data/lib/active_record/timestamp.rb +39 -26
  189. data/lib/active_record/touch_later.rb +5 -4
  190. data/lib/active_record/transactions.rb +64 -73
  191. data/lib/active_record/translation.rb +1 -1
  192. data/lib/active_record/type/adapter_specific_registry.rb +3 -13
  193. data/lib/active_record/type/hash_lookup_type_map.rb +0 -1
  194. data/lib/active_record/type/serialized.rb +0 -1
  195. data/lib/active_record/type/time.rb +10 -0
  196. data/lib/active_record/type/type_map.rb +0 -1
  197. data/lib/active_record/type/unsigned_integer.rb +0 -1
  198. data/lib/active_record/type.rb +3 -5
  199. data/lib/active_record/type_caster/connection.rb +15 -14
  200. data/lib/active_record/type_caster/map.rb +1 -4
  201. data/lib/active_record/validations/associated.rb +0 -1
  202. data/lib/active_record/validations/uniqueness.rb +15 -27
  203. data/lib/active_record/validations.rb +3 -3
  204. data/lib/active_record.rb +10 -2
  205. data/lib/arel/alias_predication.rb +9 -0
  206. data/lib/arel/attributes/attribute.rb +37 -0
  207. data/lib/arel/attributes.rb +22 -0
  208. data/lib/arel/collectors/bind.rb +24 -0
  209. data/lib/arel/collectors/composite.rb +31 -0
  210. data/lib/arel/collectors/plain_string.rb +20 -0
  211. data/lib/arel/collectors/sql_string.rb +20 -0
  212. data/lib/arel/collectors/substitute_binds.rb +28 -0
  213. data/lib/arel/crud.rb +42 -0
  214. data/lib/arel/delete_manager.rb +18 -0
  215. data/lib/arel/errors.rb +9 -0
  216. data/lib/arel/expressions.rb +29 -0
  217. data/lib/arel/factory_methods.rb +49 -0
  218. data/lib/arel/insert_manager.rb +49 -0
  219. data/lib/arel/math.rb +45 -0
  220. data/lib/arel/nodes/and.rb +32 -0
  221. data/lib/arel/nodes/ascending.rb +23 -0
  222. data/lib/arel/nodes/binary.rb +52 -0
  223. data/lib/arel/nodes/bind_param.rb +36 -0
  224. data/lib/arel/nodes/case.rb +55 -0
  225. data/lib/arel/nodes/casted.rb +50 -0
  226. data/lib/arel/nodes/comment.rb +29 -0
  227. data/lib/arel/nodes/count.rb +12 -0
  228. data/lib/arel/nodes/delete_statement.rb +45 -0
  229. data/lib/arel/nodes/descending.rb +23 -0
  230. data/lib/arel/nodes/equality.rb +18 -0
  231. data/lib/arel/nodes/extract.rb +24 -0
  232. data/lib/arel/nodes/false.rb +16 -0
  233. data/lib/arel/nodes/full_outer_join.rb +8 -0
  234. data/lib/arel/nodes/function.rb +44 -0
  235. data/lib/arel/nodes/grouping.rb +8 -0
  236. data/lib/arel/nodes/in.rb +8 -0
  237. data/lib/arel/nodes/infix_operation.rb +80 -0
  238. data/lib/arel/nodes/inner_join.rb +8 -0
  239. data/lib/arel/nodes/insert_statement.rb +37 -0
  240. data/lib/arel/nodes/join_source.rb +20 -0
  241. data/lib/arel/nodes/matches.rb +18 -0
  242. data/lib/arel/nodes/named_function.rb +23 -0
  243. data/lib/arel/nodes/node.rb +50 -0
  244. data/lib/arel/nodes/node_expression.rb +13 -0
  245. data/lib/arel/nodes/outer_join.rb +8 -0
  246. data/lib/arel/nodes/over.rb +15 -0
  247. data/lib/arel/nodes/regexp.rb +16 -0
  248. data/lib/arel/nodes/right_outer_join.rb +8 -0
  249. data/lib/arel/nodes/select_core.rb +67 -0
  250. data/lib/arel/nodes/select_statement.rb +41 -0
  251. data/lib/arel/nodes/sql_literal.rb +16 -0
  252. data/lib/arel/nodes/string_join.rb +11 -0
  253. data/lib/arel/nodes/table_alias.rb +27 -0
  254. data/lib/arel/nodes/terminal.rb +16 -0
  255. data/lib/arel/nodes/true.rb +16 -0
  256. data/lib/arel/nodes/unary.rb +45 -0
  257. data/lib/arel/nodes/unary_operation.rb +20 -0
  258. data/lib/arel/nodes/unqualified_column.rb +22 -0
  259. data/lib/arel/nodes/update_statement.rb +41 -0
  260. data/lib/arel/nodes/values_list.rb +9 -0
  261. data/lib/arel/nodes/window.rb +126 -0
  262. data/lib/arel/nodes/with.rb +11 -0
  263. data/lib/arel/nodes.rb +68 -0
  264. data/lib/arel/order_predications.rb +13 -0
  265. data/lib/arel/predications.rb +256 -0
  266. data/lib/arel/select_manager.rb +271 -0
  267. data/lib/arel/table.rb +110 -0
  268. data/lib/arel/tree_manager.rb +72 -0
  269. data/lib/arel/update_manager.rb +34 -0
  270. data/lib/arel/visitors/depth_first.rb +203 -0
  271. data/lib/arel/visitors/dot.rb +296 -0
  272. data/lib/arel/visitors/ibm_db.rb +34 -0
  273. data/lib/arel/visitors/informix.rb +62 -0
  274. data/lib/arel/visitors/mssql.rb +156 -0
  275. data/lib/arel/visitors/mysql.rb +83 -0
  276. data/lib/arel/visitors/oracle.rb +158 -0
  277. data/lib/arel/visitors/oracle12.rb +65 -0
  278. data/lib/arel/visitors/postgresql.rb +109 -0
  279. data/lib/arel/visitors/sqlite.rb +38 -0
  280. data/lib/arel/visitors/to_sql.rb +888 -0
  281. data/lib/arel/visitors/visitor.rb +45 -0
  282. data/lib/arel/visitors/where_sql.rb +22 -0
  283. data/lib/arel/visitors.rb +20 -0
  284. data/lib/arel/window_predications.rb +9 -0
  285. data/lib/arel.rb +62 -0
  286. data/lib/rails/generators/active_record/application_record/application_record_generator.rb +0 -1
  287. data/lib/rails/generators/active_record/migration/migration_generator.rb +2 -5
  288. data/lib/rails/generators/active_record/migration/templates/create_table_migration.rb.tt +1 -1
  289. data/lib/rails/generators/active_record/migration/templates/migration.rb.tt +4 -2
  290. data/lib/rails/generators/active_record/migration.rb +14 -2
  291. data/lib/rails/generators/active_record/model/model_generator.rb +1 -1
  292. data/lib/rails/generators/active_record/model/templates/model.rb.tt +10 -1
  293. metadata +113 -26
  294. data/lib/active_record/collection_cache_key.rb +0 -53
data/CHANGELOG.md CHANGED
@@ -1,4 +1,30 @@
1
- ## Rails 5.2.8.1 (July 12, 2022) ##
1
+ ## Rails 6.0.6.1 (January 17, 2023) ##
2
+
3
+ * Make `sanitize_as_sql_comment` more strict
4
+
5
+ Though this method was likely never meant to take user input, it was
6
+ attempting sanitization. That sanitization could be bypassed with
7
+ carefully crafted input.
8
+
9
+ This commit makes the sanitization more robust by replacing any
10
+ occurrances of "/*" or "*/" with "/ *" or "* /". It also performs a
11
+ first pass to remove one surrounding comment to avoid compatibility
12
+ issues for users relying on the existing removal.
13
+
14
+ This also clarifies in the documentation of annotate that it should not
15
+ be provided user input.
16
+
17
+ [CVE-2023-22794]
18
+
19
+
20
+ ## Rails 6.0.6 (September 09, 2022) ##
21
+
22
+ * Symbol is allowed by default for YAML columns
23
+
24
+ *Étienne Barrié*
25
+
26
+
27
+ ## Rails 6.0.5.1 (July 12, 2022) ##
2
28
 
3
29
  * Change ActiveRecord::Coders::YAMLColumn default to safe_load
4
30
 
@@ -26,52 +52,170 @@
26
52
  [CVE-2022-32224]
27
53
 
28
54
 
29
- ## Rails 5.2.8 (May 09, 2022) ##
55
+ ## Rails 6.0.5 (May 09, 2022) ##
30
56
 
31
57
  * No changes.
32
58
 
33
59
 
34
- ## Rails 5.2.7.1 (April 26, 2022) ##
60
+ ## Rails 6.0.4.8 (April 26, 2022) ##
35
61
 
36
62
  * No changes.
37
63
 
38
64
 
39
- ## Rails 5.2.7 (March 10, 2022) ##
65
+ ## Rails 6.0.4.7 (March 08, 2022) ##
40
66
 
41
67
  * No changes.
42
68
 
43
69
 
44
- ## Rails 5.2.6.3 (March 08, 2022) ##
70
+ ## Rails 6.0.4.6 (February 11, 2022) ##
45
71
 
46
72
  * No changes.
47
73
 
48
74
 
49
- ## Rails 5.2.6.2 (February 11, 2022) ##
75
+ ## Rails 6.0.4.5 (February 11, 2022) ##
50
76
 
51
77
  * No changes.
52
78
 
53
79
 
54
- ## Rails 5.2.6.1 (February 11, 2022) ##
80
+ ## Rails 6.0.4.4 (December 15, 2021) ##
55
81
 
56
82
  * No changes.
57
83
 
58
84
 
59
- ## Rails 5.2.6 (May 05, 2021) ##
85
+ ## Rails 6.0.4.3 (December 14, 2021) ##
60
86
 
61
87
  * No changes.
62
88
 
63
89
 
64
- ## Rails 5.2.5 (March 26, 2021) ##
90
+ ## Rails 6.0.4.2 (December 14, 2021) ##
65
91
 
66
92
  * No changes.
67
93
 
68
94
 
69
- ## Rails 5.2.4.6 (May 05, 2021) ##
95
+ ## Rails 6.0.4.1 (August 19, 2021) ##
70
96
 
71
97
  * No changes.
72
98
 
73
99
 
74
- ## Rails 5.2.4.5 (February 10, 2021) ##
100
+ ## Rails 6.0.4 (June 15, 2021) ##
101
+
102
+ * Only warn about negative enums if a positive form that would cause conflicts exists.
103
+
104
+ Fixes #39065.
105
+
106
+ *Alex Ghiculescu*
107
+
108
+ * Allow the inverse of a `has_one` association that was previously autosaved to be loaded.
109
+
110
+ Fixes #34255.
111
+
112
+ *Steven Weber*
113
+
114
+ * Reset statement cache for association if `table_name` is changed.
115
+
116
+ Fixes #36453.
117
+
118
+ *Ryuta Kamizono*
119
+
120
+ * Type cast extra select for eager loading.
121
+
122
+ *Ryuta Kamizono*
123
+
124
+ * Prevent collection associations from being autosaved multiple times.
125
+
126
+ Fixes #39173.
127
+
128
+ *Eugene Kenny*
129
+
130
+ * Resolve issue with insert_all unique_by option when used with expression index.
131
+
132
+ When the `:unique_by` option of `ActiveRecord::Persistence.insert_all` and
133
+ `ActiveRecord::Persistence.upsert_all` was used with the name of an expression index, an error
134
+ was raised. Adding a guard around the formatting behavior for the `:unique_by` corrects this.
135
+
136
+ Usage:
137
+
138
+ ```ruby
139
+ create_table :books, id: :integer, force: true do |t|
140
+ t.column :name, :string
141
+ t.index "lower(name)", unique: true
142
+ end
143
+
144
+ Book.insert_all [{ name: "MyTest" }], unique_by: :index_books_on_lower_name
145
+ ```
146
+
147
+ Fixes #39516.
148
+
149
+ *Austen Madden*
150
+
151
+ * Fix preloading for polymorphic association with custom scope.
152
+
153
+ *Ryuta Kamizono*
154
+
155
+ * Allow relations with different SQL comments in the `or` method.
156
+
157
+ *Takumi Shotoku*
158
+
159
+ * Resolve conflict between counter cache and optimistic locking.
160
+
161
+ Bump an Active Record instance's lock version after updating its counter
162
+ cache. This avoids raising an unnecessary `ActiveRecord::StaleObjectError`
163
+ upon subsequent transactions by maintaining parity with the corresponding
164
+ database record's `lock_version` column.
165
+
166
+ Fixes #16449.
167
+
168
+ *Aaron Lipman*
169
+
170
+ * Fix through association with source/through scope which has joins.
171
+
172
+ *Ryuta Kamizono*
173
+
174
+ * Fix through association to respect source scope for includes/preload.
175
+
176
+ *Ryuta Kamizono*
177
+
178
+ * Fix eager load with Arel joins to maintain the original joins order.
179
+
180
+ *Ryuta Kamizono*
181
+
182
+ * Fix group by count with eager loading + order + limit/offset.
183
+
184
+ *Ryuta Kamizono*
185
+
186
+ * Fix left joins order when merging multiple left joins from different associations.
187
+
188
+ *Ryuta Kamizono*
189
+
190
+ * Fix index creation to preserve index comment in bulk change table on MySQL.
191
+
192
+ *Ryuta Kamizono*
193
+
194
+ * Change `remove_foreign_key` to not check `:validate` option if database
195
+ doesn't support the feature.
196
+
197
+ *Ryuta Kamizono*
198
+
199
+ * Fix the result of aggregations to maintain duplicated "group by" fields.
200
+
201
+ *Ryuta Kamizono*
202
+
203
+ * Do not return duplicated records when using preload.
204
+
205
+ *Bogdan Gusiev*
206
+
207
+
208
+ ## Rails 6.0.3.7 (May 05, 2021) ##
209
+
210
+ * No changes.
211
+
212
+
213
+ ## Rails 6.0.3.6 (March 26, 2021) ##
214
+
215
+ * No changes.
216
+
217
+
218
+ ## Rails 6.0.3.5 (February 10, 2021) ##
75
219
 
76
220
  * Fix possible DoS vector in PostgreSQL money type
77
221
 
@@ -86,999 +230,1220 @@
86
230
  *Aaron Patterson*
87
231
 
88
232
 
89
- ## Rails 5.2.4.4 (September 09, 2020) ##
233
+ ## Rails 6.0.3.4 (October 07, 2020) ##
90
234
 
91
235
  * No changes.
92
236
 
93
237
 
94
- ## Rails 5.2.4.3 (May 18, 2020) ##
238
+ ## Rails 6.0.3.3 (September 09, 2020) ##
95
239
 
96
240
  * No changes.
97
241
 
98
- ## Rails 5.2.4.2 (March 19, 2020) ##
242
+
243
+ ## Rails 6.0.3.2 (June 17, 2020) ##
99
244
 
100
245
  * No changes.
101
246
 
102
247
 
103
- ## Rails 5.2.4.1 (December 18, 2019) ##
248
+ ## Rails 6.0.3.1 (May 18, 2020) ##
104
249
 
105
250
  * No changes.
106
251
 
107
252
 
108
- ## Rails 5.2.4 (November 27, 2019) ##
253
+ ## Rails 6.0.3 (May 06, 2020) ##
109
254
 
110
- * Fix circular `autosave: true` causes invalid records to be saved.
255
+ * Recommend applications don't use the `database` kwarg in `connected_to`
111
256
 
112
- Prior to the fix, when there was a circular series of `autosave: true`
113
- associations, the callback for a `has_many` association was run while
114
- another instance of the same callback on the same association hadn't
115
- finished running. When control returned to the first instance of the
116
- callback, the instance variable had changed, and subsequent associated
117
- records weren't saved correctly. Specifically, the ID field for the
118
- `belongs_to` corresponding to the `has_many` was `nil`.
257
+ The database kwarg in `connected_to` was meant to be used for one-off scripts but is often used in requests. This is really dangerous because it re-establishes a connection every time. It's deprecated in 6.1 and will be removed in 6.2 without replacement. This change soft deprecates it in 6.0 by removing documentation.
119
258
 
120
- Fixes #28080.
259
+ *Eileen M. Uchitelle*
121
260
 
122
- *Larry Reid*
261
+ * Fix support for PostgreSQL 11+ partitioned indexes.
123
262
 
124
- * PostgreSQL: Fix GROUP BY with ORDER BY virtual count attribute.
263
+ *Sebastián Palma*
125
264
 
126
- Fixes #36022.
265
+ * Add support for beginless ranges, introduced in Ruby 2.7.
127
266
 
128
- *Ryuta Kamizono*
267
+ *Josh Goodall*
129
268
 
130
- * Fix sqlite3 collation parsing when using decimal columns.
269
+ * Fix insert_all with enum values
131
270
 
132
- *Martin R. Schuster*
271
+ Fixes #38716.
133
272
 
134
- * Make ActiveRecord `ConnectionPool.connections` method thread-safe.
273
+ *Joel Blum*
135
274
 
136
- Fixes #36465.
275
+ * Regexp-escape table name for MS SQL
137
276
 
138
- *Jeff Doering*
277
+ 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.
139
278
 
140
- * Assign all attributes before calling `build` to ensure the child record is visible in
141
- `before_add` and `after_add` callbacks for `has_many :through` associations.
279
+ *Larry Reid*
142
280
 
143
- Fixes #33249.
281
+ * Store advisory locks on their own named connection.
144
282
 
145
- *Ryan H. Kerr*
283
+ 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.
146
284
 
285
+ In order to fix this we are storing the advisory lock on a new connection with the connection specification name `AdisoryLockBase`. The caveat is that we need to maintain at least 2 connections to a database while migrations are running in order to do this.
147
286
 
148
- ## Rails 5.2.3 (March 27, 2019) ##
287
+ *Eileen M. Uchitelle*, *John Crepezzi*
149
288
 
150
- * Fix different `count` calculation when using `size` with manual `select` with DISTINCT.
289
+ * Ensure `:reading` connections always raise if a write is attempted.
151
290
 
152
- Fixes #35214.
291
+ 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`.
153
292
 
154
- *Juani Villarejo*
293
+ *Eileen M. Uchitelle*
155
294
 
156
- * Fix prepared statements caching to be enabled even when query caching is enabled.
295
+ * Enforce fresh ETag header after a collection's contents change by adding
296
+ ActiveRecord::Relation#cache_key_with_version. This method will be used by
297
+ ActionController::ConditionalGet to ensure that when collection cache versioning
298
+ is enabled, requests using ConditionalGet don't return the same ETag header
299
+ after a collection is modified. Fixes #38078.
157
300
 
158
- *Ryuta Kamizono*
301
+ *Aaron Lipman*
159
302
 
160
- * Don't allow `where` with invalid value matches to nil values.
303
+ * A database URL can now contain a querystring value that contains an equal sign. This is needed to support passing PostgresSQL `options`.
161
304
 
162
- Fixes #33624.
305
+ *Joshua Flanagan*
163
306
 
164
- *Ryuta Kamizono*
307
+ * Retain explicit selections on the base model after applying `includes` and `joins`.
165
308
 
166
- * Restore an ability that class level `update` without giving ids.
309
+ Resolves #34889.
167
310
 
168
- Fixes #34743.
311
+ *Patrick Rebsch*
169
312
 
170
- *Ryuta Kamizono*
171
313
 
172
- * Fix join table column quoting with SQLite.
314
+ ## Rails 6.0.2.2 (March 19, 2020) ##
173
315
 
174
- *Gannon McGibbon*
316
+ * No changes.
175
317
 
176
- * Ensure that `delete_all` on collection proxy returns affected count.
177
318
 
178
- *Ryuta Kamizono*
319
+ ## Rails 6.0.2.1 (December 18, 2019) ##
179
320
 
180
- * Reset scope after delete on collection association to clear stale offsets of removed records.
321
+ * No changes.
181
322
 
182
- *Gannon McGibbon*
183
323
 
324
+ ## Rails 6.0.2 (December 13, 2019) ##
184
325
 
185
- ## Rails 5.2.2.1 (March 11, 2019) ##
326
+ * Share the same connection pool for primary and replica databases in the
327
+ transactional tests for the same database.
186
328
 
187
- * No changes.
329
+ *Edouard Chin*
188
330
 
331
+ * Fix the preloader when one record is fetched using `after_initialize`
332
+ but not the entire collection.
189
333
 
190
- ## Rails 5.2.2 (December 04, 2018) ##
334
+ *Bradley Price*
191
335
 
192
- * Do not ignore the scoping with query methods in the scope block.
336
+ * Fix collection callbacks not terminating when `:abort` is thrown.
337
+
338
+ *Edouard Chin*, *Ryuta Kamizono*
339
+
340
+ * Correctly deprecate `where.not` working as NOR for relations.
341
+
342
+ 12a9664 deprecated where.not working as NOR, however
343
+ doing a relation query like `where.not(relation: { ... })`
344
+ wouldn't be properly deprecated and `where.not` would work as
345
+ NAND instead.
346
+
347
+ *Edouard Chin*
348
+
349
+ * Fix `db:migrate` task with multiple databases to restore the connection
350
+ to the previous database.
351
+
352
+ The migrate task iterates and establish a connection over each db
353
+ resulting in the last one to be used by subsequent rake tasks.
354
+ We should reestablish a connection to the connection that was
355
+ established before the migrate tasks was run
356
+
357
+ *Edouard Chin*
358
+
359
+ * Fix multi-threaded issue for `AcceptanceValidator`.
193
360
 
194
361
  *Ryuta Kamizono*
195
362
 
196
- * Allow aliased attributes to be used in `#update_columns` and `#update`.
197
363
 
198
- *Gannon McGibbon*
364
+ ## Rails 6.0.1 (November 5, 2019) ##
199
365
 
200
- * Allow spaces in postgres table names.
366
+ * Common Table Expressions are allowed on read-only connections.
201
367
 
202
- Fixes issue where "user post" is misinterpreted as "\"user\".\"post\"" when quoting table names with the postgres
203
- adapter.
368
+ *Chris Morris*
204
369
 
205
- *Gannon McGibbon*
370
+ * New record instantiation respects `unscope`.
206
371
 
207
- * Cached columns_hash fields should be excluded from ResultSet#column_types
372
+ *Ryuta Kamizono*
208
373
 
209
- PR #34528 addresses the inconsistent behaviour when attribute is defined for an ignored column. The following test
210
- was passing for SQLite and MySQL, but failed for PostgreSQL:
374
+ * Fixed a case where `find_in_batches` could halt too early.
211
375
 
212
- ```ruby
213
- class DeveloperName < ActiveRecord::Type::String
214
- def deserialize(value)
215
- "Developer: #{value}"
216
- end
217
- end
376
+ *Takayuki Nakata*
218
377
 
219
- class AttributedDeveloper < ActiveRecord::Base
220
- self.table_name = "developers"
378
+ * Autosaved associations always perform validations when a custom validation
379
+ context is used.
221
380
 
222
- attribute :name, DeveloperName.new
381
+ *Tekin Suleyman*
223
382
 
224
- self.ignored_columns += ["name"]
225
- end
383
+ * `sql.active_record` notifications now include the `:connection` in
384
+ their payloads.
226
385
 
227
- developer = AttributedDeveloper.create
228
- developer.update_column :name, "name"
386
+ *Eugene Kenny*
229
387
 
230
- loaded_developer = AttributedDeveloper.where(id: developer.id).select("*").first
231
- puts loaded_developer.name # should be "Developer: name" but it's just "name"
232
- ```
388
+ * A rollback encountered in an `after_commit` callback does not reset
389
+ previously-committed record state.
233
390
 
234
- *Dmitry Tsepelev*
391
+ *Ryuta Kamizono*
235
392
 
236
- * Values of enum are frozen, raising an error when attempting to modify them.
393
+ * Fixed that join order was lost when eager-loading.
237
394
 
238
- *Emmanuel Byrd*
395
+ *Ryuta Kamizono*
239
396
 
240
- * `update_columns` now correctly raises `ActiveModel::MissingAttributeError`
241
- if the attribute does not exist.
397
+ * `DESCRIBE` queries are allowed on read-only connections.
242
398
 
243
- *Sean Griffin*
399
+ *Dylan Thacker-Smith*
244
400
 
245
- * Do not use prepared statement in queries that have a large number of binds.
401
+ * Fixed that records that had been `inspect`ed could not be marshaled.
246
402
 
247
- *Ryuta Kamizono*
403
+ *Eugene Kenny*
248
404
 
249
- * Fix query cache to load before first request.
405
+ * The connection pool reaper thread is respawned in forked processes. This
406
+ fixes that idle connections in forked processes wouldn't be reaped.
250
407
 
251
- *Eileen M. Uchitelle*
408
+ *John Hawthorn*
252
409
 
253
- * Fix collection cache key with limit and custom select to avoid ambiguous timestamp column error.
410
+ * The memoized result of `ActiveRecord::Relation#take` is properly cleared
411
+ when `ActiveRecord::Relation#reset` or `ActiveRecord::Relation#reload`
412
+ is called.
254
413
 
255
- Fixes #33056.
414
+ *Anmol Arora*
256
415
 
257
- *Federico Martinez*
416
+ * Fixed the performance regression for `primary_keys` introduced MySQL 8.0.
258
417
 
259
- * Fix duplicated record creation when using nested attributes with `create_with`.
418
+ *Hiroyuki Ishii*
260
419
 
261
- *Darwin Wu*
420
+ * `insert`, `insert_all`, `upsert`, and `upsert_all` now clear the query cache.
262
421
 
263
- * Fix regression setting children record in parent `before_save` callback.
422
+ *Eugene Kenny*
264
423
 
265
- *Guo Xiang Tan*
424
+ * Call `while_preventing_writes` directly from `connected_to`.
266
425
 
267
- * Prevent leaking of user's DB credentials on `rails db:create` failure.
426
+ 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)`.
268
427
 
269
- *bogdanvlviv*
428
+ 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.
270
429
 
271
- * Clear mutation tracker before continuing the around callbacks.
430
+ *Eileen M. Uchitelle*
272
431
 
273
- *Yuya Tanaka*
432
+ * Improve detection of ActiveRecord::StatementTimeout with mysql2 adapter in the edge case when the query is terminated during filesort.
274
433
 
275
- * Prevent deadlocks when waiting for connection from pool.
434
+ *Kir Shatrov*
276
435
 
277
- *Brent Wheeldon*
278
436
 
279
- * Avoid extra scoping when using `Relation#update` that was causing this method to change the current scope.
437
+ ## Rails 6.0.0 (August 16, 2019) ##
280
438
 
281
- *Ryuta Kamizono*
439
+ * Preserve user supplied joins order as much as possible.
282
440
 
283
- * Fix numericality validator not to be affected by custom getter.
441
+ Fixes #36761, #34328, #24281, #12953.
284
442
 
285
443
  *Ryuta Kamizono*
286
444
 
287
- * Fix bulk change table ignores comment option on PostgreSQL.
445
+ * Make the DATABASE_URL env variable only affect the primary connection. Add new env variables for multiple databases.
288
446
 
289
- *Yoshiyuki Kinjo*
447
+ *John Crepezzi*, *Eileen Uchitelle*
290
448
 
449
+ * Add a warning for enum elements with 'not_' prefix.
291
450
 
292
- ## Rails 5.2.1.1 (November 27, 2018) ##
451
+ class Foo
452
+ enum status: [:sent, :not_sent]
453
+ end
293
454
 
294
- * No changes.
455
+ *Edu Depetris*
295
456
 
457
+ * Make currency symbols optional for money column type in PostgreSQL
296
458
 
297
- ## Rails 5.2.1 (August 07, 2018) ##
459
+ *Joel Schneider*
298
460
 
299
- * PostgreSQL: Support new relkind for partitioned tables.
300
461
 
301
- Fixes #33008.
462
+ ## Rails 6.0.0.rc2 (July 22, 2019) ##
302
463
 
303
- *Yannick Schutz*
464
+ * Add database_exists? method to connection adapters to check if a database exists.
304
465
 
305
- * Rollback parent transaction when children fails to update.
466
+ *Guilherme Mansur*
306
467
 
307
- *Guillaume Malette*
468
+ * PostgreSQL: Fix GROUP BY with ORDER BY virtual count attribute.
308
469
 
309
- * Fix default value for MySQL time types with specified precision.
470
+ Fixes #36022.
310
471
 
311
- *Nikolay Kondratyev*
472
+ *Ryuta Kamizono*
312
473
 
313
- * Fix `touch` option to behave consistently with `Persistence#touch` method.
474
+ * Make ActiveRecord `ConnectionPool.connections` method thread-safe.
314
475
 
315
- *Ryuta Kamizono*
476
+ Fixes #36465.
316
477
 
317
- * Fix `save` in `after_create_commit` won't invoke extra `after_create_commit`.
478
+ *Jeff Doering*
318
479
 
319
- Fixes #32831.
480
+ * Fix sqlite3 collation parsing when using decimal columns.
320
481
 
321
- *Ryuta Kamizono*
482
+ *Martin R. Schuster*
322
483
 
323
- * Fix logic on disabling commit callbacks so they are not called unexpectedly when errors occur.
484
+ * Fix invalid schema when primary key column has a comment.
324
485
 
325
- *Brian Durand*
486
+ Fixes #29966.
326
487
 
327
- * Fix parent record should not get saved with duplicate children records.
488
+ *Guilherme Goettems Schneider*
328
489
 
329
- Fixes #32940.
490
+ * Fix table comment also being applied to the primary key column.
330
491
 
331
- *Santosh Wadghule*
492
+ *Guilherme Goettems Schneider*
332
493
 
333
- * Fix that association's after_touch is not called with counter cache.
494
+ * Fix merging left_joins to maintain its own `join_type` context.
334
495
 
335
- Fixes #31559.
496
+ Fixes #36103.
336
497
 
337
498
  *Ryuta Kamizono*
338
499
 
339
- * `becomes` should clear the mutation tracker which is created in `after_initialize`.
340
500
 
341
- Fixes #32867.
501
+ ## Rails 6.0.0.rc1 (April 24, 2019) ##
342
502
 
343
- *Ryuta Kamizono*
503
+ * Add `touch` option to `has_one` association.
344
504
 
345
- * Allow a belonging to parent object to be created from a new record.
505
+ *Abhay Nikam*
346
506
 
347
- *Jolyon Pawlyn*
507
+ * Deprecate `where.not` working as NOR and will be changed to NAND in Rails 6.1.
348
508
 
349
- * Fix that building record with assigning multiple has_one associations
350
- wrongly persists through record.
509
+ ```ruby
510
+ all = [treasures(:diamond), treasures(:sapphire), cars(:honda), treasures(:sapphire)]
511
+ assert_equal all, PriceEstimate.all.map(&:estimate_of)
512
+ ```
351
513
 
352
- Fixes #32511.
514
+ In Rails 6.0:
353
515
 
354
- *Sam DeCesare*
516
+ ```ruby
517
+ sapphire = treasures(:sapphire)
518
+
519
+ nor = all.reject { |e|
520
+ e.estimate_of_type == sapphire.class.polymorphic_name
521
+ }.reject { |e|
522
+ e.estimate_of_id == sapphire.id
523
+ }
524
+ assert_equal [cars(:honda)], nor
525
+
526
+ without_sapphire = PriceEstimate.where.not(
527
+ estimate_of_type: sapphire.class.polymorphic_name, estimate_of_id: sapphire.id
528
+ )
529
+ assert_equal nor, without_sapphire.map(&:estimate_of)
530
+ ```
355
531
 
356
- * Fix relation merging when one of the relations is going to skip the
357
- query cache.
532
+ In Rails 6.1:
358
533
 
359
- *James Williams*
534
+ ```ruby
535
+ sapphire = treasures(:sapphire)
360
536
 
537
+ nand = all - [sapphire]
538
+ assert_equal [treasures(:diamond), cars(:honda)], nand
361
539
 
362
- ## Rails 5.2.0 (April 09, 2018) ##
540
+ without_sapphire = PriceEstimate.where.not(
541
+ estimate_of_type: sapphire.class.polymorphic_name, estimate_of_id: sapphire.id
542
+ )
543
+ assert_equal nand, without_sapphire.map(&:estimate_of)
544
+ ```
363
545
 
364
- * MySQL: Support mysql2 0.5.x.
546
+ *Ryuta Kamizono*
365
547
 
366
- *Aaron Stone*
548
+ * Fix dirty tracking after rollback.
367
549
 
368
- * Apply time column precision on assignment.
550
+ Fixes #15018, #30167, #33868.
369
551
 
370
- PR #20317 changed the behavior of datetime columns so that when they
371
- have a specified precision then on assignment the value is rounded to
372
- that precision. This behavior is now applied to time columns as well.
552
+ *Ryuta Kamizono*
373
553
 
374
- Fixes #30301.
554
+ * Add `ActiveRecord::Relation#cache_version` to support recyclable cache keys via
555
+ the versioned entries in `ActiveSupport::Cache`. This also means that
556
+ `ActiveRecord::Relation#cache_key` will now return a stable key that does not
557
+ include the max timestamp or count any more.
375
558
 
376
- *Andrew White*
559
+ NOTE: This feature is turned off by default, and `cache_key` will still return
560
+ cache keys with timestamps until you set `ActiveRecord::Base.collection_cache_versioning = true`.
561
+ That's the setting for all new apps on Rails 6.0+
377
562
 
378
- * Normalize time column values for SQLite database.
563
+ *Lachlan Sylvester*
379
564
 
380
- For legacy reasons, time columns in SQLite are stored as full datetimes
381
- because until #24542 the quoting for time columns didn't remove the date
382
- component. To ensure that values are consistent we now normalize the
383
- date component to 2001-01-01 on reading and writing.
565
+ * Fix dirty tracking for `touch` to track saved changes.
384
566
 
385
- *Andrew White*
567
+ Fixes #33429.
386
568
 
387
- * Ensure that the date component is removed when quoting times.
569
+ *Ryuta Kamzono*
388
570
 
389
- PR #24542 altered the quoting for time columns so that the date component
390
- was removed however it only removed it when it was 2001-01-01. Now the
391
- date component is removed irrespective of what the date is.
571
+ * `change_column_comment` and `change_table_comment` are invertible only if
572
+ `to` and `from` options are specified.
392
573
 
393
- *Andrew White*
574
+ *Yoshiyuki Kinjo*
394
575
 
395
- * Fix `dependent: :destroy` issue for has_one/belongs_to relationship where
396
- the parent class was getting deleted when the child was not.
576
+ * Don't call commit/rollback callbacks when a record isn't saved.
397
577
 
398
- Fixes #32022.
578
+ Fixes #29747.
399
579
 
400
- *Fernando Gorodscy*
580
+ *Ryuta Kamizono*
401
581
 
402
- * Whitelist `NULLS FIRST` and `NULLS LAST` in order clauses too.
582
+ * Fix circular `autosave: true` causes invalid records to be saved.
403
583
 
404
- *Xavier Noria*
584
+ Prior to the fix, when there was a circular series of `autosave: true`
585
+ associations, the callback for a `has_many` association was run while
586
+ another instance of the same callback on the same association hadn't
587
+ finished running. When control returned to the first instance of the
588
+ callback, the instance variable had changed, and subsequent associated
589
+ records weren't saved correctly. Specifically, the ID field for the
590
+ `belongs_to` corresponding to the `has_many` was `nil`.
405
591
 
406
- * Fix that after commit callbacks on update does not triggered when optimistic locking is enabled.
592
+ Fixes #28080.
407
593
 
408
- *Ryuta Kamizono*
594
+ *Larry Reid*
409
595
 
410
- * Fix `#columns_for_distinct` of MySQL and PostgreSQL to make
411
- `ActiveRecord::FinderMethods#limited_ids_for` use correct primary key values
412
- even if `ORDER BY` columns include other table's primary key.
596
+ * Raise `ArgumentError` for invalid `:limit` and `:precision` like as other options.
413
597
 
414
- Fixes #28364.
598
+ Before:
415
599
 
416
- *Takumi Kagiyama*
600
+ ```ruby
601
+ add_column :items, :attr1, :binary, size: 10 # => ArgumentError
602
+ add_column :items, :attr2, :decimal, scale: 10 # => ArgumentError
603
+ add_column :items, :attr3, :integer, limit: 10 # => ActiveRecordError
604
+ add_column :items, :attr4, :datetime, precision: 10 # => ActiveRecordError
605
+ ```
417
606
 
418
- * Make `reflection.klass` raise if `polymorphic?` not to be misused.
607
+ After:
419
608
 
420
- Fixes #31876.
609
+ ```ruby
610
+ add_column :items, :attr1, :binary, size: 10 # => ArgumentError
611
+ add_column :items, :attr2, :decimal, scale: 10 # => ArgumentError
612
+ add_column :items, :attr3, :integer, limit: 10 # => ArgumentError
613
+ add_column :items, :attr4, :datetime, precision: 10 # => ArgumentError
614
+ ```
421
615
 
422
616
  *Ryuta Kamizono*
423
617
 
424
- * PostgreSQL: Allow pg-1.0 gem to be used with Active Record.
618
+ * Association loading isn't to be affected by scoping consistently
619
+ whether preloaded / eager loaded or not, with the exception of `unscoped`.
620
+
621
+ Before:
622
+
623
+ ```ruby
624
+ Post.where("1=0").scoping do
625
+ Comment.find(1).post # => nil
626
+ Comment.preload(:post).find(1).post # => #<Post id: 1, ...>
627
+ Comment.eager_load(:post).find(1).post # => #<Post id: 1, ...>
628
+ end
629
+ ```
630
+
631
+ After:
425
632
 
426
- *Lars Kanis*
633
+ ```ruby
634
+ Post.where("1=0").scoping do
635
+ Comment.find(1).post # => #<Post id: 1, ...>
636
+ Comment.preload(:post).find(1).post # => #<Post id: 1, ...>
637
+ Comment.eager_load(:post).find(1).post # => #<Post id: 1, ...>
638
+ end
639
+ ```
427
640
 
428
- * Deprecate `expand_hash_conditions_for_aggregates` without replacement.
429
- Using a `Relation` for performing queries is the prefered API.
641
+ Fixes #34638, #35398.
430
642
 
431
643
  *Ryuta Kamizono*
432
644
 
433
- * Fix not expanded problem when passing an Array object as argument to the where method using `composed_of` column.
645
+ * Add `rails db:prepare` to migrate or setup a database.
434
646
 
435
- ```
436
- david_balance = customers(:david).balance
437
- Customer.where(balance: [david_balance]).to_sql
647
+ Runs `db:migrate` if the database exists or `db:setup` if it doesn't.
648
+
649
+ *Roberto Miranda*
438
650
 
439
- # Before: WHERE `customers`.`balance` = NULL
440
- # After : WHERE `customers`.`balance` = 50
651
+ * Add `after_save_commit` callback as shortcut for `after_commit :hook, on: [ :create, :update ]`.
652
+
653
+ *DHH*
654
+
655
+ * Assign all attributes before calling `build` to ensure the child record is visible in
656
+ `before_add` and `after_add` callbacks for `has_many :through` associations.
657
+
658
+ Fixes #33249.
659
+
660
+ *Ryan H. Kerr*
661
+
662
+ * Add `ActiveRecord::Relation#extract_associated` for extracting associated records from a relation.
663
+
664
+ ```
665
+ account.memberships.extract_associated(:user)
666
+ # => Returns collection of User records
441
667
  ```
442
668
 
443
- Fixes #31723.
669
+ *DHH*
444
670
 
445
- *Yutaro Kanagawa*
671
+ * Add `ActiveRecord::Relation#annotate` for adding SQL comments to its queries.
446
672
 
447
- * Fix `count(:all)` with eager loading and having an order other than the driving table.
673
+ For example:
448
674
 
449
- Fixes #31783.
675
+ ```
676
+ Post.where(id: 123).annotate("this is a comment").to_sql
677
+ # SELECT "posts".* FROM "posts" WHERE "posts"."id" = 123 /* this is a comment */
678
+ ```
450
679
 
451
- *Ryuta Kamizono*
680
+ This can be useful in instrumentation or other analysis of issued queries.
452
681
 
453
- * Clear the transaction state when an Active Record object is duped.
682
+ *Matt Yoho*
454
683
 
455
- Fixes #31670.
684
+ * Support Optimizer Hints.
456
685
 
457
- *Yuriy Ustushenko*
686
+ In most databases, a way to control the optimizer is by using optimizer hints,
687
+ which can be specified within individual statements.
458
688
 
459
- * Support for PostgreSQL foreign tables.
689
+ Example (for MySQL):
460
690
 
461
- *fatkodima*
691
+ Topic.optimizer_hints("MAX_EXECUTION_TIME(50000)", "NO_INDEX_MERGE(topics)")
692
+ # SELECT /*+ MAX_EXECUTION_TIME(50000) NO_INDEX_MERGE(topics) */ `topics`.* FROM `topics`
462
693
 
463
- * Fix relation merger issue with `left_outer_joins`.
694
+ Example (for PostgreSQL with pg_hint_plan):
464
695
 
465
- *Mehmet Emin İNAÇ*
696
+ Topic.optimizer_hints("SeqScan(topics)", "Parallel(topics 8)")
697
+ # SELECT /*+ SeqScan(topics) Parallel(topics 8) */ "topics".* FROM "topics"
466
698
 
467
- * Don't allow destroyed object mutation after `save` or `save!` is called.
699
+ See also:
700
+
701
+ * https://dev.mysql.com/doc/refman/8.0/en/optimizer-hints.html
702
+ * https://pghintplan.osdn.jp/pg_hint_plan.html
703
+ * https://docs.oracle.com/en/database/oracle/oracle-database/12.2/tgsql/influencing-the-optimizer.html
704
+ * https://docs.microsoft.com/en-us/sql/t-sql/queries/hints-transact-sql-query?view=sql-server-2017
705
+ * https://www.ibm.com/support/knowledgecenter/en/SSEPGG_11.1.0/com.ibm.db2.luw.admin.perf.doc/doc/c0070117.html
468
706
 
469
707
  *Ryuta Kamizono*
470
708
 
471
- * Take into account association conditions when deleting through records.
709
+ * Fix query attribute method on user-defined attribute to be aware of typecasted value.
472
710
 
473
- Fixes #18424.
711
+ For example, the following code no longer return false as casted non-empty string:
474
712
 
475
- *Piotr Jakubowski*
713
+ ```
714
+ class Post < ActiveRecord::Base
715
+ attribute :user_defined_text, :text
716
+ end
476
717
 
477
- * Fix nested `has_many :through` associations on unpersisted parent instances.
718
+ Post.new(user_defined_text: "false").user_defined_text? # => true
719
+ ```
478
720
 
479
- For example, if you have
721
+ *Yuji Kamijima*
480
722
 
481
- class Post < ActiveRecord::Base
482
- belongs_to :author
483
- has_many :books, through: :author
484
- has_many :subscriptions, through: :books
485
- end
723
+ * Quote empty ranges like other empty enumerables.
486
724
 
487
- class Author < ActiveRecord::Base
488
- has_one :post
489
- has_many :books
490
- has_many :subscriptions, through: :books
491
- end
725
+ *Patrick Rebsch*
492
726
 
493
- class Book < ActiveRecord::Base
494
- belongs_to :author
495
- has_many :subscriptions
496
- end
727
+ * Add `insert_all`/`insert_all!`/`upsert_all` methods to `ActiveRecord::Persistence`,
728
+ allowing bulk inserts akin to the bulk updates provided by `update_all` and
729
+ bulk deletes by `delete_all`.
497
730
 
498
- class Subscription < ActiveRecord::Base
499
- belongs_to :book
500
- end
731
+ Supports skipping or upserting duplicates through the `ON CONFLICT` syntax
732
+ for PostgreSQL (9.5+) and SQLite (3.24+) and `ON DUPLICATE KEY UPDATE` syntax
733
+ for MySQL.
501
734
 
502
- Before:
735
+ *Bob Lail*
503
736
 
504
- If `post` is not persisted, then `post.subscriptions` will be empty.
737
+ * Add `rails db:seed:replant` that truncates tables of each database
738
+ for current environment and loads the seeds.
505
739
 
506
- After:
740
+ *bogdanvlviv*, *DHH*
507
741
 
508
- If `post` is not persisted, then `post.subscriptions` can be set and used
509
- just like it would if `post` were persisted.
742
+ * Add `ActiveRecord::Base.connection.truncate` for SQLite3 adapter.
510
743
 
511
- Fixes #16313.
744
+ *bogdanvlviv*
512
745
 
513
- *Zoltan Kiss*
746
+ * Deprecate mismatched collation comparison for uniqueness validator.
514
747
 
515
- * Fixed inconsistency with `first(n)` when used with `limit()`.
516
- The `first(n)` finder now respects the `limit()`, making it consistent
517
- with `relation.to_a.first(n)`, and also with the behavior of `last(n)`.
748
+ Uniqueness validator will no longer enforce case sensitive comparison in Rails 6.1.
749
+ To continue case sensitive comparison on the case insensitive column,
750
+ pass `case_sensitive: true` option explicitly to the uniqueness validator.
518
751
 
519
- Fixes #23979.
752
+ *Ryuta Kamizono*
520
753
 
521
- *Brian Christian*
754
+ * Add `reselect` method. This is a short-hand for `unscope(:select).select(fields)`.
522
755
 
523
- * Use `count(:all)` in `HasManyAssociation#count_records` to prevent invalid
524
- SQL queries for association counting.
756
+ Fixes #27340.
525
757
 
526
- *Klas Eskilson*
758
+ *Willian Gustavo Veiga*
527
759
 
528
- * Fix to invoke callbacks when using `update_attribute`.
760
+ * Add negative scopes for all enum values.
529
761
 
530
- *Mike Busch*
762
+ Example:
531
763
 
532
- * Fix `count(:all)` to correctly work `distinct` with custom SELECT list.
764
+ class Post < ActiveRecord::Base
765
+ enum status: %i[ drafted active trashed ]
766
+ end
533
767
 
534
- *Ryuta Kamizono*
768
+ Post.not_drafted # => where.not(status: :drafted)
769
+ Post.not_active # => where.not(status: :active)
770
+ Post.not_trashed # => where.not(status: :trashed)
535
771
 
536
- * Using subselect for `delete_all` with `limit` or `offset`.
772
+ *DHH*
537
773
 
538
- *Ryuta Kamizono*
774
+ * Fix different `count` calculation when using `size` with manual `select` with DISTINCT.
539
775
 
540
- * Undefine attribute methods on descendants when resetting column
541
- information.
776
+ Fixes #35214.
542
777
 
543
- *Chris Salzberg*
778
+ *Juani Villarejo*
544
779
 
545
- * Log database query callers.
546
780
 
547
- Add `verbose_query_logs` configuration option to display the caller
548
- of database queries in the log to facilitate N+1 query resolution
549
- and other debugging.
781
+ ## Rails 6.0.0.beta3 (March 11, 2019) ##
550
782
 
551
- Enabled in development only for new and upgraded applications. Not
552
- recommended for use in the production environment since it relies
553
- on Ruby's `Kernel#caller_locations` which is fairly slow.
783
+ * No changes.
554
784
 
555
- *Olivier Lacan*
556
785
 
557
- * Fix conflicts `counter_cache` with `touch: true` by optimistic locking.
786
+ ## Rails 6.0.0.beta2 (February 25, 2019) ##
558
787
 
559
- ```
560
- # create_table :posts do |t|
561
- # t.integer :comments_count, default: 0
562
- # t.integer :lock_version
563
- # t.timestamps
564
- # end
565
- class Post < ApplicationRecord
566
- end
788
+ * Fix prepared statements caching to be enabled even when query caching is enabled.
567
789
 
568
- # create_table :comments do |t|
569
- # t.belongs_to :post
570
- # end
571
- class Comment < ApplicationRecord
572
- belongs_to :post, touch: true, counter_cache: true
573
- end
574
- ```
790
+ *Ryuta Kamizono*
575
791
 
576
- Before:
577
- ```
578
- post = Post.create!
579
- # => begin transaction
580
- INSERT INTO "posts" ("created_at", "updated_at", "lock_version")
581
- VALUES ("2017-12-11 21:27:11.387397", "2017-12-11 21:27:11.387397", 0)
582
- commit transaction
583
-
584
- comment = Comment.create!(post: post)
585
- # => begin transaction
586
- INSERT INTO "comments" ("post_id") VALUES (1)
587
-
588
- UPDATE "posts" SET "comments_count" = COALESCE("comments_count", 0) + 1,
589
- "lock_version" = COALESCE("lock_version", 0) + 1 WHERE "posts"."id" = 1
590
-
591
- UPDATE "posts" SET "updated_at" = '2017-12-11 21:27:11.398330',
592
- "lock_version" = 1 WHERE "posts"."id" = 1 AND "posts"."lock_version" = 0
593
- rollback transaction
594
- # => ActiveRecord::StaleObjectError: Attempted to touch a stale object: Post.
595
-
596
- Comment.take.destroy!
597
- # => begin transaction
598
- DELETE FROM "comments" WHERE "comments"."id" = 1
599
-
600
- UPDATE "posts" SET "comments_count" = COALESCE("comments_count", 0) - 1,
601
- "lock_version" = COALESCE("lock_version", 0) + 1 WHERE "posts"."id" = 1
602
-
603
- UPDATE "posts" SET "updated_at" = '2017-12-11 21:42:47.785901',
604
- "lock_version" = 1 WHERE "posts"."id" = 1 AND "posts"."lock_version" = 0
605
- rollback transaction
606
- # => ActiveRecord::StaleObjectError: Attempted to touch a stale object: Post.
607
- ```
792
+ * Ensure `update_all` series cares about optimistic locking.
608
793
 
609
- After:
610
- ```
611
- post = Post.create!
612
- # => begin transaction
613
- INSERT INTO "posts" ("created_at", "updated_at", "lock_version")
614
- VALUES ("2017-12-11 21:27:11.387397", "2017-12-11 21:27:11.387397", 0)
615
- commit transaction
616
-
617
- comment = Comment.create!(post: post)
618
- # => begin transaction
619
- INSERT INTO "comments" ("post_id") VALUES (1)
620
-
621
- UPDATE "posts" SET "comments_count" = COALESCE("comments_count", 0) + 1,
622
- "lock_version" = COALESCE("lock_version", 0) + 1,
623
- "updated_at" = '2017-12-11 21:37:09.802642' WHERE "posts"."id" = 1
624
- commit transaction
625
-
626
- comment.destroy!
627
- # => begin transaction
628
- DELETE FROM "comments" WHERE "comments"."id" = 1
629
-
630
- UPDATE "posts" SET "comments_count" = COALESCE("comments_count", 0) - 1,
631
- "lock_version" = COALESCE("lock_version", 0) + 1,
632
- "updated_at" = '2017-12-11 21:39:02.685520' WHERE "posts"."id" = 1
633
- commit transaction
634
- ```
794
+ *Ryuta Kamizono*
635
795
 
636
- Fixes #31199.
796
+ * Don't allow `where` with non numeric string matches to 0 values.
637
797
 
638
- *bogdanvlviv*
798
+ *Ryuta Kamizono*
639
799
 
640
- * Add support for PostgreSQL operator classes to `add_index`.
800
+ * Introduce `ActiveRecord::Relation#destroy_by` and `ActiveRecord::Relation#delete_by`.
801
+
802
+ `destroy_by` allows relation to find all the records matching the condition and perform
803
+ `destroy_all` on the matched records.
641
804
 
642
805
  Example:
643
806
 
644
- add_index :users, :name, using: :gist, opclass: { name: :gist_trgm_ops }
807
+ Person.destroy_by(name: 'David')
808
+ Person.destroy_by(name: 'David', rating: 4)
645
809
 
646
- *Greg Navis*
810
+ david = Person.find_by(name: 'David')
811
+ david.posts.destroy_by(id: [1, 2, 3])
647
812
 
648
- * Don't allow scopes to be defined which conflict with instance methods on `Relation`.
813
+ `delete_by` allows relation to find all the records matching the condition and perform
814
+ `delete_all` on the matched records.
649
815
 
650
- Fixes #31120.
816
+ Example:
817
+
818
+ Person.delete_by(name: 'David')
819
+ Person.delete_by(name: 'David', rating: 4)
820
+
821
+ david = Person.find_by(name: 'David')
822
+ david.posts.delete_by(id: [1, 2, 3])
823
+
824
+ *Abhay Nikam*
651
825
 
652
- *kinnrot*
826
+ * Don't allow `where` with invalid value matches to nil values.
653
827
 
654
- * Add new error class `QueryCanceled` which will be raised
655
- when canceling statement due to user request.
828
+ Fixes #33624.
656
829
 
657
830
  *Ryuta Kamizono*
658
831
 
659
- * Add `#up_only` to database migrations for code that is only relevant when
660
- migrating up, e.g. populating a new column.
832
+ * SQLite3: Implement `add_foreign_key` and `remove_foreign_key`.
661
833
 
662
- *Rich Daley*
834
+ *Ryuta Kamizono*
663
835
 
664
- * Require raw SQL fragments to be explicitly marked when used in
665
- relation query methods.
836
+ * Deprecate using class level querying methods if the receiver scope
837
+ regarded as leaked. Use `klass.unscoped` to avoid the leaking scope.
666
838
 
667
- Before:
668
- ```
669
- Article.order("LENGTH(title)")
670
- ```
839
+ *Ryuta Kamizono*
671
840
 
672
- After:
673
- ```
674
- Article.order(Arel.sql("LENGTH(title)"))
675
- ```
841
+ * Allow applications to automatically switch connections.
676
842
 
677
- This prevents SQL injection if applications use the [strongly
678
- discouraged] form `Article.order(params[:my_order])`, under the
679
- mistaken belief that only column names will be accepted.
843
+ Adds a middleware and configuration options that can be used in your
844
+ application to automatically switch between the writing and reading
845
+ database connections.
680
846
 
681
- Raw SQL strings will now cause a deprecation warning, which will
682
- become an UnknownAttributeReference error in Rails 6.0. Applications
683
- can opt in to the future behavior by setting `allow_unsafe_raw_sql`
684
- to `:disabled`.
847
+ `GET` and `HEAD` requests will read from the replica unless there was
848
+ a write in the last 2 seconds, otherwise they will read from the primary.
849
+ Non-get requests will always write to the primary. The middleware accepts
850
+ an argument for a Resolver class and an Operations class where you are able
851
+ to change how the auto-switcher works to be most beneficial for your
852
+ application.
853
+
854
+ To use the middleware in your application you can use the following
855
+ configuration options:
685
856
 
686
- Common and judged-safe string values (such as simple column
687
- references) are unaffected:
688
857
  ```
689
- Article.order("title DESC")
858
+ config.active_record.database_selector = { delay: 2.seconds }
859
+ config.active_record.database_resolver = ActiveRecord::Middleware::DatabaseSelector::Resolver
860
+ config.active_record.database_resolver_context = ActiveRecord::Middleware::DatabaseSelector::Resolver::Session
690
861
  ```
691
862
 
692
- *Ben Toews*
863
+ To change the database selection strategy, pass a custom class to the
864
+ configuration options:
693
865
 
694
- * `update_all` will now pass its values to `Type#cast` before passing them to
695
- `Type#serialize`. This means that `update_all(foo: 'true')` will properly
696
- persist a boolean.
866
+ ```
867
+ config.active_record.database_selector = { delay: 10.seconds }
868
+ config.active_record.database_resolver = MyResolver
869
+ config.active_record.database_resolver_context = MyResolver::MyCookies
870
+ ```
697
871
 
698
- *Sean Griffin*
872
+ *Eileen M. Uchitelle*
699
873
 
700
- * Add new error class `StatementTimeout` which will be raised
701
- when statement timeout exceeded.
874
+ * MySQL: Support `:size` option to change text and blob size.
702
875
 
703
876
  *Ryuta Kamizono*
704
877
 
705
- * Fix `bin/rails db:migrate` with specified `VERSION`.
706
- `bin/rails db:migrate` with empty VERSION behaves as without `VERSION`.
707
- Check a format of `VERSION`: Allow a migration version number
708
- or name of a migration file. Raise error if format of `VERSION` is invalid.
709
- Raise error if target migration doesn't exist.
710
-
711
- *bogdanvlviv*
878
+ * Make `t.timestamps` with precision by default.
712
879
 
713
- * Fixed a bug where column orders for an index weren't written to
714
- `db/schema.rb` when using the sqlite adapter.
880
+ *Ryuta Kamizono*
715
881
 
716
- Fixes #30902.
717
882
 
718
- *Paul Kuruvilla*
883
+ ## Rails 6.0.0.beta1 (January 18, 2019) ##
719
884
 
720
- * Remove deprecated method `#sanitize_conditions`.
885
+ * Remove deprecated `#set_state` from the transaction object.
721
886
 
722
887
  *Rafael Mendonça França*
723
888
 
724
- * Remove deprecated method `#scope_chain`.
889
+ * Remove deprecated `#supports_statement_cache?` from the database adapters.
725
890
 
726
891
  *Rafael Mendonça França*
727
892
 
728
- * Remove deprecated configuration `.error_on_ignored_order_or_limit`.
893
+ * Remove deprecated `#insert_fixtures` from the database adapters.
729
894
 
730
895
  *Rafael Mendonça França*
731
896
 
732
- * Remove deprecated arguments from `#verify!`.
897
+ * Remove deprecated `ActiveRecord::ConnectionAdapters::SQLite3Adapter#valid_alter_table_type?`.
733
898
 
734
899
  *Rafael Mendonça França*
735
900
 
736
- * Remove deprecated argument `name` from `#indexes`.
901
+ * Do not allow passing the column name to `sum` when a block is passed.
737
902
 
738
903
  *Rafael Mendonça França*
739
904
 
740
- * Remove deprecated method `ActiveRecord::Migrator.schema_migrations_table_name`.
905
+ * Do not allow passing the column name to `count` when a block is passed.
741
906
 
742
907
  *Rafael Mendonça França*
743
908
 
744
- * Remove deprecated method `supports_primary_key?`.
909
+ * Remove delegation of missing methods in a relation to arel.
745
910
 
746
911
  *Rafael Mendonça França*
747
912
 
748
- * Remove deprecated method `supports_migrations?`.
913
+ * Remove delegation of missing methods in a relation to private methods of the class.
749
914
 
750
915
  *Rafael Mendonça França*
751
916
 
752
- * Remove deprecated methods `initialize_schema_migrations_table` and `initialize_internal_metadata_table`.
917
+ * Deprecate `config.active_record.sqlite3.represent_boolean_as_integer`.
753
918
 
754
919
  *Rafael Mendonça França*
755
920
 
756
- * Raises when calling `lock!` in a dirty record.
921
+ * Change `SQLite3Adapter` to always represent boolean values as integers.
757
922
 
758
923
  *Rafael Mendonça França*
759
924
 
760
- * Remove deprecated support to passing a class to `:class_name` on associations.
925
+ * Remove ability to specify a timestamp name for `#cache_key`.
761
926
 
762
927
  *Rafael Mendonça França*
763
928
 
764
- * Remove deprecated argument `default` from `index_name_exists?`.
929
+ * Remove deprecated `ActiveRecord::Migrator.migrations_path=`.
765
930
 
766
931
  *Rafael Mendonça França*
767
932
 
768
- * Remove deprecated support to `quoted_id` when typecasting an Active Record object.
933
+ * Remove deprecated `expand_hash_conditions_for_aggregates`.
769
934
 
770
935
  *Rafael Mendonça França*
771
936
 
772
- * Fix `bin/rails db:setup` and `bin/rails db:test:prepare` create wrong
773
- ar_internal_metadata's data for a test database.
937
+ * Set polymorphic type column to NULL on `dependent: :nullify` strategy.
774
938
 
775
- Before:
776
- ```
777
- $ RAILS_ENV=test rails dbconsole
778
- > SELECT * FROM ar_internal_metadata;
779
- key|value|created_at|updated_at
780
- environment|development|2017-09-11 23:14:10.815679|2017-09-11 23:14:10.815679
781
- ```
939
+ On polymorphic associations both the foreign key and the foreign type columns will be set to NULL.
782
940
 
783
- After:
784
- ```
785
- $ RAILS_ENV=test rails dbconsole
786
- > SELECT * FROM ar_internal_metadata;
787
- key|value|created_at|updated_at
788
- environment|test|2017-09-11 23:14:10.815679|2017-09-11 23:14:10.815679
789
- ```
941
+ *Laerti Papa*
790
942
 
791
- Fixes #26731.
943
+ * Allow permitted instance of `ActionController::Parameters` as argument of `ActiveRecord::Relation#exists?`.
792
944
 
793
- *bogdanvlviv*
945
+ *Gannon McGibbon*
794
946
 
795
- * Fix longer sequence name detection for serial columns.
947
+ * Add support for endless ranges introduces in Ruby 2.6.
948
+
949
+ *Greg Navis*
796
950
 
797
- Fixes #28332.
951
+ * Deprecate passing `migrations_paths` to `connection.assume_migrated_upto_version`.
798
952
 
799
953
  *Ryuta Kamizono*
800
954
 
801
- * MySQL: Don't lose `auto_increment: true` in the `db/schema.rb`.
955
+ * MySQL: `ROW_FORMAT=DYNAMIC` create table option by default.
802
956
 
803
- Fixes #30894.
957
+ Since MySQL 5.7.9, the `innodb_default_row_format` option defines the default row
958
+ format for InnoDB tables. The default setting is `DYNAMIC`.
959
+ The row format is required for indexing on `varchar(255)` with `utf8mb4` columns.
804
960
 
805
961
  *Ryuta Kamizono*
806
962
 
807
- * Fix `COUNT(DISTINCT ...)` for `GROUP BY` with `ORDER BY` and `LIMIT`.
963
+ * Fix join table column quoting with SQLite.
964
+
965
+ *Gannon McGibbon*
966
+
967
+ * Allow disabling scopes generated by `ActiveRecord.enum`.
808
968
 
809
- Fixes #30886.
969
+ *Alfred Dominic*
970
+
971
+ * Ensure that `delete_all` on collection proxy returns affected count.
810
972
 
811
973
  *Ryuta Kamizono*
812
974
 
813
- * PostgreSQL `tsrange` now preserves subsecond precision.
975
+ * Reset scope after delete on collection association to clear stale offsets of removed records.
814
976
 
815
- PostgreSQL 9.1+ introduced range types, and Rails added support for using
816
- this datatype in Active Record. However, the serialization of
817
- `PostgreSQL::OID::Range` was incomplete, because it did not properly
818
- cast the bounds that make up the range. This led to subseconds being
819
- dropped in SQL commands:
977
+ *Gannon McGibbon*
820
978
 
821
- Before:
979
+ * Add the ability to prevent writes to a database for the duration of a block.
822
980
 
823
- connection.type_cast(tsrange.serialize(range_value))
824
- # => "[2010-01-01 13:30:00 UTC,2011-02-02 19:30:00 UTC)"
981
+ Allows the application to prevent writes to a database. This can be useful when
982
+ you're building out multiple databases and want to make sure you're not sending
983
+ writes when you want a read.
825
984
 
826
- Now:
985
+ If `while_preventing_writes` is called and the query is considered a write
986
+ query the database will raise an exception regardless of whether the database
987
+ user is able to write.
827
988
 
828
- connection.type_cast(tsrange.serialize(range_value))
829
- # => "[2010-01-01 13:30:00.670277,2011-02-02 19:30:00.745125)"
989
+ This is not meant to be a catch-all for write queries but rather a way to enforce
990
+ read-only queries without opening a second connection. One purpose of this is to
991
+ catch accidental writes, not all writes.
830
992
 
831
- *Thomas Cannon*
993
+ *Eileen M. Uchitelle*
832
994
 
833
- * Passing a `Set` to `Relation#where` now behaves the same as passing an
834
- array.
995
+ * Allow aliased attributes to be used in `#update_columns` and `#update`.
835
996
 
836
- *Sean Griffin*
997
+ *Gannon McGibbon*
837
998
 
838
- * Use given algorithm while removing index from database.
999
+ * Allow spaces in postgres table names.
839
1000
 
840
- Fixes #24190.
1001
+ Fixes issue where "user post" is misinterpreted as "\"user\".\"post\"" when quoting table names with the postgres adapter.
841
1002
 
842
- *Mehmet Emin İNAÇ*
1003
+ *Gannon McGibbon*
843
1004
 
844
- * Update payload names for `sql.active_record` instrumentation to be
845
- more descriptive.
1005
+ * Cached `columns_hash` fields should be excluded from `ResultSet#column_types`.
846
1006
 
847
- Fixes #30586.
1007
+ PR #34528 addresses the inconsistent behaviour when attribute is defined for an ignored column. The following test
1008
+ was passing for SQLite and MySQL, but failed for PostgreSQL:
848
1009
 
849
- *Jeremy Green*
1010
+ ```ruby
1011
+ class DeveloperName < ActiveRecord::Type::String
1012
+ def deserialize(value)
1013
+ "Developer: #{value}"
1014
+ end
1015
+ end
850
1016
 
851
- * Add new error class `LockWaitTimeout` which will be raised
852
- when lock wait timeout exceeded.
1017
+ class AttributedDeveloper < ActiveRecord::Base
1018
+ self.table_name = "developers"
853
1019
 
854
- *Gabriel Courtemanche*
1020
+ attribute :name, DeveloperName.new
855
1021
 
856
- * Remove deprecated `#migration_keys`.
1022
+ self.ignored_columns += ["name"]
1023
+ end
857
1024
 
858
- *Ryuta Kamizono*
1025
+ developer = AttributedDeveloper.create
1026
+ developer.update_column :name, "name"
859
1027
 
860
- * Automatically guess the inverse associations for STI.
1028
+ loaded_developer = AttributedDeveloper.where(id: developer.id).select("*").first
1029
+ puts loaded_developer.name # should be "Developer: name" but it's just "name"
1030
+ ```
861
1031
 
862
- *Yuichiro Kaneko*
1032
+ *Dmitry Tsepelev*
863
1033
 
864
- * Ensure `sum` honors `distinct` on `has_many :through` associations.
1034
+ * Make the implicit order column configurable.
865
1035
 
866
- Fixes #16791.
1036
+ When calling ordered finder methods such as `first` or `last` without an
1037
+ explicit order clause, ActiveRecord sorts records by primary key. This can
1038
+ result in unpredictable and surprising behaviour when the primary key is
1039
+ not an auto-incrementing integer, for example when it's a UUID. This change
1040
+ makes it possible to override the column used for implicit ordering such
1041
+ that `first` and `last` will return more predictable results.
867
1042
 
868
- *Aaron Wortham*
1043
+ Example:
869
1044
 
870
- * Add `binary` fixture helper method.
1045
+ class Project < ActiveRecord::Base
1046
+ self.implicit_order_column = "created_at"
1047
+ end
871
1048
 
872
- *Atsushi Yoshida*
1049
+ *Tekin Suleyman*
873
1050
 
874
- * When using `Relation#or`, extract the common conditions and put them before the OR condition.
1051
+ * Bump minimum PostgreSQL version to 9.3.
875
1052
 
876
- *Maxime Handfield Lapointe*
1053
+ *Yasuo Honda*
877
1054
 
878
- * `Relation#or` now accepts two relations who have different values for
879
- `references` only, as `references` can be implicitly called by `where`.
1055
+ * Values of enum are frozen, raising an error when attempting to modify them.
880
1056
 
881
- Fixes #29411.
1057
+ *Emmanuel Byrd*
1058
+
1059
+ * Move `ActiveRecord::StatementInvalid` SQL to error property and include binds as separate error property.
1060
+
1061
+ `ActiveRecord::ConnectionAdapters::AbstractAdapter#translate_exception_class` now requires `binds` to be passed as the last argument.
1062
+
1063
+ `ActiveRecord::ConnectionAdapters::AbstractAdapter#translate_exception` now requires `message`, `sql`, and `binds` to be passed as keyword arguments.
1064
+
1065
+ Subclasses of `ActiveRecord::StatementInvalid` must now provide `sql:` and `binds:` arguments to `super`.
1066
+
1067
+ Example:
1068
+
1069
+ ```
1070
+ class MySubclassedError < ActiveRecord::StatementInvalid
1071
+ def initialize(message, sql:, binds:)
1072
+ super(message, sql: sql, binds: binds)
1073
+ end
1074
+ end
1075
+ ```
1076
+
1077
+ *Gannon McGibbon*
1078
+
1079
+ * Add an `:if_not_exists` option to `create_table`.
1080
+
1081
+ Example:
1082
+
1083
+ create_table :posts, if_not_exists: true do |t|
1084
+ t.string :title
1085
+ end
1086
+
1087
+ That would execute:
1088
+
1089
+ CREATE TABLE IF NOT EXISTS posts (
1090
+ ...
1091
+ )
1092
+
1093
+ If the table already exists, `if_not_exists: false` (the default) raises an
1094
+ exception whereas `if_not_exists: true` does nothing.
1095
+
1096
+ *fatkodima*, *Stefan Kanev*
1097
+
1098
+ * Defining an Enum as a Hash with blank key, or as an Array with a blank value, now raises an `ArgumentError`.
1099
+
1100
+ *Christophe Maximin*
1101
+
1102
+ * Adds support for multiple databases to `rails db:schema:cache:dump` and `rails db:schema:cache:clear`.
1103
+
1104
+ *Gannon McGibbon*
1105
+
1106
+ * `update_columns` now correctly raises `ActiveModel::MissingAttributeError`
1107
+ if the attribute does not exist.
882
1108
 
883
1109
  *Sean Griffin*
884
1110
 
885
- * `ApplicationRecord` is no longer generated when generating models. If you
886
- need to generate it, it can be created with `rails g application_record`.
1111
+ * Add support for hash and URL configs in database hash of `ActiveRecord::Base.connected_to`.
1112
+
1113
+ ````
1114
+ User.connected_to(database: { writing: "postgres://foo" }) do
1115
+ User.create!(name: "Gannon")
1116
+ end
1117
+
1118
+ config = { "adapter" => "sqlite3", "database" => "db/readonly.sqlite3" }
1119
+ User.connected_to(database: { reading: config }) do
1120
+ User.count
1121
+ end
1122
+ ````
1123
+
1124
+ *Gannon McGibbon*
1125
+
1126
+ * Support default expression for MySQL.
1127
+
1128
+ MySQL 8.0.13 and higher supports default value to be a function or expression.
1129
+
1130
+ https://dev.mysql.com/doc/refman/8.0/en/create-table.html
887
1131
 
888
- *Lisa Ugray*
1132
+ *Ryuta Kamizono*
1133
+
1134
+ * Support expression indexes for MySQL.
889
1135
 
890
- * Fix `COUNT(DISTINCT ...)` with `ORDER BY` and `LIMIT` to keep the existing select list.
1136
+ MySQL 8.0.13 and higher supports functional key parts that index
1137
+ expression values rather than column or column prefix values.
1138
+
1139
+ https://dev.mysql.com/doc/refman/8.0/en/create-index.html
891
1140
 
892
1141
  *Ryuta Kamizono*
893
1142
 
894
- * When a `has_one` association is destroyed by `dependent: destroy`,
895
- `destroyed_by_association` will now be set to the reflection, matching the
896
- behaviour of `has_many` associations.
1143
+ * Fix collection cache key with limit and custom select to avoid ambiguous timestamp column error.
1144
+
1145
+ Fixes #33056.
897
1146
 
898
- *Lisa Ugray*
1147
+ *Federico Martinez*
899
1148
 
900
- * Fix `unscoped(where: [columns])` removing the wrong bind values.
1149
+ * Add basic API for connection switching to support multiple databases.
901
1150
 
902
- When the `where` is called on a relation after a `or`, unscoping the column of that later `where` removed
903
- bind values used by the `or` instead. (possibly other cases too)
1151
+ 1) Adds a `connects_to` method for models to connect to multiple databases. Example:
904
1152
 
905
1153
  ```
906
- Post.where(id: 1).or(Post.where(id: 2)).where(foo: 3).unscope(where: :foo).to_sql
907
- # Currently:
908
- # SELECT "posts".* FROM "posts" WHERE ("posts"."id" = 2 OR "posts"."id" = 3)
909
- # With fix:
910
- # SELECT "posts".* FROM "posts" WHERE ("posts"."id" = 1 OR "posts"."id" = 2)
1154
+ class AnimalsModel < ApplicationRecord
1155
+ self.abstract_class = true
1156
+
1157
+ connects_to database: { writing: :animals_primary, reading: :animals_replica }
1158
+ end
1159
+
1160
+ class Dog < AnimalsModel
1161
+ # connected to both the animals_primary db for writing and the animals_replica for reading
1162
+ end
911
1163
  ```
912
1164
 
913
- *Maxime Handfield Lapointe*
1165
+ 2) Adds a `connected_to` block method for switching connection roles or connecting to
1166
+ a database that the model didn't connect to. Connecting to the database in this block is
1167
+ useful when you have another defined connection, for example `slow_replica` that you don't
1168
+ want to connect to by default but need in the console, or a specific code block.
914
1169
 
915
- * Values constructed using multi-parameter assignment will now use the
916
- post-type-cast value for rendering in single-field form inputs.
1170
+ ```
1171
+ ActiveRecord::Base.connected_to(role: :reading) do
1172
+ Dog.first # finds dog from replica connected to AnimalsBase
1173
+ Book.first # doesn't have a reading connection, will raise an error
1174
+ end
1175
+ ```
917
1176
 
918
- *Sean Griffin*
1177
+ ```
1178
+ ActiveRecord::Base.connected_to(database: :slow_replica) do
1179
+ SlowReplicaModel.first # if the db config has a slow_replica configuration this will be used to do the lookup, otherwise this will throw an exception
1180
+ end
1181
+ ```
919
1182
 
920
- * `Relation#joins` is no longer affected by the target model's
921
- `current_scope`, with the exception of `unscoped`.
1183
+ *Eileen M. Uchitelle*
922
1184
 
923
- Fixes #29338.
1185
+ * Enum raises on invalid definition values
924
1186
 
925
- *Sean Griffin*
1187
+ When defining a Hash enum it can be easy to use `[]` instead of `{}`. This
1188
+ commit checks that only valid definition values are provided, those can
1189
+ be a Hash, an array of Symbols or an array of Strings. Otherwise it
1190
+ raises an `ArgumentError`.
926
1191
 
927
- * Change sqlite3 boolean serialization to use 1 and 0.
1192
+ Fixes #33961
928
1193
 
929
- SQLite natively recognizes 1 and 0 as true and false, but does not natively
930
- recognize 't' and 'f' as was previously serialized.
1194
+ *Alberto Almagro*
931
1195
 
932
- This change in serialization requires a migration of stored boolean data
933
- for SQLite databases, so it's implemented behind a configuration flag
934
- whose default false value is deprecated.
1196
+ * Reloading associations now clears the Query Cache like `Persistence#reload` does.
935
1197
 
936
- *Lisa Ugray*
1198
+ ```
1199
+ class Post < ActiveRecord::Base
1200
+ has_one :category
1201
+ belongs_to :author
1202
+ has_many :comments
1203
+ end
937
1204
 
938
- * Skip query caching when working with batches of records (`find_each`, `find_in_batches`,
939
- `in_batches`).
1205
+ # Each of the following will now clear the query cache.
1206
+ post.reload_category
1207
+ post.reload_author
1208
+ post.comments.reload
1209
+ ```
940
1210
 
941
- Previously, records would be fetched in batches, but all records would be retained in memory
942
- until the end of the request or job.
1211
+ *Christophe Maximin*
943
1212
 
944
- *Eugene Kenny*
1213
+ * Added `index` option for `change_table` migration helpers.
1214
+ With this change you can create indexes while adding new
1215
+ columns into the existing tables.
945
1216
 
946
- * Prevent errors raised by `sql.active_record` notification subscribers from being converted into
947
- `ActiveRecord::StatementInvalid` exceptions.
1217
+ Example:
1218
+
1219
+ change_table(:languages) do |t|
1220
+ t.string :country_code, index: true
1221
+ end
1222
+
1223
+ *Mehmet Emin İNAÇ*
1224
+
1225
+ * Fix `transaction` reverting for migrations.
1226
+
1227
+ Before: Commands inside a `transaction` in a reverted migration ran uninverted.
1228
+ Now: This change fixes that by reverting commands inside `transaction` block.
1229
+
1230
+ *fatkodima*, *David Verhasselt*
948
1231
 
949
- *Dennis Taylor*
1232
+ * Raise an error instead of scanning the filesystem root when `fixture_path` is blank.
950
1233
 
951
- * Fix eager loading/preloading association with scope including joins.
1234
+ *Gannon McGibbon*, *Max Albrecht*
952
1235
 
953
- Fixes #28324.
1236
+ * Allow `ActiveRecord::Base.configurations=` to be set with a symbolized hash.
1237
+
1238
+ *Gannon McGibbon*
1239
+
1240
+ * Don't update counter cache unless the record is actually saved.
1241
+
1242
+ Fixes #31493, #33113, #33117.
954
1243
 
955
1244
  *Ryuta Kamizono*
956
1245
 
957
- * Fix transactions to apply state to child transactions.
1246
+ * Deprecate `ActiveRecord::Result#to_hash` in favor of `ActiveRecord::Result#to_a`.
958
1247
 
959
- Previously, if you had a nested transaction and the outer transaction was rolledback, the record from the
960
- inner transaction would still be marked as persisted.
1248
+ *Gannon McGibbon*, *Kevin Cheng*
961
1249
 
962
- This change fixes that by applying the state of the parent transaction to the child transaction when the
963
- parent transaction is rolledback. This will correctly mark records from the inner transaction as not persisted.
1250
+ * SQLite3 adapter supports expression indexes.
964
1251
 
965
- *Eileen M. Uchitelle*, *Aaron Patterson*
1252
+ ```
1253
+ create_table :users do |t|
1254
+ t.string :email
1255
+ end
966
1256
 
967
- * Deprecate `set_state` method in `TransactionState`.
1257
+ add_index :users, 'lower(email)', name: 'index_users_on_email', unique: true
1258
+ ```
968
1259
 
969
- Deprecated the `set_state` method in favor of setting the state via specific methods. If you need to mark the
970
- state of the transaction you can now use `rollback!`, `commit!` or `nullify!` instead of
971
- `set_state(:rolledback)`, `set_state(:committed)`, or `set_state(nil)`.
1260
+ *Gray Kemmey*
972
1261
 
973
- *Eileen M. Uchitelle*, *Aaron Patterson*
1262
+ * Allow subclasses to redefine autosave callbacks for associated records.
1263
+
1264
+ Fixes #33305.
1265
+
1266
+ *Andrey Subbota*
1267
+
1268
+ * Bump minimum MySQL version to 5.5.8.
1269
+
1270
+ *Yasuo Honda*
1271
+
1272
+ * Use MySQL utf8mb4 character set by default.
1273
+
1274
+ `utf8mb4` character set with 4-Byte encoding supports supplementary characters including emoji.
1275
+ The previous default 3-Byte encoding character set `utf8` is not enough to support them.
1276
+
1277
+ *Yasuo Honda*
1278
+
1279
+ * Fix duplicated record creation when using nested attributes with `create_with`.
1280
+
1281
+ *Darwin Wu*
1282
+
1283
+ * Configuration item `config.filter_parameters` could also filter out
1284
+ sensitive values of database columns when calling `#inspect`.
1285
+ We also added `ActiveRecord::Base::filter_attributes`/`=` in order to
1286
+ specify sensitive attributes to specific model.
1287
+
1288
+ ```
1289
+ Rails.application.config.filter_parameters += [:credit_card_number, /phone/]
1290
+ Account.last.inspect # => #<Account id: 123, name: "DHH", credit_card_number: [FILTERED], telephone_number: [FILTERED] ...>
1291
+ SecureAccount.filter_attributes += [:name]
1292
+ SecureAccount.last.inspect # => #<SecureAccount id: 42, name: [FILTERED], credit_card_number: [FILTERED] ...>
1293
+ ```
1294
+
1295
+ *Zhang Kang*, *Yoshiyuki Kinjo*
974
1296
 
975
- * Deprecate delegating to `arel` in `Relation`.
1297
+ * Deprecate `column_name_length`, `table_name_length`, `columns_per_table`,
1298
+ `indexes_per_table`, `columns_per_multicolumn_index`, `sql_query_length`,
1299
+ and `joins_per_query` methods in `DatabaseLimits`.
976
1300
 
977
1301
  *Ryuta Kamizono*
978
1302
 
979
- * Query cache was unavailable when entering the `ActiveRecord::Base.cache` block
980
- without being connected.
1303
+ * `ActiveRecord::Base.configurations` now returns an object.
981
1304
 
982
- *Tsukasa Oishi*
1305
+ `ActiveRecord::Base.configurations` used to return a hash, but this
1306
+ is an inflexible data model. In order to improve multiple-database
1307
+ handling in Rails, we've changed this to return an object. Some methods
1308
+ are provided to make the object behave hash-like in order to ease the
1309
+ transition process. Since most applications don't manipulate the hash
1310
+ we've decided to add backwards-compatible functionality that will throw
1311
+ a deprecation warning if used, however calling `ActiveRecord::Base.configurations`
1312
+ will use the new version internally and externally.
983
1313
 
984
- * Previously, when building records using a `has_many :through` association,
985
- if the child records were deleted before the parent was saved, they would
986
- still be persisted. Now, if child records are deleted before the parent is saved
987
- on a `has_many :through` association, the child records will not be persisted.
1314
+ For example, the following `database.yml`:
1315
+
1316
+ ```
1317
+ development:
1318
+ adapter: sqlite3
1319
+ database: db/development.sqlite3
1320
+ ```
988
1321
 
989
- *Tobias Kraze*
1322
+ Used to become a hash:
990
1323
 
991
- * Merging two relations representing nested joins no longer transforms the joins of
992
- the merged relation into LEFT OUTER JOIN.
1324
+ ```
1325
+ { "development" => { "adapter" => "sqlite3", "database" => "db/development.sqlite3" } }
1326
+ ```
993
1327
 
994
- Example:
1328
+ Is now converted into the following object:
995
1329
 
996
1330
  ```
997
- Author.joins(:posts).merge(Post.joins(:comments))
998
- # Before the change:
999
- #=> SELECT ... FROM authors INNER JOIN posts ON ... LEFT OUTER JOIN comments ON...
1331
+ #<ActiveRecord::DatabaseConfigurations:0x00007fd1acbdf800 @configurations=[
1332
+ #<ActiveRecord::DatabaseConfigurations::HashConfig:0x00007fd1acbded10 @env_name="development",
1333
+ @spec_name="primary", @config={"adapter"=>"sqlite3", "database"=>"db/development.sqlite3"}>
1334
+ ]
1335
+ ```
1336
+
1337
+ Iterating over the database configurations has also changed. Instead of
1338
+ calling hash methods on the `configurations` hash directly, a new method `configs_for` has
1339
+ been provided that allows you to select the correct configuration. `env_name` and
1340
+ `spec_name` arguments are optional. For example, these return an array of
1341
+ database config objects for the requested environment and a single database config object
1342
+ will be returned for the requested environment and specification name respectively.
1000
1343
 
1001
- # After the change:
1002
- #=> SELECT ... FROM authors INNER JOIN posts ON ... INNER JOIN comments ON...
1344
+ ```
1345
+ ActiveRecord::Base.configurations.configs_for(env_name: "development")
1346
+ ActiveRecord::Base.configurations.configs_for(env_name: "development", spec_name: "primary")
1003
1347
  ```
1004
1348
 
1005
- *Maxime Handfield Lapointe*
1349
+ *Eileen M. Uchitelle*, *Aaron Patterson*
1006
1350
 
1007
- * `ActiveRecord::Persistence#touch` does not work well when optimistic locking enabled and
1008
- `locking_column`, without default value, is null in the database.
1351
+ * Add database configuration to disable advisory locks.
1009
1352
 
1010
- *bogdanvlviv*
1353
+ ```
1354
+ production:
1355
+ adapter: postgresql
1356
+ advisory_locks: false
1357
+ ```
1011
1358
 
1012
- * Fix destroying existing object does not work well when optimistic locking enabled and
1013
- `locking_column` is null in the database.
1359
+ *Guo Xiang*
1014
1360
 
1015
- *bogdanvlviv*
1361
+ * SQLite3 adapter `alter_table` method restores foreign keys.
1016
1362
 
1017
- * Use bulk INSERT to insert fixtures for better performance.
1363
+ *Yasuo Honda*
1018
1364
 
1019
- *Kir Shatrov*
1365
+ * Allow `:to_table` option to `invert_remove_foreign_key`.
1366
+
1367
+ Example:
1020
1368
 
1021
- * Prevent creation of bind param if casted value is nil.
1369
+ remove_foreign_key :accounts, to_table: :owners
1022
1370
 
1023
- *Ryuta Kamizono*
1371
+ *Nikolay Epifanov*, *Rich Chen*
1372
+
1373
+ * Add environment & load_config dependency to `bin/rake db:seed` to enable
1374
+ seed load in environments without Rails and custom DB configuration
1375
+
1376
+ *Tobias Bielohlawek*
1377
+
1378
+ * Fix default value for mysql time types with specified precision.
1379
+
1380
+ *Nikolay Kondratyev*
1024
1381
 
1025
- * Deprecate passing arguments and block at the same time to `count` and `sum` in `ActiveRecord::Calculations`.
1382
+ * Fix `touch` option to behave consistently with `Persistence#touch` method.
1026
1383
 
1027
1384
  *Ryuta Kamizono*
1028
1385
 
1029
- * Loading model schema from database is now thread-safe.
1386
+ * Migrations raise when duplicate column definition.
1030
1387
 
1031
- Fixes #28589.
1388
+ Fixes #33024.
1032
1389
 
1033
- *Vikrant Chaudhary*, *David Abdemoulaie*
1390
+ *Federico Martinez*
1034
1391
 
1035
- * Add `ActiveRecord::Base#cache_version` to support recyclable cache keys via the new versioned entries
1036
- in `ActiveSupport::Cache`. This also means that `ActiveRecord::Base#cache_key` will now return a stable key
1037
- that does not include a timestamp any more.
1392
+ * Bump minimum SQLite version to 3.8
1038
1393
 
1039
- NOTE: This feature is turned off by default, and `#cache_key` will still return cache keys with timestamps
1040
- until you set `ActiveRecord::Base.cache_versioning = true`. That's the setting for all new apps on Rails 5.2+
1394
+ *Yasuo Honda*
1041
1395
 
1042
- *DHH*
1396
+ * Fix parent record should not get saved with duplicate children records.
1043
1397
 
1044
- * Respect `SchemaDumper.ignore_tables` in rake tasks for databases structure dump.
1398
+ Fixes #32940.
1045
1399
 
1046
- *Rusty Geldmacher*, *Guillermo Iguaran*
1400
+ *Santosh Wadghule*
1047
1401
 
1048
- * Add type caster to `RuntimeReflection#alias_name`.
1402
+ * Fix logic on disabling commit callbacks so they are not called unexpectedly when errors occur.
1049
1403
 
1050
- Fixes #28959.
1404
+ *Brian Durand*
1051
1405
 
1052
- *Jon Moss*
1406
+ * Ensure `Associations::CollectionAssociation#size` and `Associations::CollectionAssociation#empty?`
1407
+ use loaded association ids if present.
1053
1408
 
1054
- * Deprecate `supports_statement_cache?`.
1409
+ *Graham Turner*
1055
1410
 
1056
- *Ryuta Kamizono*
1411
+ * Add support to preload associations of polymorphic associations when not all the records have the requested associations.
1057
1412
 
1058
- * Raise error `UnknownMigrationVersionError` on the movement of migrations
1059
- when the current migration does not exist.
1413
+ *Dana Sherson*
1060
1414
 
1061
- *bogdanvlviv*
1415
+ * Add `touch_all` method to `ActiveRecord::Relation`.
1416
+
1417
+ Example:
1062
1418
 
1063
- * Fix `bin/rails db:forward` first migration.
1419
+ Person.where(name: "David").touch_all(time: Time.new(2020, 5, 16, 0, 0, 0))
1064
1420
 
1065
- *bogdanvlviv*
1421
+ *fatkodima*, *duggiefresh*
1066
1422
 
1067
- * Support Descending Indexes for MySQL.
1423
+ * Add `ActiveRecord::Base.base_class?` predicate.
1068
1424
 
1069
- MySQL 8.0.1 and higher supports descending indexes: `DESC` in an index definition is no longer ignored.
1070
- See https://dev.mysql.com/doc/refman/8.0/en/descending-indexes.html.
1425
+ *Bogdan Gusiev*
1071
1426
 
1072
- *Ryuta Kamizono*
1427
+ * Add custom prefix/suffix options to `ActiveRecord::Store.store_accessor`.
1073
1428
 
1074
- * Fix inconsistency with changed attributes when overriding Active Record attribute reader.
1429
+ *Tan Huynh*, *Yukio Mizuta*
1075
1430
 
1076
- *bogdanvlviv*
1431
+ * Rails 6 requires Ruby 2.5.0 or newer.
1077
1432
 
1078
- * When calling the dynamic fixture accessor method with no arguments, it now returns all fixtures of this type.
1079
- Previously this method always returned an empty array.
1433
+ *Jeremy Daer*, *Kasper Timm Hansen*
1080
1434
 
1081
- *Kevin McPhillips*
1435
+ * Deprecate `update_attributes`/`!` in favor of `update`/`!`.
1436
+
1437
+ *Eddie Lebow*
1438
+
1439
+ * Add `ActiveRecord::Base.create_or_find_by`/`!` to deal with the SELECT/INSERT race condition in
1440
+ `ActiveRecord::Base.find_or_create_by`/`!` by leaning on unique constraints in the database.
1441
+
1442
+ *DHH*
1443
+
1444
+ * Add `Relation#pick` as short-hand for single-value plucks.
1445
+
1446
+ *DHH*
1082
1447
 
1083
1448
 
1084
- Please check [5-1-stable](https://github.com/rails/rails/blob/5-1-stable/activerecord/CHANGELOG.md) for previous changes.
1449
+ Please check [5-2-stable](https://github.com/rails/rails/blob/5-2-stable/activerecord/CHANGELOG.md) for previous changes.