activerecord 5.2.4.3 → 6.0.2.2

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

Potentially problematic release.


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

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