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