activerecord 5.2.5 → 6.0.0.beta1

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