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