activerecord 5.2.4.4 → 6.0.3.4

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