activerecord 4.2.9 → 6.1.4.1

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

Potentially problematic release.


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

Files changed (374) hide show
  1. checksums.yaml +5 -5
  2. data/CHANGELOG.md +964 -1382
  3. data/MIT-LICENSE +4 -2
  4. data/README.rdoc +15 -14
  5. data/examples/performance.rb +33 -32
  6. data/examples/simple.rb +5 -4
  7. data/lib/active_record/aggregations.rb +266 -251
  8. data/lib/active_record/association_relation.rb +40 -15
  9. data/lib/active_record/associations/alias_tracker.rb +40 -43
  10. data/lib/active_record/associations/association.rb +162 -69
  11. data/lib/active_record/associations/association_scope.rb +105 -130
  12. data/lib/active_record/associations/belongs_to_association.rb +83 -65
  13. data/lib/active_record/associations/belongs_to_polymorphic_association.rb +13 -12
  14. data/lib/active_record/associations/builder/association.rb +57 -43
  15. data/lib/active_record/associations/builder/belongs_to.rb +74 -57
  16. data/lib/active_record/associations/builder/collection_association.rb +15 -37
  17. data/lib/active_record/associations/builder/has_and_belongs_to_many.rb +49 -66
  18. data/lib/active_record/associations/builder/has_many.rb +13 -5
  19. data/lib/active_record/associations/builder/has_one.rb +44 -6
  20. data/lib/active_record/associations/builder/singular_association.rb +16 -10
  21. data/lib/active_record/associations/collection_association.rb +148 -287
  22. data/lib/active_record/associations/collection_proxy.rb +252 -150
  23. data/lib/active_record/associations/foreign_association.rb +23 -1
  24. data/lib/active_record/associations/has_many_association.rb +56 -98
  25. data/lib/active_record/associations/has_many_through_association.rb +68 -89
  26. data/lib/active_record/associations/has_one_association.rb +73 -47
  27. data/lib/active_record/associations/has_one_through_association.rb +20 -11
  28. data/lib/active_record/associations/join_dependency/join_association.rb +54 -81
  29. data/lib/active_record/associations/join_dependency/join_base.rb +10 -9
  30. data/lib/active_record/associations/join_dependency/join_part.rb +14 -14
  31. data/lib/active_record/associations/join_dependency.rb +174 -169
  32. data/lib/active_record/associations/preloader/association.rb +108 -115
  33. data/lib/active_record/associations/preloader/through_association.rb +85 -65
  34. data/lib/active_record/associations/preloader.rb +97 -94
  35. data/lib/active_record/associations/singular_association.rb +18 -39
  36. data/lib/active_record/associations/through_association.rb +39 -19
  37. data/lib/active_record/associations.rb +1845 -1598
  38. data/lib/active_record/attribute_assignment.rb +59 -185
  39. data/lib/active_record/attribute_methods/before_type_cast.rb +18 -10
  40. data/lib/active_record/attribute_methods/dirty.rb +168 -148
  41. data/lib/active_record/attribute_methods/primary_key.rb +93 -83
  42. data/lib/active_record/attribute_methods/query.rb +8 -10
  43. data/lib/active_record/attribute_methods/read.rb +19 -79
  44. data/lib/active_record/attribute_methods/serialization.rb +49 -24
  45. data/lib/active_record/attribute_methods/time_zone_conversion.rb +55 -36
  46. data/lib/active_record/attribute_methods/write.rb +24 -55
  47. data/lib/active_record/attribute_methods.rb +149 -154
  48. data/lib/active_record/attributes.rb +234 -78
  49. data/lib/active_record/autosave_association.rb +133 -60
  50. data/lib/active_record/base.rb +46 -46
  51. data/lib/active_record/callbacks.rb +234 -79
  52. data/lib/active_record/coders/json.rb +3 -1
  53. data/lib/active_record/coders/yaml_column.rb +34 -13
  54. data/lib/active_record/connection_adapters/abstract/connection_pool.rb +887 -323
  55. data/lib/active_record/connection_adapters/abstract/database_limits.rb +17 -41
  56. data/lib/active_record/connection_adapters/abstract/database_statements.rb +292 -124
  57. data/lib/active_record/connection_adapters/abstract/query_cache.rb +78 -24
  58. data/lib/active_record/connection_adapters/abstract/quoting.rb +177 -60
  59. data/lib/active_record/connection_adapters/abstract/savepoints.rb +8 -6
  60. data/lib/active_record/connection_adapters/abstract/schema_creation.rb +157 -93
  61. data/lib/active_record/connection_adapters/abstract/schema_definitions.rb +473 -255
  62. data/lib/active_record/connection_adapters/abstract/schema_dumper.rb +79 -36
  63. data/lib/active_record/connection_adapters/abstract/schema_statements.rb +869 -286
  64. data/lib/active_record/connection_adapters/abstract/transaction.rb +257 -91
  65. data/lib/active_record/connection_adapters/abstract_adapter.rb +483 -230
  66. data/lib/active_record/connection_adapters/abstract_mysql_adapter.rb +557 -640
  67. data/lib/active_record/connection_adapters/column.rb +67 -40
  68. data/lib/active_record/connection_adapters/deduplicable.rb +29 -0
  69. data/lib/active_record/connection_adapters/legacy_pool_manager.rb +35 -0
  70. data/lib/active_record/connection_adapters/mysql/column.rb +27 -0
  71. data/lib/active_record/connection_adapters/mysql/database_statements.rb +194 -0
  72. data/lib/active_record/connection_adapters/mysql/explain_pretty_printer.rb +71 -0
  73. data/lib/active_record/connection_adapters/mysql/quoting.rb +96 -0
  74. data/lib/active_record/connection_adapters/mysql/schema_creation.rb +97 -0
  75. data/lib/active_record/connection_adapters/mysql/schema_definitions.rb +103 -0
  76. data/lib/active_record/connection_adapters/mysql/schema_dumper.rb +91 -0
  77. data/lib/active_record/connection_adapters/mysql/schema_statements.rb +268 -0
  78. data/lib/active_record/connection_adapters/mysql/type_metadata.rb +40 -0
  79. data/lib/active_record/connection_adapters/mysql2_adapter.rb +80 -192
  80. data/lib/active_record/connection_adapters/pool_config.rb +73 -0
  81. data/lib/active_record/connection_adapters/pool_manager.rb +47 -0
  82. data/lib/active_record/connection_adapters/postgresql/column.rb +44 -11
  83. data/lib/active_record/connection_adapters/postgresql/database_statements.rb +75 -160
  84. data/lib/active_record/connection_adapters/postgresql/explain_pretty_printer.rb +44 -0
  85. data/lib/active_record/connection_adapters/postgresql/oid/array.rb +49 -58
  86. data/lib/active_record/connection_adapters/postgresql/oid/bit.rb +9 -8
  87. data/lib/active_record/connection_adapters/postgresql/oid/bit_varying.rb +2 -0
  88. data/lib/active_record/connection_adapters/postgresql/oid/bytea.rb +4 -2
  89. data/lib/active_record/connection_adapters/postgresql/oid/cidr.rb +8 -6
  90. data/lib/active_record/connection_adapters/postgresql/oid/date.rb +13 -1
  91. data/lib/active_record/connection_adapters/postgresql/oid/date_time.rb +14 -19
  92. data/lib/active_record/connection_adapters/postgresql/oid/decimal.rb +3 -1
  93. data/lib/active_record/connection_adapters/postgresql/oid/enum.rb +5 -4
  94. data/lib/active_record/connection_adapters/postgresql/oid/hstore.rb +31 -20
  95. data/lib/active_record/connection_adapters/postgresql/oid/inet.rb +2 -0
  96. data/lib/active_record/connection_adapters/postgresql/oid/interval.rb +49 -0
  97. data/lib/active_record/connection_adapters/postgresql/oid/jsonb.rb +3 -11
  98. data/lib/active_record/connection_adapters/postgresql/oid/legacy_point.rb +44 -0
  99. data/lib/active_record/connection_adapters/postgresql/oid/macaddr.rb +25 -0
  100. data/lib/active_record/connection_adapters/postgresql/oid/money.rb +7 -9
  101. data/lib/active_record/connection_adapters/postgresql/oid/{infinity.rb → oid.rb} +5 -3
  102. data/lib/active_record/connection_adapters/postgresql/oid/point.rb +32 -11
  103. data/lib/active_record/connection_adapters/postgresql/oid/range.rb +70 -34
  104. data/lib/active_record/connection_adapters/postgresql/oid/specialized_string.rb +4 -5
  105. data/lib/active_record/connection_adapters/postgresql/oid/type_map_initializer.rb +58 -54
  106. data/lib/active_record/connection_adapters/postgresql/oid/uuid.rb +18 -4
  107. data/lib/active_record/connection_adapters/postgresql/oid/vector.rb +3 -1
  108. data/lib/active_record/connection_adapters/postgresql/oid/xml.rb +3 -1
  109. data/lib/active_record/connection_adapters/postgresql/oid.rb +25 -25
  110. data/lib/active_record/connection_adapters/postgresql/quoting.rb +145 -48
  111. data/lib/active_record/connection_adapters/postgresql/referential_integrity.rb +27 -14
  112. data/lib/active_record/connection_adapters/postgresql/schema_creation.rb +80 -0
  113. data/lib/active_record/connection_adapters/postgresql/schema_definitions.rb +178 -108
  114. data/lib/active_record/connection_adapters/postgresql/schema_dumper.rb +49 -0
  115. data/lib/active_record/connection_adapters/postgresql/schema_statements.rb +496 -298
  116. data/lib/active_record/connection_adapters/postgresql/type_metadata.rb +44 -0
  117. data/lib/active_record/connection_adapters/postgresql/utils.rb +11 -8
  118. data/lib/active_record/connection_adapters/postgresql_adapter.rb +588 -375
  119. data/lib/active_record/connection_adapters/schema_cache.rb +167 -29
  120. data/lib/active_record/connection_adapters/sql_type_metadata.rb +45 -0
  121. data/lib/active_record/connection_adapters/sqlite3/database_statements.rb +144 -0
  122. data/lib/active_record/connection_adapters/sqlite3/explain_pretty_printer.rb +21 -0
  123. data/lib/active_record/connection_adapters/sqlite3/quoting.rb +102 -0
  124. data/lib/active_record/connection_adapters/sqlite3/schema_creation.rb +21 -0
  125. data/lib/active_record/connection_adapters/sqlite3/schema_definitions.rb +19 -0
  126. data/lib/active_record/connection_adapters/sqlite3/schema_dumper.rb +18 -0
  127. data/lib/active_record/connection_adapters/sqlite3/schema_statements.rb +170 -0
  128. data/lib/active_record/connection_adapters/sqlite3_adapter.rb +322 -373
  129. data/lib/active_record/connection_adapters/statement_pool.rb +33 -13
  130. data/lib/active_record/connection_adapters.rb +52 -0
  131. data/lib/active_record/connection_handling.rb +314 -41
  132. data/lib/active_record/core.rb +458 -241
  133. data/lib/active_record/counter_cache.rb +70 -49
  134. data/lib/active_record/database_configurations/connection_url_resolver.rb +98 -0
  135. data/lib/active_record/database_configurations/database_config.rb +80 -0
  136. data/lib/active_record/database_configurations/hash_config.rb +96 -0
  137. data/lib/active_record/database_configurations/url_config.rb +53 -0
  138. data/lib/active_record/database_configurations.rb +272 -0
  139. data/lib/active_record/delegated_type.rb +209 -0
  140. data/lib/active_record/destroy_association_async_job.rb +36 -0
  141. data/lib/active_record/dynamic_matchers.rb +87 -106
  142. data/lib/active_record/enum.rb +211 -92
  143. data/lib/active_record/errors.rb +224 -54
  144. data/lib/active_record/explain.rb +27 -11
  145. data/lib/active_record/explain_registry.rb +4 -2
  146. data/lib/active_record/explain_subscriber.rb +10 -5
  147. data/lib/active_record/fixture_set/file.rb +33 -14
  148. data/lib/active_record/fixture_set/model_metadata.rb +32 -0
  149. data/lib/active_record/fixture_set/render_context.rb +17 -0
  150. data/lib/active_record/fixture_set/table_row.rb +152 -0
  151. data/lib/active_record/fixture_set/table_rows.rb +46 -0
  152. data/lib/active_record/fixtures.rb +275 -500
  153. data/lib/active_record/gem_version.rb +6 -4
  154. data/lib/active_record/inheritance.rb +175 -110
  155. data/lib/active_record/insert_all.rb +212 -0
  156. data/lib/active_record/integration.rb +121 -29
  157. data/lib/active_record/internal_metadata.rb +62 -0
  158. data/lib/active_record/legacy_yaml_adapter.rb +27 -5
  159. data/lib/active_record/locale/en.yml +3 -2
  160. data/lib/active_record/locking/optimistic.rb +98 -92
  161. data/lib/active_record/locking/pessimistic.rb +22 -6
  162. data/lib/active_record/log_subscriber.rb +93 -31
  163. data/lib/active_record/middleware/database_selector/resolver/session.rb +48 -0
  164. data/lib/active_record/middleware/database_selector/resolver.rb +92 -0
  165. data/lib/active_record/middleware/database_selector.rb +77 -0
  166. data/lib/active_record/migration/command_recorder.rb +185 -90
  167. data/lib/active_record/migration/compatibility.rb +295 -0
  168. data/lib/active_record/migration/join_table.rb +8 -7
  169. data/lib/active_record/migration.rb +673 -325
  170. data/lib/active_record/model_schema.rb +418 -113
  171. data/lib/active_record/nested_attributes.rb +263 -224
  172. data/lib/active_record/no_touching.rb +15 -2
  173. data/lib/active_record/null_relation.rb +24 -38
  174. data/lib/active_record/persistence.rb +572 -136
  175. data/lib/active_record/query_cache.rb +29 -23
  176. data/lib/active_record/querying.rb +50 -31
  177. data/lib/active_record/railtie.rb +170 -51
  178. data/lib/active_record/railties/console_sandbox.rb +3 -3
  179. data/lib/active_record/railties/controller_runtime.rb +34 -33
  180. data/lib/active_record/railties/databases.rake +523 -199
  181. data/lib/active_record/readonly_attributes.rb +9 -4
  182. data/lib/active_record/reflection.rb +454 -291
  183. data/lib/active_record/relation/batches/batch_enumerator.rb +85 -0
  184. data/lib/active_record/relation/batches.rb +217 -59
  185. data/lib/active_record/relation/calculations.rb +324 -249
  186. data/lib/active_record/relation/delegation.rb +76 -84
  187. data/lib/active_record/relation/finder_methods.rb +316 -242
  188. data/lib/active_record/relation/from_clause.rb +30 -0
  189. data/lib/active_record/relation/merger.rb +95 -103
  190. data/lib/active_record/relation/predicate_builder/array_handler.rb +26 -26
  191. data/lib/active_record/relation/predicate_builder/association_query_value.rb +42 -0
  192. data/lib/active_record/relation/predicate_builder/basic_object_handler.rb +19 -0
  193. data/lib/active_record/relation/predicate_builder/polymorphic_array_value.rb +57 -0
  194. data/lib/active_record/relation/predicate_builder/range_handler.rb +22 -0
  195. data/lib/active_record/relation/predicate_builder/relation_handler.rb +7 -1
  196. data/lib/active_record/relation/predicate_builder.rb +136 -122
  197. data/lib/active_record/relation/query_attribute.rb +50 -0
  198. data/lib/active_record/relation/query_methods.rb +757 -413
  199. data/lib/active_record/relation/record_fetch_warning.rb +51 -0
  200. data/lib/active_record/relation/spawn_methods.rb +18 -20
  201. data/lib/active_record/relation/where_clause.rb +239 -0
  202. data/lib/active_record/relation.rb +554 -343
  203. data/lib/active_record/result.rb +91 -47
  204. data/lib/active_record/runtime_registry.rb +6 -4
  205. data/lib/active_record/sanitization.rb +134 -122
  206. data/lib/active_record/schema.rb +21 -24
  207. data/lib/active_record/schema_dumper.rb +141 -92
  208. data/lib/active_record/schema_migration.rb +24 -23
  209. data/lib/active_record/scoping/default.rb +96 -83
  210. data/lib/active_record/scoping/named.rb +78 -36
  211. data/lib/active_record/scoping.rb +45 -27
  212. data/lib/active_record/secure_token.rb +48 -0
  213. data/lib/active_record/serialization.rb +8 -6
  214. data/lib/active_record/signed_id.rb +116 -0
  215. data/lib/active_record/statement_cache.rb +89 -36
  216. data/lib/active_record/store.rb +128 -43
  217. data/lib/active_record/suppressor.rb +61 -0
  218. data/lib/active_record/table_metadata.rb +81 -0
  219. data/lib/active_record/tasks/database_tasks.rb +364 -130
  220. data/lib/active_record/tasks/mysql_database_tasks.rb +67 -113
  221. data/lib/active_record/tasks/postgresql_database_tasks.rb +86 -49
  222. data/lib/active_record/tasks/sqlite_database_tasks.rb +44 -19
  223. data/lib/active_record/test_databases.rb +24 -0
  224. data/lib/active_record/test_fixtures.rb +287 -0
  225. data/lib/active_record/timestamp.rb +86 -43
  226. data/lib/active_record/touch_later.rb +65 -0
  227. data/lib/active_record/transactions.rb +182 -163
  228. data/lib/active_record/translation.rb +3 -1
  229. data/lib/active_record/type/adapter_specific_registry.rb +126 -0
  230. data/lib/active_record/type/date.rb +4 -45
  231. data/lib/active_record/type/date_time.rb +4 -49
  232. data/lib/active_record/type/decimal_without_scale.rb +6 -2
  233. data/lib/active_record/type/hash_lookup_type_map.rb +5 -4
  234. data/lib/active_record/type/internal/timezone.rb +17 -0
  235. data/lib/active_record/type/json.rb +30 -0
  236. data/lib/active_record/type/serialized.rb +27 -15
  237. data/lib/active_record/type/text.rb +2 -2
  238. data/lib/active_record/type/time.rb +21 -16
  239. data/lib/active_record/type/type_map.rb +16 -19
  240. data/lib/active_record/type/unsigned_integer.rb +9 -8
  241. data/lib/active_record/type.rb +84 -23
  242. data/lib/active_record/type_caster/connection.rb +33 -0
  243. data/lib/active_record/type_caster/map.rb +23 -0
  244. data/lib/active_record/type_caster.rb +9 -0
  245. data/lib/active_record/validations/absence.rb +25 -0
  246. data/lib/active_record/validations/associated.rb +12 -4
  247. data/lib/active_record/validations/length.rb +26 -0
  248. data/lib/active_record/validations/numericality.rb +35 -0
  249. data/lib/active_record/validations/presence.rb +14 -13
  250. data/lib/active_record/validations/uniqueness.rb +63 -56
  251. data/lib/active_record/validations.rb +39 -35
  252. data/lib/active_record/version.rb +3 -1
  253. data/lib/active_record.rb +42 -29
  254. data/lib/arel/alias_predication.rb +9 -0
  255. data/lib/arel/attributes/attribute.rb +41 -0
  256. data/lib/arel/collectors/bind.rb +29 -0
  257. data/lib/arel/collectors/composite.rb +39 -0
  258. data/lib/arel/collectors/plain_string.rb +20 -0
  259. data/lib/arel/collectors/sql_string.rb +27 -0
  260. data/lib/arel/collectors/substitute_binds.rb +35 -0
  261. data/lib/arel/crud.rb +42 -0
  262. data/lib/arel/delete_manager.rb +18 -0
  263. data/lib/arel/errors.rb +9 -0
  264. data/lib/arel/expressions.rb +29 -0
  265. data/lib/arel/factory_methods.rb +49 -0
  266. data/lib/arel/insert_manager.rb +49 -0
  267. data/lib/arel/math.rb +45 -0
  268. data/lib/arel/nodes/and.rb +32 -0
  269. data/lib/arel/nodes/ascending.rb +23 -0
  270. data/lib/arel/nodes/binary.rb +126 -0
  271. data/lib/arel/nodes/bind_param.rb +44 -0
  272. data/lib/arel/nodes/case.rb +55 -0
  273. data/lib/arel/nodes/casted.rb +62 -0
  274. data/lib/arel/nodes/comment.rb +29 -0
  275. data/lib/arel/nodes/count.rb +12 -0
  276. data/lib/arel/nodes/delete_statement.rb +45 -0
  277. data/lib/arel/nodes/descending.rb +23 -0
  278. data/lib/arel/nodes/equality.rb +15 -0
  279. data/lib/arel/nodes/extract.rb +24 -0
  280. data/lib/arel/nodes/false.rb +16 -0
  281. data/lib/arel/nodes/full_outer_join.rb +8 -0
  282. data/lib/arel/nodes/function.rb +44 -0
  283. data/lib/arel/nodes/grouping.rb +11 -0
  284. data/lib/arel/nodes/homogeneous_in.rb +76 -0
  285. data/lib/arel/nodes/in.rb +15 -0
  286. data/lib/arel/nodes/infix_operation.rb +92 -0
  287. data/lib/arel/nodes/inner_join.rb +8 -0
  288. data/lib/arel/nodes/insert_statement.rb +37 -0
  289. data/lib/arel/nodes/join_source.rb +20 -0
  290. data/lib/arel/nodes/matches.rb +18 -0
  291. data/lib/arel/nodes/named_function.rb +23 -0
  292. data/lib/arel/nodes/node.rb +51 -0
  293. data/lib/arel/nodes/node_expression.rb +13 -0
  294. data/lib/arel/nodes/ordering.rb +27 -0
  295. data/lib/arel/nodes/outer_join.rb +8 -0
  296. data/lib/arel/nodes/over.rb +15 -0
  297. data/lib/arel/nodes/regexp.rb +16 -0
  298. data/lib/arel/nodes/right_outer_join.rb +8 -0
  299. data/lib/arel/nodes/select_core.rb +67 -0
  300. data/lib/arel/nodes/select_statement.rb +41 -0
  301. data/lib/arel/nodes/sql_literal.rb +19 -0
  302. data/lib/arel/nodes/string_join.rb +11 -0
  303. data/lib/arel/nodes/table_alias.rb +31 -0
  304. data/lib/arel/nodes/terminal.rb +16 -0
  305. data/lib/arel/nodes/true.rb +16 -0
  306. data/lib/arel/nodes/unary.rb +44 -0
  307. data/lib/arel/nodes/unary_operation.rb +20 -0
  308. data/lib/arel/nodes/unqualified_column.rb +22 -0
  309. data/lib/arel/nodes/update_statement.rb +41 -0
  310. data/lib/arel/nodes/values_list.rb +9 -0
  311. data/lib/arel/nodes/window.rb +126 -0
  312. data/lib/arel/nodes/with.rb +11 -0
  313. data/lib/arel/nodes.rb +70 -0
  314. data/lib/arel/order_predications.rb +13 -0
  315. data/lib/arel/predications.rb +250 -0
  316. data/lib/arel/select_manager.rb +270 -0
  317. data/lib/arel/table.rb +118 -0
  318. data/lib/arel/tree_manager.rb +72 -0
  319. data/lib/arel/update_manager.rb +34 -0
  320. data/lib/arel/visitors/dot.rb +308 -0
  321. data/lib/arel/visitors/mysql.rb +93 -0
  322. data/lib/arel/visitors/postgresql.rb +120 -0
  323. data/lib/arel/visitors/sqlite.rb +38 -0
  324. data/lib/arel/visitors/to_sql.rb +899 -0
  325. data/lib/arel/visitors/visitor.rb +45 -0
  326. data/lib/arel/visitors.rb +13 -0
  327. data/lib/arel/window_predications.rb +9 -0
  328. data/lib/arel.rb +54 -0
  329. data/lib/rails/generators/active_record/application_record/application_record_generator.rb +26 -0
  330. data/lib/rails/generators/active_record/application_record/templates/application_record.rb.tt +5 -0
  331. data/lib/rails/generators/active_record/migration/migration_generator.rb +43 -37
  332. data/lib/rails/generators/active_record/migration/templates/create_table_migration.rb.tt +26 -0
  333. data/lib/rails/generators/active_record/migration/templates/{migration.rb → migration.rb.tt} +13 -4
  334. data/lib/rails/generators/active_record/migration.rb +35 -1
  335. data/lib/rails/generators/active_record/model/model_generator.rb +55 -22
  336. data/lib/rails/generators/active_record/model/templates/abstract_base_class.rb.tt +7 -0
  337. data/lib/rails/generators/active_record/model/templates/model.rb.tt +22 -0
  338. data/lib/rails/generators/active_record/model/templates/{module.rb → module.rb.tt} +0 -0
  339. data/lib/rails/generators/active_record.rb +7 -5
  340. metadata +172 -65
  341. data/lib/active_record/associations/preloader/belongs_to.rb +0 -17
  342. data/lib/active_record/associations/preloader/collection_association.rb +0 -24
  343. data/lib/active_record/associations/preloader/has_many.rb +0 -17
  344. data/lib/active_record/associations/preloader/has_many_through.rb +0 -19
  345. data/lib/active_record/associations/preloader/has_one.rb +0 -23
  346. data/lib/active_record/associations/preloader/has_one_through.rb +0 -9
  347. data/lib/active_record/associations/preloader/singular_association.rb +0 -21
  348. data/lib/active_record/attribute.rb +0 -163
  349. data/lib/active_record/attribute_decorators.rb +0 -66
  350. data/lib/active_record/attribute_set/builder.rb +0 -106
  351. data/lib/active_record/attribute_set.rb +0 -81
  352. data/lib/active_record/connection_adapters/connection_specification.rb +0 -275
  353. data/lib/active_record/connection_adapters/mysql_adapter.rb +0 -491
  354. data/lib/active_record/connection_adapters/postgresql/array_parser.rb +0 -93
  355. data/lib/active_record/connection_adapters/postgresql/oid/float.rb +0 -21
  356. data/lib/active_record/connection_adapters/postgresql/oid/integer.rb +0 -11
  357. data/lib/active_record/connection_adapters/postgresql/oid/json.rb +0 -35
  358. data/lib/active_record/connection_adapters/postgresql/oid/time.rb +0 -11
  359. data/lib/active_record/railties/jdbcmysql_error.rb +0 -16
  360. data/lib/active_record/serializers/xml_serializer.rb +0 -193
  361. data/lib/active_record/type/big_integer.rb +0 -13
  362. data/lib/active_record/type/binary.rb +0 -50
  363. data/lib/active_record/type/boolean.rb +0 -31
  364. data/lib/active_record/type/decimal.rb +0 -64
  365. data/lib/active_record/type/decorator.rb +0 -14
  366. data/lib/active_record/type/float.rb +0 -19
  367. data/lib/active_record/type/integer.rb +0 -59
  368. data/lib/active_record/type/mutable.rb +0 -16
  369. data/lib/active_record/type/numeric.rb +0 -36
  370. data/lib/active_record/type/string.rb +0 -40
  371. data/lib/active_record/type/time_value.rb +0 -38
  372. data/lib/active_record/type/value.rb +0 -110
  373. data/lib/rails/generators/active_record/migration/templates/create_table_migration.rb +0 -19
  374. data/lib/rails/generators/active_record/model/templates/model.rb +0 -10
data/CHANGELOG.md CHANGED
@@ -1,2014 +1,1596 @@
1
- ## Rails 4.2.9 (June 26, 2017) ##
1
+ ## Rails 6.1.4.1 (August 19, 2021) ##
2
2
 
3
- * Fix regression caused by `collection_singular_ids=` ignoring different primary key on relationship.
4
-
5
- *Nick Pezza*
6
-
7
- * Fix `rake db:schema:load` with subdirectories.
8
-
9
- *Ryuta Kamizono*
10
-
11
- * Fix `rake db:migrate:status` with subdirectories.
12
-
13
- *Ryuta Kamizono*
14
-
15
- * Fix regression of #1969 with SELECT aliases in HAVING clause.
16
-
17
- *Eugene Kenny*
18
-
19
- * Fix `wait_timeout` to configurable for mysql2 adapter.
20
-
21
- Fixes #26556.
22
-
23
- *Ryuta Kamizono*
24
-
25
- * Make `table_name=` reset current statement cache,
26
- so queries are not run against the previous table name.
27
-
28
- *namusyaka*
3
+ * No changes.
29
4
 
30
5
 
31
- ## Rails 4.2.8 (February 21, 2017) ##
6
+ ## Rails 6.1.4 (June 24, 2021) ##
32
7
 
33
- * Using a mysql2 connection after it fails to reconnect will now have an error message
34
- saying the connection is closed rather than an undefined method error message.
8
+ * Do not try to rollback transactions that failed due to a `ActiveRecord::TransactionRollbackError`.
35
9
 
36
- *Dylan Thacker-Smith*
10
+ *Jamie McCarthy*
37
11
 
38
- * Bust Model.attribute_names cache when resetting column information
12
+ * Raise an error if `pool_config` is `nil` in `set_pool_config`.
39
13
 
40
- *James Coleman*
14
+ *Eileen M. Uchitelle*
41
15
 
42
- * Fix query caching when type information is reset
16
+ * Fix compatibility with `psych >= 4`.
43
17
 
44
- Backports ancillary fix in 5.0.
18
+ Starting in Psych 4.0.0 `YAML.load` behaves like `YAML.safe_load`. To preserve compatibility
19
+ Active Record's schema cache loader and `YAMLColumn` now uses `YAML.unsafe_load` if available.
45
20
 
46
- *James Coleman*
21
+ *Jean Boussier*
47
22
 
48
- * Allow `joins` to be unscoped.
23
+ * Support using replicas when using `rails dbconsole`.
49
24
 
50
- Fixes #13775.
25
+ *Christopher Thornton*
51
26
 
52
- *Takashi Kokubun*
27
+ * Restore connection pools after transactional tests.
53
28
 
54
- * Hashes can once again be passed to setters of `composed_of`, if all of the
55
- mapping methods are methods implemented on `Hash`.
29
+ *Eugene Kenny*
56
30
 
57
- Fixes #25978.
31
+ * Change `upsert_all` to fails cleanly for MySQL when `:unique_by` is used.
58
32
 
59
- *Sean Griffin*
33
+ *Bastian Bartmann*
60
34
 
35
+ * Fix user-defined `self.default_scope` to respect table alias.
61
36
 
62
- ## Rails 4.2.7 (July 12, 2016) ##
37
+ *Ryuta Kamizono*
63
38
 
64
- * Inspecting an object with an associated array of over 10 elements no longer
65
- truncates the array, preventing `inspect` from looping infinitely in some
66
- cases.
39
+ * Clear `@cache_keys` cache after `update_all`, `delete_all`, `destroy_all`.
67
40
 
68
- *Kevin McPhillips*
41
+ *Ryuta Kamizono*
69
42
 
70
- * Ensure hashes can be assigned to attributes created using `composed_of`.
71
- Fixes #25210.
43
+ * Changed Arel predications `contains` and `overlaps` to use
44
+ `quoted_node` so that PostgreSQL arrays are quoted properly.
72
45
 
73
- *Sean Griffin*
46
+ *Bradley Priest*
74
47
 
75
- * Queries such as `Computer.joins(:monitor).group(:status).count` will now be
76
- interpreted as `Computer.joins(:monitor).group('computers.status').count`
77
- so that when `Computer` and `Monitor` have both `status` columns we don't
78
- have conflicts in projection.
48
+ * Fix `merge` when the `where` clauses have string contents.
79
49
 
80
- *Rafael Sales*
50
+ *Ryuta Kamizono*
81
51
 
82
- * ActiveRecord::Relation#count: raise an ArgumentError when finder options
83
- are specified or an ActiveRecord::StatementInvalid when an invalid type
84
- is provided for a column name (e.g. a Hash).
52
+ * Fix rollback of parent destruction with nested `dependent: :destroy`.
85
53
 
86
- Fixes #20434
54
+ *Jacopo Beschi*
87
55
 
88
- *Konstantinos Rousis*
56
+ * Fix binds logging for `"WHERE ... IN ..."` statements.
89
57
 
90
- * Correctly pass MySQL options when using structure_dump or structure_load
58
+ *Ricardo Díaz*
91
59
 
92
- Specifically, it fixes an issue when using SSL authentication.
60
+ * Handle `false` in relation strict loading checks.
93
61
 
94
- *Alex Coomans*
62
+ Previously when a model had strict loading set to true and then had a
63
+ relation set `strict_loading` to false the false wasn't considered when
64
+ deciding whether to raise/warn about strict loading.
95
65
 
66
+ ```
67
+ class Dog < ActiveRecord::Base
68
+ self.strict_loading_by_default = true
96
69
 
97
- ## Rails 4.2.6 (March 07, 2016) ##
70
+ has_many :treats, strict_loading: false
71
+ end
72
+ ```
98
73
 
99
- * Fix a bug where using `t.foreign_key` twice with the same `to_table` within
100
- the same table definition would only create one foreign key.
74
+ In the example, `dog.treats` would still raise even though
75
+ `strict_loading` was set to false. This is a bug effecting more than
76
+ Active Storage which is why I made this PR superceeding #41461. We need
77
+ to fix this for all applications since the behavior is a little
78
+ surprising. I took the test from ##41461 and the code suggestion from #41453
79
+ with some additions.
101
80
 
102
- *George Millo*
81
+ *Eileen M. Uchitelle*, *Radamés Roriz*
103
82
 
104
- * Fix regression in dirty attribute tracking after #dup. Changes to the
105
- clone no longer show as changed attributes in the original object.
83
+ * Fix numericality validator without precision.
106
84
 
107
- *Dominic Cleal*
85
+ *Ryuta Kamizono*
108
86
 
109
- * Fix regression when loading fixture files with symbol keys.
87
+ * Fix aggregate attribute on Enum types.
110
88
 
111
- Closes #22584.
89
+ *Ryuta Kamizono*
112
90
 
113
- *Yves Senn*
91
+ * Fix `CREATE INDEX` statement generation for PostgreSQL.
114
92
 
115
- * Fix `rake db:structure:dump` on Postgres when multiple schemas are used.
93
+ *eltongo*
116
94
 
117
- Fixes #22346.
95
+ * Fix where clause on enum attribute when providing array of strings.
118
96
 
119
- *Nick Muerdter*, *ckoenig*
97
+ *Ryuta Kamizono*
120
98
 
121
- * Introduce `connection.data_sources` and `connection.data_source_exists?`.
122
- These methods determine what relations can be used to back Active Record
123
- models (usually tables and views).
99
+ * Fix `unprepared_statement` to work it when nesting.
124
100
 
125
- *Yves Senn*, *Matthew Draper*
101
+ *Ryuta Kamizono*
126
102
 
127
103
 
128
- ## Rails 4.2.5.2 (February 26, 2016) ##
104
+ ## Rails 6.1.3.2 (May 05, 2021) ##
129
105
 
130
106
  * No changes.
131
107
 
132
108
 
133
- ## Rails 4.2.5.1 (January 25, 2015) ##
109
+ ## Rails 6.1.3.1 (March 26, 2021) ##
134
110
 
135
111
  * No changes.
136
112
 
137
113
 
138
- ## Rails 4.2.5 (November 12, 2015) ##
139
-
140
- * No longer pass deprecated option `-i` to `pg_dump`.
141
-
142
- *Paul Sadauskas*
143
-
144
- * Set `scope.reordering_value` to `true` if :reordering values are specified.
145
-
146
- Fixes #21886.
147
-
148
- *Hiroaki Izu*
149
-
150
- * Avoid disabling errors on the PostgreSQL connection when enabling the
151
- standard_conforming_strings setting. Errors were previously disabled because
152
- the setting wasn't writable in Postgres 8.1 and didn't exist in earlier
153
- versions. Now Rails only supports Postgres 8.2+ we're fine to assume the
154
- setting exists. Disabling errors caused problems when using a connection
155
- pooling tool like PgBouncer because it's not guaranteed to have the same
156
- connection between calls to `execute` and it could leave the connection
157
- with errors disabled.
158
-
159
- Fixes #22101.
160
-
161
- *Harry Marr*
162
-
163
- * Includes HABTM returns correct size now. It's caused by the join dependency
164
- only instantiates one HABTM object because the join table hasn't a primary key.
165
-
166
- Fixes #16032.
167
-
168
- Examples:
169
-
170
- before:
171
-
172
- Project.first.salaried_developers.size # => 3
173
- Project.includes(:salaried_developers).first.salaried_developers.size # => 1
174
-
175
- after:
176
-
177
- Project.first.salaried_developers.size # => 3
178
- Project.includes(:salaried_developers).first.salaried_developers.size # => 3
179
-
180
- *Bigxiang*
181
-
182
- * Descriptive error message when fixtures contain a missing column.
183
-
184
- Closes #21201.
185
-
186
- *Yves Senn*
114
+ ## Rails 6.1.3 (February 17, 2021) ##
187
115
 
188
- * `bin/rake db:migrate` uses
189
- `ActiveRecord::Tasks::DatabaseTasks.migrations_paths` instead of
190
- `Migrator.migrations_paths`.
191
-
192
- *Tobias Bielohlawek*
193
-
194
- * Fix `rewhere` in a `has_many` association.
195
-
196
- Fixes #21955.
197
-
198
- *Josh Branchaud*, *Kal*
199
-
200
- * Added run_cmd class method to ActiveRecord::Tasks::DatabaseTasks for
201
- drying up Kernel.system() calls within this namespace and to avoid
202
- shell expansion by using a paramter list instead of string as arguments
203
- for Kernel.system(). Thanks to Nate Berkopec for supply patch to get
204
- test units passing.
205
-
206
- *Bryan Paxton*
207
-
208
- * Avoid leaking the first relation we call `first` on, per model.
209
-
210
- Fixes #21921.
211
-
212
- *Matthew Draper*, *Jean Boussier*
213
-
214
- * Allow deserialization of Active Record models that were YAML encoded prior
215
- to Rails 4.2
216
-
217
- *Sean Griffin*
218
-
219
- * Correctly apply `unscope` when preloading through associations.
220
-
221
- *Jimmy Bourassa*
222
-
223
- * Ensure `select` quotes aliased attributes, even when using `from`.
224
-
225
- Fixes #21488
226
-
227
- *Sean Griffin & @johanlunds*
228
-
229
- * Correct query for PostgreSQL 8.2 compatibility.
230
-
231
- *Ben Murphy*, *Matthew Draper*
232
-
233
- * Uniqueness validator raises descriptive error when running on a persisted
234
- record without primary key.
235
-
236
- Closes #21304.
237
-
238
- *Yves Senn*
239
-
240
-
241
- ## Rails 4.2.4 (August 24, 2015) ##
242
-
243
- * Skip statement cache on through association reader.
244
-
245
- If the through class has default scopes we should skip the statement
246
- cache.
247
-
248
- Closes #20745.
116
+ * Fix the MySQL adapter to always set the right collation and charset
117
+ to the connection session.
249
118
 
250
119
  *Rafael Mendonça França*
251
120
 
252
- * Fixes #19420. When generating schema.rb using Postgres BigInt[] data type
253
- the limit: 8 was not coming through. This caused it to become Int[] data type
254
- after doing a rebuild off of schema.rb.
255
-
256
- *Jake Waller*
257
-
258
- * Fix state being carried over from previous transaction.
259
-
260
- Considering the following example where `name` is a required attribute.
261
- Before we had `new_record?` returning `true` for a persisted record:
262
-
263
- author = Author.create! name: 'foo'
264
- author.name = nil
265
- author.save # => false
266
- author.new_record? # => true
267
-
268
- Fixes #20824.
269
-
270
- *Roque Pinel*
271
-
272
- * Correctly ignore `mark_for_destruction` when `autosave` isn't set to `true`
273
- when validating associations.
274
-
275
- Fixes #20882.
276
-
277
- *Sean Griffin*
278
-
279
- * Fix through associations using scopes having the scope merged multiple
280
- times.
281
-
282
- Fixes #20721.
283
- Fixes #20727.
284
-
285
- *Sean Griffin*
286
-
287
- * `ActiveRecord::Base.dump_schema_after_migration` applies migration tasks
288
- other than `db:migrate`. (eg. `db:rollback`, `db:migrate:dup`, ...)
289
-
290
- Fixes #20743.
291
-
292
- *Yves Senn*
293
-
294
- * Correctly raise `ActiveRecord::AssociationTypeMismatch` when assigning
295
- a wrong type to a namespaced association.
296
-
297
- Fixes #20545.
298
-
299
- *Diego Carrion*
121
+ * Fix MySQL adapter handling of time objects when prepared statements
122
+ are enabled.
300
123
 
301
- * Prevent error when using `force_reload: true` on an unassigned polymorphic
302
- belongs_to association.
303
-
304
- Fixes #20426.
305
-
306
- *James Dabbs*
307
-
308
-
309
- ## Rails 4.2.3 (June 25, 2015) ##
310
-
311
- * Let `WITH` queries (Common Table Expressions) be explainable.
312
-
313
- *Vladimir Kochnev*
314
-
315
- * Fix n+1 query problem when eager loading nil associations (fixes #18312)
316
-
317
- *Sammy Larbi*
318
-
319
- * Fixed an error which would occur in dirty checking when calling
320
- `update_attributes` from a getter.
321
-
322
- Fixes #20531.
323
-
324
- *Sean Griffin*
325
-
326
- * Ensure symbols passed to `ActiveRecord::Relation#select` are always treated
327
- as columns.
328
-
329
- Fixes #20360.
330
-
331
- *Sean Griffin*
332
-
333
- * Clear query cache when `ActiveRecord::Base#reload` is called.
334
-
335
- *Shane Hender*
336
-
337
- * Pass `:extend` option for `has_and_belongs_to_many` associations to the
338
- underlying `has_many :through`.
339
-
340
- *Jaehyun Shin*
341
-
342
- * Make `unscope` aware of "less than" and "greater than" conditions.
343
-
344
- *TAKAHASHI Kazuaki*
345
-
346
- * Revert behavior of `db:schema:load` back to loading the full
347
- environment. This ensures that initializers are run.
348
-
349
- Fixes #19545.
350
-
351
- *Yves Senn*
124
+ *Rafael Mendonça França*
352
125
 
353
- * Fix missing index when using `timestamps` with the `index` option.
126
+ * Fix scoping in enum fields using conditions that would generate
127
+ an `IN` clause.
354
128
 
355
- The `index` option used with `timestamps` should be passed to both
356
- `column` definitions for `created_at` and `updated_at` rather than just
357
- the first.
129
+ *Ryuta Kamizono*
358
130
 
359
- *Paul Mucur*
131
+ * Skip optimised #exist? query when #include? is called on a relation
132
+ with a having clause
360
133
 
361
- * Rename `:class` to `:anonymous_class` in association options.
134
+ Relations that have aliased select values AND a having clause that
135
+ references an aliased select value would generate an error when
136
+ #include? was called, due to an optimisation that would generate
137
+ call #exists? on the relation instead, which effectively alters
138
+ the select values of the query (and thus removes the aliased select
139
+ values), but leaves the having clause intact. Because the having
140
+ clause is then referencing an aliased column that is no longer
141
+ present in the simplified query, an ActiveRecord::InvalidStatement
142
+ error was raised.
362
143
 
363
- Fixes #19659.
144
+ An sample query affected by this problem:
364
145
 
365
- *Andrew White*
146
+ ```ruby
147
+ Author.select('COUNT(*) as total_posts', 'authors.*')
148
+ .joins(:posts)
149
+ .group(:id)
150
+ .having('total_posts > 2')
151
+ .include?(Author.first)
152
+ ```
366
153
 
367
- * Fixed a bug where uniqueness validations would error on out of range values,
368
- even if an validation should have prevented it from hitting the database.
154
+ This change adds an addition check to the condition that skips the
155
+ simplified #exists? query, which simply checks for the presence of
156
+ a having clause.
369
157
 
370
- *Andrey Voronkov*
158
+ Fixes #41417
371
159
 
372
- * Foreign key related methods in the migration DSL respect
373
- `ActiveRecord::Base.pluralize_table_names = false`.
160
+ *Michael Smart*
374
161
 
375
- Fixes #19643.
162
+ * Increment postgres prepared statement counter before making a prepared statement, so if the statement is aborted
163
+ without Rails knowledge (e.g., if app gets kill -9d during long-running query or due to Rack::Timeout), app won't end
164
+ up in perpetual crash state for being inconsistent with Postgres.
376
165
 
377
- *Mehmet Emin İNAÇ*
166
+ *wbharding*, *Martin Tepper*
378
167
 
379
- * Reduce memory usage from loading types on pg.
380
168
 
381
- Fixes #19578.
169
+ ## Rails 6.1.2.1 (February 10, 2021) ##
382
170
 
383
- *Sean Griffin*
171
+ * Fix possible DoS vector in PostgreSQL money type
384
172
 
385
- * Fix referencing wrong table aliases while joining tables of has many through
386
- association (only when calling calculation methods).
173
+ Carefully crafted input can cause a DoS via the regular expressions used
174
+ for validating the money format in the PostgreSQL adapter. This patch
175
+ fixes the regexp.
387
176
 
388
- Fixes #19276.
177
+ Thanks to @dee-see from Hackerone for this patch!
389
178
 
390
- *pinglamb*
179
+ [CVE-2021-22880]
391
180
 
392
- * Don't attempt to update counter caches, when the column wasn't selected.
181
+ *Aaron Patterson*
393
182
 
394
- Fixes #19437.
395
183
 
396
- *Sean Griffin*
184
+ ## Rails 6.1.2 (February 09, 2021) ##
397
185
 
398
- * Correctly persist a serialized attribute that has been returned to
399
- its default value by an in-place modification.
186
+ * Fix timestamp type for sqlite3.
400
187
 
401
- Fixes #19467.
188
+ *Eileen M. Uchitelle*
402
189
 
403
- *Matthew Draper*
190
+ * Make destroy async transactional.
404
191
 
405
- * Fix default `format` value in `ActiveRecord::Tasks::DatabaseTasks#schema_file`.
192
+ An active record rollback could occur while enqueuing a job. In this
193
+ case the job would enqueue even though the database deletion
194
+ rolledback putting things in a funky state.
406
195
 
407
- *James Cox*
196
+ Now the jobs are only enqueued until after the db transaction has been committed.
408
197
 
409
- * Dont enroll records in the transaction if they dont have commit callbacks.
410
- That was causing a memory grow problem when creating a lot of records inside a transaction.
198
+ *Cory Gwin*
411
199
 
412
- Fixes #15549.
200
+ * Fix malformed packet error in MySQL statement for connection configuration.
413
201
 
414
- *Will Bryant*, *Aaron Patterson*
202
+ *robinroestenburg*
415
203
 
416
- * Correctly create through records when created on a has many through
417
- association when using `where`.
204
+ * Connection specification now passes the "url" key as a configuration for the
205
+ adapter if the "url" protocol is "jdbc", "http", or "https". Previously only
206
+ urls with the "jdbc" prefix were passed to the Active Record Adapter, others
207
+ are assumed to be adapter specification urls.
418
208
 
419
- Fixes #19073.
209
+ Fixes #41137.
420
210
 
421
- *Sean Griffin*
211
+ *Jonathan Bracy*
422
212
 
213
+ * Fix granular connection swapping when there are multiple abstract classes.
423
214
 
424
- ## Rails 4.2.2 (June 16, 2015) ##
215
+ *Eileen M. Uchitelle*
425
216
 
426
- * No Changes *
217
+ * Fix `find_by` with custom primary key for belongs_to association.
427
218
 
219
+ *Ryuta Kamizono*
428
220
 
429
- ## Rails 4.2.1 (March 19, 2015) ##
221
+ * Add support for `rails console --sandbox` for multiple database applications.
430
222
 
431
- * Fixed ActiveRecord::Relation#becomes! and changed_attributes issues for type column
223
+ *alpaca-tc*
432
224
 
433
- Fixes #17139.
225
+ * Fix `where` on polymorphic association with empty array.
434
226
 
435
- *Miklos Fazekas*
227
+ *Ryuta Kamizono*
436
228
 
437
- * `remove_reference` with `foreign_key: true` removes the foreign key before
438
- removing the column. This fixes a bug where it was not possible to remove
439
- the column on MySQL.
229
+ * Fix preventing writes for `ApplicationRecord`.
440
230
 
441
- Fixes #18664.
231
+ *Eileen M. Uchitelle*
442
232
 
443
- *Yves Senn*
444
233
 
445
- * Add a `:foreign_key` option to `references` and associated migration
446
- methods. The model and migration generators now use this option, rather than
447
- the `add_foreign_key` form.
234
+ ## Rails 6.1.1 (January 07, 2021) ##
448
235
 
449
- *Sean Griffin*
236
+ * Fix fixtures loading when strict loading is enabled for the association.
450
237
 
451
- * Fix rounding problem for PostgreSQL timestamp column.
238
+ *Alex Ghiculescu*
452
239
 
453
- If timestamp column have the precision, it need to format according to
454
- the precision of timestamp column.
240
+ * Fix `where` with custom primary key for belongs_to association.
455
241
 
456
242
  *Ryuta Kamizono*
457
243
 
458
- * Respect the database default charset for `schema_migrations` table.
459
-
460
- The charset of `version` column in `schema_migrations` table is depend
461
- on the database default charset and collation rather than the encoding
462
- of the connection.
244
+ * Fix `where` with aliased associations.
463
245
 
464
246
  *Ryuta Kamizono*
465
247
 
466
- * Respect custom primary keys for associations when calling `Relation#where`
467
-
468
- Fixes #18813.
469
-
470
- *Sean Griffin*
471
-
472
- * Fixed several edge cases which could result in a counter cache updating
473
- twice or not updating at all for `has_many` and `has_many :through`.
474
-
475
- Fixes #10865.
476
-
477
- *Sean Griffin*
478
-
479
- * Foreign keys added by migrations were given random, generated names. This
480
- meant a different `structure.sql` would be generated every time a developer
481
- ran migrations on their machine.
482
-
483
- The generated part of foreign key names is now a hash of the table name and
484
- column name, which is consistent every time you run the migration.
485
-
486
- *Chris Sinjakli*
487
-
488
- * Fixed ActiveRecord::Relation#group method when argument is SQL reserved key word:
489
-
490
- SplitTest.group(:key).count
491
- Property.group(:value).count
492
-
493
- *Bogdan Gusiev*
494
-
495
- * Don't define autosave association callbacks twice from
496
- `accepts_nested_attributes_for`.
497
-
498
- Fixes #18704.
499
-
500
- *Sean Griffin*
501
-
502
- * Integer types will no longer raise a `RangeError` when assigning an
503
- attribute, but will instead raise when going to the database.
504
-
505
- Fixes several vague issues which were never reported directly. See the
506
- commit message from the commit which added this line for some examples.
507
-
508
- *Sean Griffin*
509
-
510
- * Values which would error while being sent to the database (such as an
511
- ASCII-8BIT string with invalid UTF-8 bytes on Sqlite3), no longer error on
512
- assignment. They will still error when sent to the database, but you are
513
- given the ability to re-assign it to a valid value.
514
-
515
- Fixes #18580.
516
-
517
- *Sean Griffin*
518
-
519
- * Don't remove join dependencies in `Relation#exists?`
520
-
521
- Fixes #18632.
522
-
523
- *Sean Griffin*
524
-
525
- * Invalid values assigned to a JSON column are assumed to be `nil`.
526
-
527
- Fixes #18629.
528
-
529
- *Sean Griffin*
530
-
531
- * No longer issue deprecation warning when including a scope with extensions.
532
- Previously every scope with extension methods was transformed into an
533
- instance dependent scope. Including such a scope would wrongfully issue a
534
- deprecation warning. This is no longer the case.
535
-
536
- Fixes #18467.
537
-
538
- *Yves Senn*
539
-
540
- * Correctly use the type provided by `serialize` when updating records using
541
- optimistic locking.
542
-
543
- Fixes #18385.
544
-
545
- *Sean Griffin*
546
-
547
- * `attribute_will_change!` will no longer cause non-persistable attributes to
548
- be sent to the database.
549
-
550
- Fixes #18407.
551
-
552
- *Sean Griffin*
553
-
554
- * Format the datetime string according to the precision of the datetime field.
555
-
556
- Incompatible to rounding behavior between MySQL 5.6 and earlier.
557
-
558
- In 5.5, when you insert `2014-08-17 12:30:00.999999` the fractional part
559
- is ignored. In 5.6, it's rounded to `2014-08-17 12:30:01`:
560
-
561
- http://bugs.mysql.com/bug.php?id=68760
248
+ * Fix `composed_of` with symbol mapping.
562
249
 
563
250
  *Ryuta Kamizono*
564
251
 
565
- * Allow precision option for MySQL datetimes.
252
+ * Don't skip money's type cast for pluck and calculations.
566
253
 
567
254
  *Ryuta Kamizono*
568
255
 
569
- * Clear query cache on rollback.
570
-
571
- *Florian Weingarten*
572
-
573
- * Fixed setting of foreign_key for through associations while building of new record.
574
-
575
- Fixes #12698.
576
-
577
- *Ivan Antropov*
578
-
579
- * Fixed automatic inverse_of for models nested in module.
580
-
581
- *Andrew McCloud*
582
-
583
- * Fix `reaping_frequency` option when the value is a string.
584
-
585
- This usually happens when it is configured using `DATABASE_URL`.
586
-
587
- *korbin*
588
-
589
- * Fix error message when trying to create an associated record and the foreign
590
- key is missing.
591
-
592
- Before this fix the following exception was being raised:
593
-
594
- NoMethodError: undefined method `val' for #<Arel::Nodes::BindParam:0x007fc64d19c218>
595
-
596
- Now the message is:
597
-
598
- ActiveRecord::UnknownAttributeError: unknown attribute 'foreign_key' for Model.
599
-
600
- *Rafael Mendonça França*
601
-
602
- * Fix change detection problem for PostgreSQL bytea type and
603
- `ArgumentError: string contains null byte` exception with pg-0.18.
604
-
605
- Fixes #17680.
606
-
607
- *Lars Kanis*
608
-
609
- * When a table has a composite primary key, the `primary_key` method for
610
- SQLite3 and PostgreSQL adapters was only returning the first field of the key.
611
- Ensures that it will return nil instead, as Active Record doesn't support
612
- composite primary keys.
613
-
614
- Fixes #18070.
615
-
616
- *arthurnn*
617
-
618
- * Ensure `first!` and friends work on loaded associations.
619
-
620
- Fixes #18237.
621
-
622
- *Sean Griffin*
623
-
624
- * Dump the default `nil` for PostgreSQL UUID primary key.
256
+ * Fix `where` on polymorphic association with non Active Record object.
625
257
 
626
258
  *Ryuta Kamizono*
627
259
 
628
- * Don't raise when writing an attribute with an out-of-range datetime passed
629
- by the user.
630
-
631
- *Grey Baker*
632
-
633
- * Fixes bug with 'ActiveRecord::Type::Numeric' that causes negative values to
634
- be marked as having changed when set to the same negative value.
635
-
636
- Fixes #18161.
637
-
638
- *Daniel Fox*
639
-
260
+ * Make sure `db:prepare` works even the schema file doesn't exist.
640
261
 
641
- ## Rails 4.2.0 (December 20, 2014) ##
642
-
643
- * Introduce `force: :cascade` option for `create_table`. Using this option
644
- will recreate tables even if they have dependent objects (like foreign keys).
645
- `db/schema.rb` now uses `force: :cascade`. This makes it possible to
646
- reload the schema when foreign keys are in place.
647
-
648
- *Matthew Draper*, *Yves Senn*
649
-
650
- * `db:schema:load` and `db:structure:load` no longer purge the database
651
- before loading the schema. This is left for the user to do.
652
- `db:test:prepare` will still purge the database.
653
-
654
- Fixes #17945.
655
-
656
- *Yves Senn*
262
+ *Rafael Mendonça França*
657
263
 
658
- * Fix undesirable RangeError by Type::Integer. Add Type::UnsignedInteger.
264
+ * Fix complicated `has_many :through` with nested where condition.
659
265
 
660
266
  *Ryuta Kamizono*
661
267
 
662
- * Add `foreign_type` option to `has_one` and `has_many` association macros.
663
-
664
- This option enables to define the column name of associated object's type for polymorphic associations.
665
-
666
- *Ulisses Almeida, Kassio Borges*
667
-
668
- * `add_timestamps` and `remove_timestamps` now properly reversible with
669
- options.
670
-
671
- *Noam Gagliardi-Rabinovich*
672
-
673
- * Bring back `db:test:prepare` to synchronize the test database schema.
674
-
675
- Manual synchronization using `bin/rake db:test:prepare` is required
676
- when a migration is rolled-back, edited and reapplied.
677
-
678
- `ActiveRecord::Base.maintain_test_schema` now uses `db:test:prepare`
679
- to synchronize the schema. Plugins can use this task as a hook to
680
- provide custom behavior after the schema has been loaded.
681
-
682
- NOTE: `test:prepare` runs before the schema is synchronized.
683
-
684
- Fixes #17171, #15787.
685
-
686
- *Yves Senn*
687
-
688
- * Change `reflections` public api to return the keys as String objects.
689
-
690
- Fixes #16928.
691
-
692
- *arthurnn*
693
-
694
- * Renaming a table in pg also renames the primary key index.
695
-
696
- Fixes #12856
697
-
698
- *Sean Griffin*
699
-
700
- * Make it possible to access fixtures excluded by a `default_scope`.
701
-
702
- *Yves Senn*
703
-
704
- * Fix preloading of associations with a scope containing joins along with
705
- conditions on the joined association.
706
-
707
- *Siddharth Sharma*
708
-
709
- * Add `Table#name` to match `TableDefinition#name`.
710
-
711
- *Cody Cutrer*
712
-
713
- * Cache `CollectionAssociation#reader` proxies separately before and after
714
- the owner has been saved so that the proxy is not cached without the
715
- owner's id.
716
-
717
- *Ben Woosley*
718
-
719
- * `ActiveRecord::ReadOnlyRecord` now has a descriptive message.
720
-
721
- *Franky W.*
722
-
723
- * Fix preloading of associations which unscope a default scope.
268
+ * Handle STI models for `has_many dependent: :destroy_async`.
724
269
 
725
- Fixes #11036.
270
+ *Muhammad Usman*
726
271
 
727
- *Byron Bischoff*
272
+ * Restore possibility of passing `false` to :polymorphic option of `belongs_to`.
728
273
 
729
- * Added SchemaDumper support for tables with jsonb columns.
274
+ Previously, passing `false` would trigger the option validation logic
275
+ to throw an error saying :polymorphic would not be a valid option.
730
276
 
731
- *Ted O'Meara*
277
+ *glaszig*
732
278
 
733
- * Deprecate `sanitize_sql_hash_for_conditions` without replacement. Using a
734
- `Relation` for performing queries and updates is the prefered API.
279
+ * Allow adding nonnamed expression indexes to be revertible.
735
280
 
736
- *Sean Griffin*
281
+ Fixes #40732.
737
282
 
738
- * Queries now properly type cast values that are part of a join statement,
739
- even when using type decorators such as `serialize`.
283
+ Previously, the following code would raise an error, when executed while rolling back,
284
+ and the index name should be specified explicitly. Now, the index name is inferred
285
+ automatically.
740
286
 
741
- *Melanie Gilman & Sean Griffin*
287
+ ```ruby
288
+ add_index(:items, "to_tsvector('english', description)")
289
+ ```
742
290
 
743
- * MySQL enum type lookups, with values matching another type, no longer result
744
- in an endless loop.
291
+ *fatkodima*
745
292
 
746
- Fixes #17402.
747
293
 
748
- *Yves Senn*
294
+ ## Rails 6.1.0 (December 09, 2020) ##
749
295
 
750
- * Raise `ArgumentError` when the body of a scope is not callable.
296
+ * Only warn about negative enums if a positive form that would cause conflicts exists.
751
297
 
752
- *Mauro George*
298
+ Fixes #39065.
753
299
 
754
- * Use type column first in multi-column indexes created with `add-reference`.
300
+ *Alex Ghiculescu*
755
301
 
756
- *Derek Prior*
302
+ * Change `attribute_for_inspect` to take `filter_attributes` in consideration.
757
303
 
758
- * Fix `Relation.rewhere` to work with Range values.
759
-
760
- *Dan Olson*
761
-
762
- * `AR::UnknownAttributeError` now includes the class name of a record.
763
-
764
- User.new(name: "Yuki Nishijima", project_attributes: {name: "kaminari"})
765
- # => ActiveRecord::UnknownAttributeError: unknown attribute 'name' for User.
766
-
767
- *Yuki Nishijima*
768
-
769
- * Fix a regression causing `after_create` callbacks to run before associated
770
- records are autosaved.
771
-
772
- Fixes #17209.
773
-
774
- *Agis Anastasopoulos*
775
-
776
- * Honor overridden `rack.test` in Rack environment for the connection
777
- management middleware.
778
-
779
- *Simon Eskildsen*
780
-
781
- * Add a truncate method to the connection.
782
-
783
- *Aaron Patterson*
784
-
785
- * Don't autosave unchanged has_one through records.
786
-
787
- *Alan Kennedy*, *Steve Parrington*
788
-
789
- * Do not dump foreign keys for ignored tables.
790
-
791
- *Yves Senn*
304
+ *Rafael Mendonça França*
792
305
 
793
- * PostgreSQL adapter correctly dumps foreign keys targeting tables
794
- outside the schema search path.
306
+ * Fix odd behavior of inverse_of with multiple belongs_to to same class.
795
307
 
796
- Fixes #16907.
308
+ Fixes #35204.
797
309
 
798
- *Matthew Draper*, *Yves Senn*
310
+ *Tomoyuki Kai*
799
311
 
800
- * When a thread is killed, rollback the active transaction, instead of
801
- committing it during the stack unwind. Previously, we could commit half-
802
- completed work. This fix only works for Ruby 2.0+; on 1.9, we can't
803
- distinguish a thread kill from an ordinary non-local (block) return, so must
804
- default to committing.
312
+ * Build predicate conditions with objects that delegate `#id` and primary key:
805
313
 
806
- *Chris Hanks*
314
+ ```ruby
315
+ class AdminAuthor
316
+ delegate_missing_to :@author
807
317
 
808
- * A `NullRelation` should represent nothing. This fixes a bug where
809
- `Comment.where(post_id: Post.none)` returned a non-empty result.
318
+ def initialize(author)
319
+ @author = author
320
+ end
321
+ end
810
322
 
811
- Fixes #15176.
323
+ Post.where(author: AdminAuthor.new(author))
324
+ ```
812
325
 
813
- *Matthew Draper*, *Yves Senn*
326
+ *Sean Doyle*
814
327
 
815
- * Include default column limits in schema.rb. Allows defaults to be changed
816
- in the future without affecting old migrations that assumed old defaults.
328
+ * Add `connected_to_many` API.
817
329
 
818
- *Jeremy Kemper*
330
+ This API allows applications to connect to multiple databases at once without switching all of them or implementing a deeply nested stack.
819
331
 
820
- * MySQL: schema.rb now includes TEXT and BLOB column limits.
332
+ Before:
821
333
 
822
- *Jeremy Kemper*
334
+ AnimalsRecord.connected_to(role: :reading) do
335
+ MealsRecord.connected_to(role: :reading) do
336
+ Dog.first # read from animals replica
337
+ Dinner.first # read from meals replica
338
+ Person.first # read from primary writer
339
+ end
340
+ end
823
341
 
824
- * MySQL: correct LONGTEXT and LONGBLOB limits from 2GB to their true 4GB.
342
+ After:
825
343
 
826
- *Jeremy Kemper*
344
+ ActiveRecord::Base.connected_to_many([AnimalsRecord, MealsRecord], role: :reading) do
345
+ Dog.first # read from animals replica
346
+ Dinner.first # read from meals replica
347
+ Person.first # read from primary writer
348
+ end
827
349
 
828
- * SQLite3Adapter now checks for views in `table_exists?`. Fixes #14041.
350
+ *Eileen M. Uchitelle*, *John Crepezzi*
829
351
 
830
- *Girish Sonawane*
352
+ * Add option to raise or log for `ActiveRecord::StrictLoadingViolationError`.
831
353
 
832
- * Introduce `connection.supports_views?` to check whether the current adapter
833
- has support for SQL views. Connection adapters should define this method.
354
+ Some applications may not want to raise an error in production if using `strict_loading`. This would allow an application to set strict loading to log for the production environment while still raising in development and test environments.
834
355
 
835
- *Yves Senn*
356
+ Set `config.active_record.action_on_strict_loading_violation` to `:log` errors instead of raising.
836
357
 
837
- * Allow included modules to override association methods.
358
+ *Eileen M. Uchitelle*
838
359
 
839
- Fixes #16684.
360
+ * Allow the inverse of a `has_one` association that was previously autosaved to be loaded.
840
361
 
841
- *Yves Senn*
362
+ Fixes #34255.
842
363
 
843
- * Schema loading rake tasks (like `db:schema:load` and `db:setup`) maintain
844
- the database connection to the current environment.
364
+ *Steven Weber*
845
365
 
846
- Fixes #16757.
366
+ * Optimise the length of index names for polymorphic references by using the reference name rather than the type and id column names.
847
367
 
848
- *Joshua Cody*, *Yves Senn*
368
+ Because the default behaviour when adding an index with multiple columns is to use all column names in the index name, this could frequently lead to overly long index names for polymorphic references which would fail the migration if it exceeded the database limit.
849
369
 
850
- * MySQL: set the connection collation along with the charset.
370
+ This change reduces the chance of that happening by using the reference name, e.g. `index_my_table_on_my_reference`.
851
371
 
852
- Sets the connection collation to the database collation configured in
853
- database.yml. Otherwise, `SET NAMES utf8mb4` will use the default
854
- collation for that charset (utf8mb4_general_ci) when you may have chosen
855
- a different collation, like utf8mb4_unicode_ci.
372
+ Fixes #38655.
856
373
 
857
- This only applies to literal string comparisons, not column values, so it
858
- is unlikely to affect you.
374
+ *Luke Redpath*
859
375
 
860
- *Jeremy Kemper*
376
+ * MySQL: Uniqueness validator now respects default database collation,
377
+ no longer enforce case sensitive comparison by default.
861
378
 
862
- * `default_sequence_name` from the PostgreSQL adapter returns a `String`.
379
+ *Ryuta Kamizono*
863
380
 
864
- *Yves Senn*
381
+ * Remove deprecated methods from `ActiveRecord::ConnectionAdapters::DatabaseLimits`.
865
382
 
866
- * Fix a regression where whitespaces were stripped from DISTINCT queries in
867
- PostgreSQL.
383
+ `column_name_length`
384
+ `table_name_length`
385
+ `columns_per_table`
386
+ `indexes_per_table`
387
+ `columns_per_multicolumn_index`
388
+ `sql_query_length`
389
+ `joins_per_query`
868
390
 
869
- *Agis Anastasopoulos*
391
+ *Rafael Mendonça França*
870
392
 
871
- Fixes #16623.
393
+ * Remove deprecated `ActiveRecord::ConnectionAdapters::AbstractAdapter#supports_multi_insert?`.
872
394
 
873
- * Fix has_many :through relation merging failing when dynamic conditions are
874
- passed as a lambda with an arity of one.
395
+ *Rafael Mendonça França*
875
396
 
876
- Fixes #16128.
397
+ * Remove deprecated `ActiveRecord::ConnectionAdapters::AbstractAdapter#supports_foreign_keys_in_create?`.
877
398
 
878
- *Agis Anastasopoulos*
399
+ *Rafael Mendonça França*
879
400
 
880
- * Fix `Relation#exists?` to work with polymorphic associations.
401
+ * Remove deprecated `ActiveRecord::ConnectionAdapters::PostgreSQLAdapter#supports_ranges?`.
881
402
 
882
- Fixes #15821.
403
+ *Rafael Mendonça França*
883
404
 
884
- *Kassio Borges*
405
+ * Remove deprecated `ActiveRecord::Base#update_attributes` and `ActiveRecord::Base#update_attributes!`.
885
406
 
886
- * Currently, Active Record rescues any errors raised within
887
- `after_rollback`/`after_create` callbacks and prints them to the logs.
888
- Future versions of Rails will not rescue these errors anymore and
889
- just bubble them up like the other callbacks.
407
+ *Rafael Mendonça França*
890
408
 
891
- This commit adds an opt-in flag to enable not rescuing the errors.
409
+ * Remove deprecated `migrations_path` argument in `ActiveRecord::ConnectionAdapter::SchemaStatements#assume_migrated_upto_version`.
892
410
 
893
- Example:
411
+ *Rafael Mendonça França*
894
412
 
895
- # Do not swallow errors in after_commit/after_rollback callbacks.
896
- config.active_record.raise_in_transactional_callbacks = true
413
+ * Remove deprecated `config.active_record.sqlite3.represent_boolean_as_integer`.
897
414
 
898
- Fixes #13460.
415
+ *Rafael Mendonça França*
899
416
 
900
- *arthurnn*
417
+ * `relation.create` does no longer leak scope to class level querying methods
418
+ in initialization block and callbacks.
901
419
 
902
- * Fix an issue where custom accessor methods (such as those generated by
903
- `enum`) with the same name as a global method are incorrectly overridden
904
- when subclassing.
420
+ Before:
905
421
 
906
- Fixes #16288.
422
+ User.where(name: "John").create do |john|
423
+ User.find_by(name: "David") # => nil
424
+ end
907
425
 
908
- *Godfrey Chan*
426
+ After:
909
427
 
910
- * `*_was` and `changes` now work correctly for in-place attribute changes as
911
- well.
428
+ User.where(name: "John").create do |john|
429
+ User.find_by(name: "David") # => #<User name: "David", ...>
430
+ end
912
431
 
913
- *Sean Griffin*
432
+ *Ryuta Kamizono*
914
433
 
915
- * Fix regression on `after_commit` that did not fire with nested transactions.
434
+ * Named scope chain does no longer leak scope to class level querying methods.
916
435
 
917
- Fixes #16425.
436
+ class User < ActiveRecord::Base
437
+ scope :david, -> { User.where(name: "David") }
438
+ end
918
439
 
919
- *arthurnn*
440
+ Before:
920
441
 
921
- * Do not try to write timestamps when a table has no timestamps columns.
442
+ User.where(name: "John").david
443
+ # SELECT * FROM users WHERE name = 'John' AND name = 'David'
922
444
 
923
- Fixes #8813.
445
+ After:
924
446
 
925
- *Sergey Potapov*
447
+ User.where(name: "John").david
448
+ # SELECT * FROM users WHERE name = 'David'
926
449
 
927
- * `index_exists?` with `:name` option does verify specified columns.
450
+ *Ryuta Kamizono*
928
451
 
929
- Example:
452
+ * Remove deprecated methods from `ActiveRecord::DatabaseConfigurations`.
930
453
 
931
- add_index :articles, :title, name: "idx_title"
454
+ `fetch`
455
+ `each`
456
+ `first`
457
+ `values`
458
+ `[]=`
932
459
 
933
- # Before:
934
- index_exists? :articles, :title, name: "idx_title" # => `true`
935
- index_exists? :articles, :body, name: "idx_title" # => `true`
460
+ *Rafael Mendonça França*
936
461
 
937
- # After:
938
- index_exists? :articles, :title, name: "idx_title" # => `true`
939
- index_exists? :articles, :body, name: "idx_title" # => `false`
462
+ * `where.not` now generates NAND predicates instead of NOR.
940
463
 
941
- *Yves Senn*, *Matthew Draper*
464
+ Before:
942
465
 
943
- * `add_timestamps` and `t.timestamps` now require you to pass the `:null` option.
944
- Not passing the option is deprecated but the default is still `null: true`.
945
- With Rails 5 this will change to `null: false`.
466
+ User.where.not(name: "Jon", role: "admin")
467
+ # SELECT * FROM users WHERE name != 'Jon' AND role != 'admin'
946
468
 
947
- *Sean Griffin*
469
+ After:
948
470
 
949
- * When calling `update_columns` on a record that is not persisted, the error
950
- message now reflects whether that object is a new record or has been
951
- destroyed.
471
+ User.where.not(name: "Jon", role: "admin")
472
+ # SELECT * FROM users WHERE NOT (name == 'Jon' AND role == 'admin')
952
473
 
953
- *Lachlan Sylvester*
474
+ *Rafael Mendonça França*
954
475
 
955
- * Define `id_was` to get the previous value of the primary key.
476
+ * Remove deprecated `ActiveRecord::Result#to_hash` method.
956
477
 
957
- Currently when we call `id_was` and we have a custom primary key name,
958
- Active Record will return the current value of the primary key. This
959
- makes it impossible to correctly do an update operation if you change the
960
- id.
478
+ *Rafael Mendonça França*
961
479
 
962
- Fixes #16413.
480
+ * Deprecate `ActiveRecord::Base.allow_unsafe_raw_sql`.
963
481
 
964
482
  *Rafael Mendonça França*
965
483
 
966
- * Deprecate `DatabaseTasks.load_schema` to act on the current connection.
967
- Use `.load_schema_current` instead. In the future `load_schema` will
968
- require the `configuration` to act on as an argument.
484
+ * Remove deprecated support for using unsafe raw SQL in `ActiveRecord::Relation` methods.
969
485
 
970
- *Yves Senn*
971
-
972
- * Fix automatic maintaining test schema to properly handle sql structure
973
- schema format.
486
+ *Rafael Mendonça França*
974
487
 
975
- Fixes #15394.
488
+ * Allow users to silence the "Rails couldn't infer whether you are using multiple databases..."
489
+ message using `config.active_record.suppress_multiple_database_warning`.
976
490
 
977
- *Wojciech Wnętrzak*
491
+ *Omri Gabay*
978
492
 
979
- * Fix type casting to Decimal from Float with large precision.
493
+ * Connections can be granularly switched for abstract classes when `connected_to` is called.
980
494
 
981
- *Tomohiro Hashidate*
495
+ This change allows `connected_to` to switch a `role` and/or `shard` for a single abstract class instead of all classes globally. Applications that want to use the new feature need to set `config.active_record.legacy_connection_handling` to `false` in their application configuration.
982
496
 
983
- * Deprecate `Reflection#source_macro`
497
+ Example usage:
984
498
 
985
- `Reflection#source_macro` is no longer needed in Active Record
986
- source so it has been deprecated. Code that used `source_macro`
987
- was removed in #16353.
499
+ Given an application we have a `User` model that inherits from `ApplicationRecord` and a `Dog` model that inherits from `AnimalsRecord`. `AnimalsRecord` and `ApplicationRecord` have writing and reading connections as well as shard `default`, `one`, and `two`.
988
500
 
989
- *Eileen M. Uchtitelle*, *Aaron Patterson*
501
+ ```ruby
502
+ ActiveRecord::Base.connected_to(role: :reading) do
503
+ User.first # reads from default replica
504
+ Dog.first # reads from default replica
990
505
 
991
- * No verbose backtrace by `db:drop` when database does not exist.
506
+ AnimalsRecord.connected_to(role: :writing, shard: :one) do
507
+ User.first # reads from default replica
508
+ Dog.first # reads from shard one primary
509
+ end
992
510
 
993
- Fixes #16295.
511
+ User.first # reads from default replica
512
+ Dog.first # reads from default replica
994
513
 
995
- *Kenn Ejima*
514
+ ApplicationRecord.connected_to(role: :writing, shard: :two) do
515
+ User.first # reads from shard two primary
516
+ Dog.first # reads from default replica
517
+ end
518
+ end
519
+ ```
996
520
 
997
- * Add support for PostgreSQL JSONB.
521
+ *Eileen M. Uchitelle*, *John Crepezzi*
998
522
 
999
- Example:
523
+ * Allow double-dash comment syntax when querying read-only databases
1000
524
 
1001
- create_table :posts do |t|
1002
- t.jsonb :meta_data
1003
- end
525
+ *James Adam*
1004
526
 
1005
- *Philippe Creux*, *Chris Teague*
527
+ * Add `values_at` method.
1006
528
 
1007
- * `db:purge` with MySQL respects `Rails.env`.
529
+ Returns an array containing the values associated with the given methods.
1008
530
 
1009
- *Yves Senn*
531
+ ```ruby
532
+ topic = Topic.first
533
+ topic.values_at(:title, :author_name)
534
+ # => ["Budget", "Jason"]
535
+ ```
1010
536
 
1011
- * `change_column_default :table, :column, nil` with PostgreSQL will issue a
1012
- `DROP DEFAULT` instead of a `DEFAULT NULL` query.
537
+ Similar to `Hash#values_at` but on an Active Record instance.
1013
538
 
1014
- Fixes #16261.
539
+ *Guillaume Briday*
1015
540
 
1016
- *Matthew Draper*, *Yves Senn*
541
+ * Fix `read_attribute_before_type_cast` to consider attribute aliases.
1017
542
 
1018
- * Allow to specify a type for the foreign key column in `references`
1019
- and `add_reference`.
543
+ *Marcelo Lauxen*
1020
544
 
1021
- Example:
545
+ * Support passing record to uniqueness validator `:conditions` callable:
1022
546
 
1023
- change_table :vehicle do |t|
1024
- t.references :station, type: :uuid
1025
- end
547
+ ```ruby
548
+ class Article < ApplicationRecord
549
+ validates_uniqueness_of :title, conditions: ->(article) {
550
+ published_at = article.published_at
551
+ where(published_at: published_at.beginning_of_year..published_at.end_of_year)
552
+ }
553
+ end
554
+ ```
1026
555
 
1027
- *Andrey Novikov*, *Łukasz Sarnacki*
556
+ *Eliot Sykes*
1028
557
 
1029
- * `create_join_table` removes a common prefix when generating the join table.
1030
- This matches the existing behavior of HABTM associations.
558
+ * `BatchEnumerator#update_all` and `BatchEnumerator#delete_all` now return the
559
+ total number of rows affected, just like their non-batched counterparts.
1031
560
 
1032
- Fixes #13683.
561
+ ```ruby
562
+ Person.in_batches.update_all("first_name = 'Eugene'") # => 42
563
+ Person.in_batches.delete_all # => 42
564
+ ```
1033
565
 
1034
- *Stefan Kanev*
566
+ Fixes #40287.
1035
567
 
1036
- * Do not swallow errors on `compute_type` when having a bad `alias_method` on
1037
- a class.
568
+ *Eugene Kenny*
1038
569
 
1039
- *arthurnn*
570
+ * Add support for PostgreSQL `interval` data type with conversion to
571
+ `ActiveSupport::Duration` when loading records from database and
572
+ serialization to ISO 8601 formatted duration string on save.
573
+ Add support to define a column in migrations and get it in a schema dump.
574
+ Optional column precision is supported.
1040
575
 
1041
- * PostgreSQL invalid `uuid` are convert to nil.
576
+ To use this in 6.1, you need to place the next string to your model file:
1042
577
 
1043
- *Abdelkader Boudih*
578
+ attribute :duration, :interval
1044
579
 
1045
- * Restore 4.0 behavior for using serialize attributes with `JSON` as coder.
580
+ To keep old behavior until 6.2 is released:
1046
581
 
1047
- With 4.1.x, `serialize` started returning a string when `JSON` was passed as
1048
- the second attribute. It will now return a hash as per previous versions.
582
+ attribute :duration, :string
1049
583
 
1050
584
  Example:
1051
585
 
1052
- class Post < ActiveRecord::Base
1053
- serialize :comment, JSON
586
+ create_table :events do |t|
587
+ t.string :name
588
+ t.interval :duration
1054
589
  end
1055
590
 
1056
- class Comment
1057
- include ActiveModel::Model
1058
- attr_accessor :category, :text
591
+ class Event < ApplicationRecord
592
+ attribute :duration, :interval
1059
593
  end
1060
594
 
1061
- post = Post.create!
1062
- post.comment = Comment.new(category: "Animals", text: "This is a comment about squirrels.")
1063
- post.save!
1064
-
1065
- # 4.0
1066
- post.comment # => {"category"=>"Animals", "text"=>"This is a comment about squirrels."}
1067
-
1068
- # 4.1 before
1069
- post.comment # => "#<Comment:0x007f80ab48ff98>"
1070
-
1071
- # 4.1 after
1072
- post.comment # => {"category"=>"Animals", "text"=>"This is a comment about squirrels."}
1073
-
1074
- When using `JSON` as the coder in `serialize`, Active Record will use the
1075
- new `ActiveRecord::Coders::JSON` coder which delegates its `dump/load` to
1076
- `ActiveSupport::JSON.encode/decode`. This ensures special objects are dumped
1077
- correctly using the `#as_json` hook.
595
+ Event.create!(name: 'Rock Fest', duration: 2.days)
596
+ Event.last.duration # => 2 days
597
+ Event.last.duration.iso8601 # => "P2D"
598
+ Event.new(duration: 'P1DT12H3S').duration # => 1 day, 12 hours, and 3 seconds
599
+ Event.new(duration: '1 day') # Unknown value will be ignored and NULL will be written to database
1078
600
 
1079
- To keep the previous behaviour, supply a custom coder instead
1080
- ([example](https://gist.github.com/jenncoop/8c4142bbe59da77daa63)).
1081
-
1082
- Fixes #15594.
1083
-
1084
- *Jenn Cooper*
1085
-
1086
- * Do not use `RENAME INDEX` syntax for MariaDB 10.0.
1087
-
1088
- Fixes #15931.
1089
-
1090
- *Jeff Browning*
1091
-
1092
- * Calling `#empty?` on a `has_many` association would use the value from the
1093
- counter cache if one exists.
601
+ *Andrey Novikov*
1094
602
 
1095
- *David Verhasselt*
603
+ * Allow associations supporting the `dependent:` key to take `dependent: :destroy_async`.
1096
604
 
1097
- * Fix the schema dump generated for tables without constraints and with
1098
- primary key with default value of custom PostgreSQL function result.
605
+ ```ruby
606
+ class Account < ActiveRecord::Base
607
+ belongs_to :supplier, dependent: :destroy_async
608
+ end
609
+ ```
1099
610
 
1100
- Fixes #16111.
611
+ `:destroy_async` will enqueue a job to destroy associated records in the background.
1101
612
 
1102
- *Andrey Novikov*
613
+ *DHH*, *George Claghorn*, *Cory Gwin*, *Rafael Mendonça França*, *Adrianna Chang*
1103
614
 
1104
- * Fix the SQL generated when a `delete_all` is run on an association to not
1105
- produce an `IN` statements.
615
+ * Add `SKIP_TEST_DATABASE` environment variable to disable modifying the test database when `rails db:create` and `rails db:drop` are called.
1106
616
 
1107
- Before:
617
+ *Jason Schweier*
1108
618
 
1109
- UPDATE "categorizations" SET "category_id" = NULL WHERE
1110
- "categorizations"."category_id" = 1 AND "categorizations"."id" IN (1, 2)
1111
-
1112
- After:
619
+ * `connects_to` can only be called on `ActiveRecord::Base` or abstract classes.
1113
620
 
1114
- UPDATE "categorizations" SET "category_id" = NULL WHERE
1115
- "categorizations"."category_id" = 1
621
+ Ensure that `connects_to` can only be called from `ActiveRecord::Base` or abstract classes. This protects the application from opening duplicate or too many connections.
1116
622
 
1117
- *Eileen M. Uchitelle, Aaron Patterson*
623
+ *Eileen M. Uchitelle*, *John Crepezzi*
1118
624
 
1119
- * Avoid type casting boolean and `ActiveSupport::Duration` values to numeric
1120
- values for string columns. Otherwise, in some database, the string column
1121
- values will be coerced to a numeric allowing false or 0.seconds match any
1122
- string starting with a non-digit.
625
+ * All connection adapters `execute` now raises `ActiveRecord::ConnectionNotEstablished` rather than
626
+ `ActiveRecord::StatementInvalid` when they encounter a connection error.
1123
627
 
1124
- Example:
628
+ *Jean Boussier*
1125
629
 
1126
- App.where(apikey: false) # => SELECT * FROM users WHERE apikey = '0'
630
+ * `Mysql2Adapter#quote_string` now raises `ActiveRecord::ConnectionNotEstablished` rather than
631
+ `ActiveRecord::StatementInvalid` when it can't connect to the MySQL server.
1127
632
 
1128
- *Dylan Thacker-Smith*
633
+ *Jean Boussier*
1129
634
 
1130
- * Add a `:required` option to singular associations, providing a nicer
1131
- API for presence validations on associations.
635
+ * Add support for check constraints that are `NOT VALID` via `validate: false` (PostgreSQL-only).
1132
636
 
1133
- *Sean Griffin*
637
+ *Alex Robbin*
1134
638
 
1135
- * Fix an error in `reset_counters` when associations have `select` scope.
1136
- (Call to `count` generated invalid SQL.)
639
+ * Ensure the default configuration is considered primary or first for an environment
1137
640
 
1138
- *Cade Truitt*
641
+ If a multiple database application provides a configuration named primary, that will be treated as default. In applications that do not have a primary entry, the default database configuration will be the first configuration for an environment.
1139
642
 
1140
- * After a successful `reload`, `new_record?` is always false.
643
+ *Eileen M. Uchitelle*
1141
644
 
1142
- Fixes #12101.
645
+ * Allow `where` references association names as joined table name aliases.
1143
646
 
1144
- *Matthew Draper*
647
+ ```ruby
648
+ class Comment < ActiveRecord::Base
649
+ enum label: [:default, :child]
650
+ has_many :children, class_name: "Comment", foreign_key: :parent_id
651
+ end
1145
652
 
1146
- * PostgreSQL renaming table doesn't attempt to rename non existent sequences.
653
+ # ... FROM comments LEFT OUTER JOIN comments children ON ... WHERE children.label = 1
654
+ Comment.includes(:children).where("children.label": "child")
655
+ ```
1147
656
 
1148
- *Abdelkader Boudih*
657
+ *Ryuta Kamizono*
1149
658
 
1150
- * Move 'dependent: :destroy' handling for `belongs_to`
1151
- from `before_destroy` to `after_destroy` callback chain
659
+ * Support storing demodulized class name for polymorphic type.
1152
660
 
1153
- Fixes #12380.
661
+ Before Rails 6.1, storing demodulized class name is supported only for STI type
662
+ by `store_full_sti_class` class attribute.
1154
663
 
1155
- *Ivan Antropov*
664
+ Now `store_full_class_name` class attribute can handle both STI and polymorphic types.
1156
665
 
1157
- * Detect in-place modifications on String attributes.
666
+ *Ryuta Kamizono*
1158
667
 
1159
- Before this change, an attribute modified in-place had to be marked as
1160
- changed in order for it to be persisted in the database. Now it is no longer
1161
- required.
668
+ * Deprecate `rails db:structure:{load, dump}` tasks and extend
669
+ `rails db:schema:{load, dump}` tasks to work with either `:ruby` or `:sql` format,
670
+ depending on `config.active_record.schema_format` configuration value.
1162
671
 
1163
- Before:
672
+ *fatkodima*
1164
673
 
1165
- user = User.first
1166
- user.name << ' Griffin'
1167
- user.name_will_change!
1168
- user.save
1169
- user.reload.name # => "Sean Griffin"
674
+ * Respect the `select` values for eager loading.
1170
675
 
1171
- After:
676
+ ```ruby
677
+ post = Post.select("UPPER(title) AS title").first
678
+ post.title # => "WELCOME TO THE WEBLOG"
679
+ post.body # => ActiveModel::MissingAttributeError
1172
680
 
1173
- user = User.first
1174
- user.name << ' Griffin'
1175
- user.save
1176
- user.reload.name # => "Sean Griffin"
681
+ # Rails 6.0 (ignore the `select` values)
682
+ post = Post.select("UPPER(title) AS title").eager_load(:comments).first
683
+ post.title # => "Welcome to the weblog"
684
+ post.body # => "Such a lovely day"
1177
685
 
1178
- *Sean Griffin*
686
+ # Rails 6.1 (respect the `select` values)
687
+ post = Post.select("UPPER(title) AS title").eager_load(:comments).first
688
+ post.title # => "WELCOME TO THE WEBLOG"
689
+ post.body # => ActiveModel::MissingAttributeError
690
+ ```
1179
691
 
1180
- * Add `ActiveRecord::Base#validate!` that raises `RecordInvalid` if the record
1181
- is invalid.
692
+ *Ryuta Kamizono*
1182
693
 
1183
- *Bogdan Gusiev*, *Marc Schütz*
694
+ * Allow attribute's default to be configured but keeping its own type.
1184
695
 
1185
- * Support for adding and removing foreign keys. Foreign keys are now
1186
- a part of `schema.rb`. This is supported by Mysql2Adapter, MysqlAdapter
1187
- and PostgreSQLAdapter.
696
+ ```ruby
697
+ class Post < ActiveRecord::Base
698
+ attribute :written_at, default: -> { Time.now.utc }
699
+ end
1188
700
 
1189
- Many thanks to *Matthew Higgins* for laying the foundation with his work on
1190
- [foreigner](https://github.com/matthuhiggins/foreigner).
701
+ # Rails 6.0
702
+ Post.type_for_attribute(:written_at) # => #<Type::Value ... precision: nil, ...>
1191
703
 
1192
- Example:
704
+ # Rails 6.1
705
+ Post.type_for_attribute(:written_at) # => #<Type::DateTime ... precision: 6, ...>
706
+ ```
1193
707
 
1194
- # within your migrations:
1195
- add_foreign_key :articles, :authors
1196
- remove_foreign_key :articles, :authors
708
+ *Ryuta Kamizono*
1197
709
 
1198
- *Yves Senn*
710
+ * Allow default to be configured for Enum.
1199
711
 
1200
- * Fix subtle bugs regarding attribute assignment on models with no primary
1201
- key. `'id'` will no longer be part of the attributes hash.
712
+ ```ruby
713
+ class Book < ActiveRecord::Base
714
+ enum status: [:proposed, :written, :published], _default: :published
715
+ end
1202
716
 
1203
- *Sean Griffin*
717
+ Book.new.status # => "published"
718
+ ```
1204
719
 
1205
- * Deprecate automatic counter caches on `has_many :through`. The behavior was
1206
- broken and inconsistent.
720
+ *Ryuta Kamizono*
1207
721
 
1208
- *Sean Griffin*
722
+ * Deprecate YAML loading from legacy format older than Rails 5.0.
1209
723
 
1210
- * `preload` preserves readonly flag for associations.
724
+ *Ryuta Kamizono*
1211
725
 
1212
- See #15853.
726
+ * Added the setting `ActiveRecord::Base.immutable_strings_by_default`, which
727
+ allows you to specify that all string columns should be frozen unless
728
+ otherwise specified. This will reduce memory pressure for applications which
729
+ do not generally mutate string properties of Active Record objects.
1213
730
 
1214
- *Yves Senn*
731
+ *Sean Griffin*, *Ryuta Kamizono*
1215
732
 
1216
- * Assume numeric types have changed if they were assigned to a value that
1217
- would fail numericality validation, regardless of the old value. Previously
1218
- this would only occur if the old value was 0.
733
+ * Deprecate `map!` and `collect!` on `ActiveRecord::Result`.
1219
734
 
1220
- Example:
735
+ *Ryuta Kamizono*
1221
736
 
1222
- model = Model.create!(number: 5)
1223
- model.number = '5wibble'
1224
- model.number_changed? # => true
737
+ * Support `relation.and` for intersection as Set theory.
1225
738
 
1226
- Fixes #14731.
739
+ ```ruby
740
+ david_and_mary = Author.where(id: [david, mary])
741
+ mary_and_bob = Author.where(id: [mary, bob])
1227
742
 
1228
- *Sean Griffin*
743
+ david_and_mary.merge(mary_and_bob) # => [mary, bob]
1229
744
 
1230
- * `reload` no longer merges with the existing attributes.
1231
- The attribute hash is fully replaced. The record is put into the same state
1232
- as it would be with `Model.find(model.id)`.
745
+ david_and_mary.and(mary_and_bob) # => [mary]
746
+ david_and_mary.or(mary_and_bob) # => [david, mary, bob]
747
+ ```
1233
748
 
1234
- *Sean Griffin*
749
+ *Ryuta Kamizono*
1235
750
 
1236
- * The object returned from `select_all` must respond to `column_types`.
1237
- If this is not the case a `NoMethodError` is raised.
751
+ * Merging conditions on the same column no longer maintain both conditions,
752
+ and will be consistently replaced by the latter condition in Rails 6.2.
753
+ To migrate to Rails 6.2's behavior, use `relation.merge(other, rewhere: true)`.
1238
754
 
1239
- *Sean Griffin*
755
+ ```ruby
756
+ # Rails 6.1 (IN clause is replaced by merger side equality condition)
757
+ Author.where(id: [david.id, mary.id]).merge(Author.where(id: bob)) # => [bob]
1240
758
 
1241
- * Detect in-place modifications of PG array types
759
+ # Rails 6.1 (both conflict conditions exists, deprecated)
760
+ Author.where(id: david.id..mary.id).merge(Author.where(id: bob)) # => []
1242
761
 
1243
- *Sean Griffin*
762
+ # Rails 6.1 with rewhere to migrate to Rails 6.2's behavior
763
+ Author.where(id: david.id..mary.id).merge(Author.where(id: bob), rewhere: true) # => [bob]
1244
764
 
1245
- * Add `bin/rake db:purge` task to empty the current database.
765
+ # Rails 6.2 (same behavior with IN clause, mergee side condition is consistently replaced)
766
+ Author.where(id: [david.id, mary.id]).merge(Author.where(id: bob)) # => [bob]
767
+ Author.where(id: david.id..mary.id).merge(Author.where(id: bob)) # => [bob]
768
+ ```
1246
769
 
1247
- *Yves Senn*
770
+ *Ryuta Kamizono*
1248
771
 
1249
- * Deprecate `serialized_attributes` without replacement.
772
+ * Do not mark Postgresql MAC address and UUID attributes as changed when the assigned value only varies by case.
1250
773
 
1251
- *Sean Griffin*
774
+ *Peter Fry*
1252
775
 
1253
- * Correctly extract IPv6 addresses from `DATABASE_URI`: the square brackets
1254
- are part of the URI structure, not the actual host.
776
+ * Resolve issue with insert_all unique_by option when used with expression index.
1255
777
 
1256
- Fixes #15705.
778
+ When the `:unique_by` option of `ActiveRecord::Persistence.insert_all` and
779
+ `ActiveRecord::Persistence.upsert_all` was used with the name of an expression index, an error
780
+ was raised. Adding a guard around the formatting behavior for the `:unique_by` corrects this.
1257
781
 
1258
- *Andy Bakun*, *Aaron Stone*
782
+ Usage:
1259
783
 
1260
- * Ensure both parent IDs are set on join records when both sides of a
1261
- through association are new.
784
+ ```ruby
785
+ create_table :books, id: :integer, force: true do |t|
786
+ t.column :name, :string
787
+ t.index "lower(name)", unique: true
788
+ end
1262
789
 
1263
- *Sean Griffin*
790
+ Book.insert_all [{ name: "MyTest" }], unique_by: :index_books_on_lower_name
791
+ ```
1264
792
 
1265
- * `ActiveRecord::Dirty` now detects in-place changes to mutable values.
1266
- Serialized attributes on ActiveRecord models will no longer save when
1267
- unchanged.
793
+ Fixes #39516.
1268
794
 
1269
- Fixes #8328.
795
+ *Austen Madden*
1270
796
 
1271
- *Sean Griffin*
797
+ * Add basic support for CHECK constraints to database migrations.
1272
798
 
1273
- * `Pluck` now works when selecting columns from different tables with the same
1274
- name.
799
+ Usage:
1275
800
 
1276
- Fixes #15649.
801
+ ```ruby
802
+ add_check_constraint :products, "price > 0", name: "price_check"
803
+ remove_check_constraint :products, name: "price_check"
804
+ ```
1277
805
 
1278
- *Sean Griffin*
806
+ *fatkodima*
1279
807
 
1280
- * Remove `cache_attributes` and friends. All attributes are cached.
808
+ * Add `ActiveRecord::Base.strict_loading_by_default` and `ActiveRecord::Base.strict_loading_by_default=`
809
+ to enable/disable strict_loading mode by default for a model. The configuration's value is
810
+ inheritable by subclasses, but they can override that value and it will not impact parent class.
1281
811
 
1282
- *Sean Griffin*
812
+ Usage:
1283
813
 
1284
- * Remove deprecated method `ActiveRecord::Base.quoted_locking_column`.
814
+ ```ruby
815
+ class Developer < ApplicationRecord
816
+ self.strict_loading_by_default = true
1285
817
 
1286
- *Akshay Vishnoi*
818
+ has_many :projects
819
+ end
1287
820
 
1288
- * `ActiveRecord::FinderMethods.find` with block can handle proc parameter as
1289
- `Enumerable#find` does.
821
+ dev = Developer.first
822
+ dev.projects.first
823
+ # => ActiveRecord::StrictLoadingViolationError Exception: Developer is marked as strict_loading and Project cannot be lazily loaded.
824
+ ```
1290
825
 
1291
- Fixes #15382.
826
+ *bogdanvlviv*
1292
827
 
1293
- *James Yang*
828
+ * Deprecate passing an Active Record object to `quote`/`type_cast` directly.
1294
829
 
1295
- * Make timezone aware attributes work with PostgreSQL array columns.
830
+ *Ryuta Kamizono*
1296
831
 
1297
- Fixes #13402.
832
+ * Default engine `ENGINE=InnoDB` is no longer dumped to make schema more agnostic.
1298
833
 
1299
- *Kuldeep Aggarwal*, *Sean Griffin*
834
+ Before:
1300
835
 
1301
- * `ActiveRecord::SchemaMigration` has no primary key regardless of the
1302
- `primary_key_prefix_type` configuration.
836
+ ```ruby
837
+ create_table "accounts", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci", force: :cascade do |t|
838
+ end
839
+ ```
1303
840
 
1304
- Fixes #15051.
841
+ After:
1305
842
 
1306
- *JoseLuis Torres*, *Yves Senn*
843
+ ```ruby
844
+ create_table "accounts", charset: "utf8mb4", collation: "utf8mb4_0900_ai_ci", force: :cascade do |t|
845
+ end
846
+ ```
1307
847
 
1308
- * `rake db:migrate:status` works with legacy migration numbers like `00018_xyz.rb`.
848
+ *Ryuta Kamizono*
1309
849
 
1310
- Fixes #15538.
850
+ * Added delegated type as an alternative to single-table inheritance for representing class hierarchies.
851
+ See ActiveRecord::DelegatedType for the full description.
1311
852
 
1312
- *Yves Senn*
853
+ *DHH*
1313
854
 
1314
- * Baseclass becomes! subclass.
855
+ * Deprecate aggregations with group by duplicated fields.
1315
856
 
1316
- Before this change, a record which changed its STI type, could not be
1317
- updated.
857
+ To migrate to Rails 6.2's behavior, use `uniq!(:group)` to deduplicate group fields.
1318
858
 
1319
- Fixes #14785.
859
+ ```ruby
860
+ accounts = Account.group(:firm_id)
1320
861
 
1321
- *Matthew Draper*, *Earl St Sauver*, *Edo Balvers*
862
+ # duplicated group fields, deprecated.
863
+ accounts.merge(accounts.where.not(credit_limit: nil)).sum(:credit_limit)
864
+ # => {
865
+ # [1, 1] => 50,
866
+ # [2, 2] => 60
867
+ # }
1322
868
 
1323
- * Remove deprecated `ActiveRecord::Migrator.proper_table_name`. Use the
1324
- `proper_table_name` instance method on `ActiveRecord::Migration` instead.
869
+ # use `uniq!(:group)` to deduplicate group fields.
870
+ accounts.merge(accounts.where.not(credit_limit: nil)).uniq!(:group).sum(:credit_limit)
871
+ # => {
872
+ # 1 => 50,
873
+ # 2 => 60
874
+ # }
875
+ ```
1325
876
 
1326
- *Akshay Vishnoi*
877
+ *Ryuta Kamizono*
1327
878
 
1328
- * Fix regression on eager loading association based on SQL query rather than
1329
- existing column.
879
+ * Deprecate duplicated query annotations.
1330
880
 
1331
- Fixes #15480.
881
+ To migrate to Rails 6.2's behavior, use `uniq!(:annotate)` to deduplicate query annotations.
1332
882
 
1333
- *Lauro Caetano*, *Carlos Antonio da Silva*
883
+ ```ruby
884
+ accounts = Account.where(id: [1, 2]).annotate("david and mary")
1334
885
 
1335
- * Deprecate returning `nil` from `column_for_attribute` when no column exists.
1336
- It will return a null object in Rails 5.0
886
+ # duplicated annotations, deprecated.
887
+ accounts.merge(accounts.rewhere(id: 3))
888
+ # SELECT accounts.* FROM accounts WHERE accounts.id = 3 /* david and mary */ /* david and mary */
1337
889
 
1338
- *Sean Griffin*
890
+ # use `uniq!(:annotate)` to deduplicate annotations.
891
+ accounts.merge(accounts.rewhere(id: 3)).uniq!(:annotate)
892
+ # SELECT accounts.* FROM accounts WHERE accounts.id = 3 /* david and mary */
893
+ ```
1339
894
 
1340
- * Implemented `ActiveRecord::Base#pretty_print` to work with PP.
895
+ *Ryuta Kamizono*
1341
896
 
1342
- *Ethan*
897
+ * Resolve conflict between counter cache and optimistic locking.
1343
898
 
1344
- * Preserve type when dumping PostgreSQL point, bit, bit varying and money
1345
- columns.
899
+ Bump an Active Record instance's lock version after updating its counter
900
+ cache. This avoids raising an unnecessary `ActiveRecord::StaleObjectError`
901
+ upon subsequent transactions by maintaining parity with the corresponding
902
+ database record's `lock_version` column.
1346
903
 
1347
- *Yves Senn*
904
+ Fixes #16449.
1348
905
 
1349
- * New records remain new after YAML serialization.
906
+ *Aaron Lipman*
1350
907
 
1351
- *Sean Griffin*
908
+ * Support merging option `:rewhere` to allow mergee side condition to be replaced exactly.
1352
909
 
1353
- * PostgreSQL support default values for enum types. Fixes #7814.
910
+ ```ruby
911
+ david_and_mary = Author.where(id: david.id..mary.id)
1354
912
 
1355
- *Yves Senn*
913
+ # both conflict conditions exists
914
+ david_and_mary.merge(Author.where(id: bob)) # => []
1356
915
 
1357
- * PostgreSQL `default_sequence_name` respects schema. Fixes #7516.
916
+ # mergee side condition is replaced by rewhere
917
+ david_and_mary.merge(Author.rewhere(id: bob)) # => [bob]
1358
918
 
1359
- *Yves Senn*
919
+ # mergee side condition is replaced by rewhere option
920
+ david_and_mary.merge(Author.where(id: bob), rewhere: true) # => [bob]
921
+ ```
1360
922
 
1361
- * Fix `columns_for_distinct` of PostgreSQL adapter to work correctly
1362
- with orders without sort direction modifiers.
923
+ *Ryuta Kamizono*
1363
924
 
1364
- *Nikolay Kondratyev*
925
+ * Add support for finding records based on signed ids, which are tamper-proof, verified ids that can be
926
+ set to expire and scoped with a purpose. This is particularly useful for things like password reset
927
+ or email verification, where you want the bearer of the signed id to be able to interact with the
928
+ underlying record, but usually only within a certain time period.
1365
929
 
1366
- * PostgreSQL `reset_pk_sequence!` respects schemas. Fixes #14719.
930
+ ```ruby
931
+ signed_id = User.first.signed_id expires_in: 15.minutes, purpose: :password_reset
1367
932
 
1368
- *Yves Senn*
933
+ User.find_signed signed_id # => nil, since the purpose does not match
1369
934
 
1370
- * Keep PostgreSQL `hstore` and `json` attributes as `Hash` in `@attributes`.
1371
- Fixes duplication in combination with `store_accessor`.
935
+ travel 16.minutes
936
+ User.find_signed signed_id, purpose: :password_reset # => nil, since the signed id has expired
1372
937
 
1373
- Fixes #15369.
938
+ travel_back
939
+ User.find_signed signed_id, purpose: :password_reset # => User.first
1374
940
 
1375
- *Yves Senn*
941
+ User.find_signed! "bad data" # => ActiveSupport::MessageVerifier::InvalidSignature
942
+ ```
1376
943
 
1377
- * `rake railties:install:migrations` respects the order of railties.
944
+ *DHH*
1378
945
 
1379
- *Arun Agrawal*
946
+ * Support `ALGORITHM = INSTANT` DDL option for index operations on MySQL.
1380
947
 
1381
- * Fix redefine a `has_and_belongs_to_many` inside inherited class
1382
- Fixing regression case, where redefining the same `has_and_belongs_to_many`
1383
- definition into a subclass would raise.
948
+ *Ryuta Kamizono*
1384
949
 
1385
- Fixes #14983.
950
+ * Fix index creation to preserve index comment in bulk change table on MySQL.
1386
951
 
1387
- *arthurnn*
952
+ *Ryuta Kamizono*
1388
953
 
1389
- * Fix `has_and_belongs_to_many` public reflection.
1390
- When defining a `has_and_belongs_to_many`, internally we convert that to two has_many.
1391
- But as `reflections` is a public API, people expect to see the right macro.
954
+ * Allow `unscope` to be aware of table name qualified values.
1392
955
 
1393
- Fixes #14682.
956
+ It is possible to unscope only the column in the specified table.
1394
957
 
1395
- *arthurnn*
958
+ ```ruby
959
+ posts = Post.joins(:comments).group(:"posts.hidden")
960
+ posts = posts.where("posts.hidden": false, "comments.hidden": false)
1396
961
 
1397
- * Fix serialization for records with an attribute named `format`.
962
+ posts.count
963
+ # => { false => 10 }
1398
964
 
1399
- Fixes #15188.
965
+ # unscope both hidden columns
966
+ posts.unscope(where: :hidden).count
967
+ # => { false => 11, true => 1 }
1400
968
 
1401
- *Godfrey Chan*
969
+ # unscope only comments.hidden column
970
+ posts.unscope(where: :"comments.hidden").count
971
+ # => { false => 11 }
972
+ ```
1402
973
 
1403
- * When a `group` is set, `sum`, `size`, `average`, `minimum` and `maximum`
1404
- on a NullRelation should return a Hash.
974
+ *Ryuta Kamizono*, *Slava Korolev*
1405
975
 
1406
- *Kuldeep Aggarwal*
976
+ * Fix `rewhere` to truly overwrite collided where clause by new where clause.
1407
977
 
1408
- * Fix serialized fields returning serialized data after being updated with
1409
- `update_column`.
978
+ ```ruby
979
+ steve = Person.find_by(name: "Steve")
980
+ david = Author.find_by(name: "David")
1410
981
 
1411
- *Simon Hørup Eskildsen*
982
+ relation = Essay.where(writer: steve)
1412
983
 
1413
- * Fix polymorphic eager loading when using a String as foreign key.
984
+ # Before
985
+ relation.rewhere(writer: david).to_a # => []
1414
986
 
1415
- Fixes #14734.
987
+ # After
988
+ relation.rewhere(writer: david).to_a # => [david]
989
+ ```
1416
990
 
1417
- *Lauro Caetano*
991
+ *Ryuta Kamizono*
1418
992
 
1419
- * Change belongs_to touch to be consistent with timestamp updates
993
+ * Inspect time attributes with subsec and time zone offset.
1420
994
 
1421
- If a model is set up with a belongs_to: touch relationship the parent
1422
- record will only be touched if the record was modified. This makes it
1423
- consistent with timestamp updating on the record itself.
995
+ ```ruby
996
+ p Knot.create
997
+ => #<Knot id: 1, created_at: "2016-05-05 01:29:47.116928000 +0000">
998
+ ```
1424
999
 
1425
- *Brock Trappitt*
1000
+ *akinomaeni*, *Jonathan Hefner*
1426
1001
 
1427
- * Fix the inferred table name of a `has_and_belongs_to_many` auxiliary
1428
- table inside a schema.
1002
+ * Deprecate passing a column to `type_cast`.
1429
1003
 
1430
- Fixes #14824.
1004
+ *Ryuta Kamizono*
1431
1005
 
1432
- *Eric Chahin*
1006
+ * Deprecate `in_clause_length` and `allowed_index_name_length` in `DatabaseLimits`.
1433
1007
 
1434
- * Remove unused `:timestamp` type. Transparently alias it to `:datetime`
1435
- in all cases. Fixes inconsistencies when column types are sent outside of
1436
- `ActiveRecord`, such as for XML Serialization.
1008
+ *Ryuta Kamizono*
1437
1009
 
1438
- *Sean Griffin*
1010
+ * Support bulk insert/upsert on relation to preserve scope values.
1439
1011
 
1440
- * Fix bug that added `table_name_prefix` and `table_name_suffix` to
1441
- extension names in PostgreSQL when migrating.
1012
+ *Josef Šimánek*, *Ryuta Kamizono*
1442
1013
 
1443
- *Joao Carlos*
1014
+ * Preserve column comment value on changing column name on MySQL.
1444
1015
 
1445
- * The `:index` option in migrations, which previously was only available for
1446
- `references`, now works with any column types.
1016
+ *Islam Taha*
1447
1017
 
1448
- *Marc Schütz*
1018
+ * Add support for `if_exists` option for removing an index.
1449
1019
 
1450
- * Add support for counter name to be passed as parameter on `CounterCache::ClassMethods#reset_counters`.
1020
+ The `remove_index` method can take an `if_exists` option. If this is set to true an error won't be raised if the index doesn't exist.
1451
1021
 
1452
- *jnormore*
1022
+ *Eileen M. Uchitelle*
1453
1023
 
1454
- * Restrict deletion of record when using `delete_all` with `uniq`, `group`, `having`
1455
- or `offset`.
1024
+ * Remove ibm_db, informix, mssql, oracle, and oracle12 Arel visitors which are not used in the code base.
1456
1025
 
1457
- In these cases the generated query ignored them and that caused unintended
1458
- records to be deleted.
1026
+ *Ryuta Kamizono*
1459
1027
 
1460
- Fixes #11985.
1028
+ * Prevent `build_association` from `touching` a parent record if the record isn't persisted for `has_one` associations.
1461
1029
 
1462
- *Leandro Facchinetti*
1030
+ Fixes #38219.
1463
1031
 
1464
- * Floats with limit >= 25 that get turned into doubles in MySQL no longer have
1465
- their limit dropped from the schema.
1032
+ *Josh Brody*
1466
1033
 
1467
- Fixes #14135.
1034
+ * Add support for `if_not_exists` option for adding index.
1468
1035
 
1469
- *Aaron Nelson*
1036
+ The `add_index` method respects `if_not_exists` option. If it is set to true
1037
+ index won't be added.
1470
1038
 
1471
- * Fix how to calculate associated class name when using namespaced `has_and_belongs_to_many`
1472
- association.
1039
+ Usage:
1473
1040
 
1474
- Fixes #14709.
1041
+ ```ruby
1042
+ add_index :users, :account_id, if_not_exists: true
1043
+ ```
1475
1044
 
1476
- *Kassio Borges*
1045
+ The `if_not_exists` option passed to `create_table` also gets propagated to indexes
1046
+ created within that migration so that if table and its indexes exist then there is no
1047
+ attempt to create them again.
1477
1048
 
1478
- * `ActiveRecord::Relation::Merger#filter_binds` now compares equivalent symbols and
1479
- strings in column names as equal.
1049
+ *Prathamesh Sonpatki*
1480
1050
 
1481
- This fixes a rare case in which more bind values are passed than there are
1482
- placeholders for them in the generated SQL statement, which can make PostgreSQL
1483
- throw a `StatementInvalid` exception.
1051
+ * Add `ActiveRecord::Base#previously_new_record?` to show if a record was new before the last save.
1484
1052
 
1485
- *Nat Budin*
1053
+ *Tom Ward*
1486
1054
 
1487
- * Fix `stored_attributes` to correctly merge the details of stored
1488
- attributes defined in parent classes.
1055
+ * Support descending order for `find_each`, `find_in_batches`, and `in_batches`.
1489
1056
 
1490
- Fixes #14672.
1057
+ Batch processing methods allow you to work with the records in batches, greatly reducing memory consumption, but records are always batched from oldest id to newest.
1491
1058
 
1492
- *Brad Bennett*, *Jessica Yao*, *Lakshmi Parthasarathy*
1059
+ This change allows reversing the order, batching from newest to oldest. This is useful when you need to process newer batches of records first.
1493
1060
 
1494
- * `change_column_default` allows `[]` as argument to `change_column_default`.
1061
+ Pass `order: :desc` to yield batches in descending order. The default remains `order: :asc`.
1495
1062
 
1496
- Fixes #11586.
1063
+ ```ruby
1064
+ Person.find_each(order: :desc) do |person|
1065
+ person.party_all_night!
1066
+ end
1067
+ ```
1497
1068
 
1498
- *Yves Senn*
1069
+ *Alexey Vasiliev*
1499
1070
 
1500
- * Handle `name` and `"char"` column types in the PostgreSQL adapter.
1071
+ * Fix `insert_all` with enum values.
1501
1072
 
1502
- `name` and `"char"` are special character types used internally by
1503
- PostgreSQL and are used by internal system catalogs. These field types
1504
- can sometimes show up in structure-sniffing queries that feature internal system
1505
- structures or with certain PostgreSQL extensions.
1073
+ Fixes #38716.
1506
1074
 
1507
- *J Smith*, *Yves Senn*
1075
+ *Joel Blum*
1508
1076
 
1509
- * Fix `PostgreSQLAdapter::OID::Float#type_cast` to convert Infinity and
1510
- NaN PostgreSQL values into a native Ruby `Float::INFINITY` and `Float::NAN`
1077
+ * Add support for `db:rollback:name` for multiple database applications.
1511
1078
 
1512
- Before:
1079
+ Multiple database applications will now raise if `db:rollback` is call and recommend using the `db:rollback:[NAME]` to rollback migrations.
1513
1080
 
1514
- Point.create(value: 1.0/0)
1515
- Point.last.value # => 0.0
1081
+ *Eileen M. Uchitelle*
1516
1082
 
1517
- After:
1083
+ * `Relation#pick` now uses already loaded results instead of making another query.
1518
1084
 
1519
- Point.create(value: 1.0/0)
1520
- Point.last.value # => Infinity
1085
+ *Eugene Kenny*
1521
1086
 
1522
- *Innokenty Mikhailov*
1087
+ * Deprecate using `return`, `break` or `throw` to exit a transaction block after writes.
1523
1088
 
1524
- * Allow the PostgreSQL adapter to handle bigserial primary key types again.
1089
+ *Dylan Thacker-Smith*
1525
1090
 
1526
- Fixes #10410.
1091
+ * Dump the schema or structure of a database when calling `db:migrate:name`.
1527
1092
 
1528
- *Patrick Robertson*
1093
+ In previous versions of Rails, `rails db:migrate` would dump the schema of the database. In Rails 6, that holds true (`rails db:migrate` dumps all databases' schemas), but `rails db:migrate:name` does not share that behavior.
1529
1094
 
1530
- * Deprecate joining, eager loading and preloading of instance dependent
1531
- associations without replacement. These operations happen before instances
1532
- are created. The current behavior is unexpected and can result in broken
1533
- behavior.
1095
+ Going forward, calls to `rails db:migrate:name` will dump the schema (or structure) of the database being migrated.
1534
1096
 
1535
- Fixes #15024.
1097
+ *Kyle Thompson*
1536
1098
 
1537
- *Yves Senn*
1099
+ * Reset the `ActiveRecord::Base` connection after `rails db:migrate:name`.
1538
1100
 
1539
- * Fix `has_and_belongs_to_many` CollectionAssociation size calculations.
1101
+ When `rails db:migrate` has finished, it ensures the `ActiveRecord::Base` connection is reset to its original configuration. Going forward, `rails db:migrate:name` will have the same behavior.
1540
1102
 
1541
- `has_and_belongs_to_many` should fall back to using the normal CollectionAssociation's
1542
- size calculation if the collection is not cached or loaded.
1103
+ *Kyle Thompson*
1543
1104
 
1544
- Fixes #14913, #14914.
1105
+ * Disallow calling `connected_to` on subclasses of `ActiveRecord::Base`.
1545
1106
 
1546
- *Fred Wu*
1107
+ Behavior has not changed here but the previous API could be misleading to people who thought it would switch connections for only that class. `connected_to` switches the context from which we are getting connections, not the connections themselves.
1547
1108
 
1548
- * Return a non zero status when running `rake db:migrate:status` and migration table does
1549
- not exist.
1109
+ *Eileen M. Uchitelle*, *John Crepezzi*
1550
1110
 
1551
- *Paul B.*
1111
+ * Add support for horizontal sharding to `connects_to` and `connected_to`.
1552
1112
 
1553
- * Add support for module-level `table_name_suffix` in models.
1113
+ Applications can now connect to multiple shards and switch between their shards in an application. Note that the shard swapping is still a manual process as this change does not include an API for automatic shard swapping.
1554
1114
 
1555
- This makes `table_name_suffix` work the same way as `table_name_prefix` when
1556
- using namespaced models.
1115
+ Usage:
1557
1116
 
1558
- *Jenner LaFave*
1117
+ Given the following configuration:
1559
1118
 
1560
- * Revert the behaviour of `ActiveRecord::Relation#join` changed through 4.0 => 4.1 to 4.0.
1119
+ ```yaml
1120
+ # config/database.yml
1121
+ production:
1122
+ primary:
1123
+ database: my_database
1124
+ primary_shard_one:
1125
+ database: my_database_shard_one
1126
+ ```
1561
1127
 
1562
- In 4.1.0 `Relation#join` is delegated to `Arel#SelectManager`.
1563
- In 4.0 series it is delegated to `Array#join`.
1128
+ Connect to multiple shards:
1564
1129
 
1565
- *Bogdan Gusiev*
1130
+ ```ruby
1131
+ class ApplicationRecord < ActiveRecord::Base
1132
+ self.abstract_class = true
1566
1133
 
1567
- * Log nil binary column values correctly.
1134
+ connects_to shards: {
1135
+ default: { writing: :primary },
1136
+ shard_one: { writing: :primary_shard_one }
1137
+ }
1138
+ ```
1568
1139
 
1569
- When an object with a binary column is updated with a nil value
1570
- in that column, the SQL logger would throw an exception when trying
1571
- to log that nil value. This only occurs when updating a record
1572
- that already has a non-nil value in that column since an initial nil
1573
- value isn't included in the SQL anyway (at least, when dirty checking
1574
- is enabled.) The column's new value will now be logged as `<NULL binary data>`
1575
- to parallel the existing `<N bytes of binary data>` for non-nil values.
1140
+ Swap between shards in your controller / model code:
1576
1141
 
1577
- *James Coleman*
1142
+ ```ruby
1143
+ ActiveRecord::Base.connected_to(shard: :shard_one) do
1144
+ # Read from shard one
1145
+ end
1146
+ ```
1578
1147
 
1579
- * Rails will now pass a custom validation context through to autosave associations
1580
- in order to validate child associations with the same context.
1148
+ The horizontal sharding API also supports read replicas. See guides for more details.
1581
1149
 
1582
- Fixes #13854.
1150
+ *Eileen M. Uchitelle*, *John Crepezzi*
1583
1151
 
1584
- *Eric Chahin*, *Aaron Nelson*, *Kevin Casey*
1152
+ * Deprecate `spec_name` in favor of `name` on database configurations.
1585
1153
 
1586
- * Stringify all variables keys of MySQL connection configuration.
1154
+ The accessors for `spec_name` on `configs_for` and `DatabaseConfig` are deprecated. Please use `name` instead.
1587
1155
 
1588
- When `sql_mode` variable for MySQL adapters set in configuration as `String`
1589
- was ignored and overwritten by strict mode option.
1156
+ Deprecated behavior:
1590
1157
 
1591
- Fixes #14895.
1158
+ ```ruby
1159
+ db_config = ActiveRecord::Base.configurations.configs_for(env_name: "development", spec_name: "primary")
1160
+ db_config.spec_name
1161
+ ```
1592
1162
 
1593
- *Paul Nikitochkin*
1163
+ New behavior:
1594
1164
 
1595
- * Ensure SQLite3 statements are closed on errors.
1165
+ ```ruby
1166
+ db_config = ActiveRecord::Base.configurations.configs_for(env_name: "development", name: "primary")
1167
+ db_config.name
1168
+ ```
1596
1169
 
1597
- Fixes #13631.
1170
+ *Eileen M. Uchitelle*
1598
1171
 
1599
- *Timur Alperovich*
1172
+ * Add additional database-specific rake tasks for multi-database users.
1600
1173
 
1601
- * Give `ActiveRecord::PredicateBuilder` private methods the privacy they deserve.
1174
+ Previously, `rails db:create`, `rails db:drop`, and `rails db:migrate` were the only rails tasks that could operate on a single
1175
+ database. For example:
1602
1176
 
1603
- *Hector Satre*
1177
+ ```
1178
+ rails db:create
1179
+ rails db:create:primary
1180
+ rails db:create:animals
1181
+ rails db:drop
1182
+ rails db:drop:primary
1183
+ rails db:drop:animals
1184
+ rails db:migrate
1185
+ rails db:migrate:primary
1186
+ rails db:migrate:animals
1187
+ ```
1604
1188
 
1605
- * When using a custom `join_table` name on a `habtm`, rails was not saving it
1606
- on Reflections. This causes a problem when rails loads fixtures, because it
1607
- uses the reflections to set database with fixtures.
1189
+ With these changes, `rails db:schema:dump`, `rails db:schema:load`, `rails db:structure:dump`, `rails db:structure:load` and
1190
+ `rails db:test:prepare` can additionally operate on a single database. For example:
1608
1191
 
1609
- Fixes #14845.
1192
+ ```
1193
+ rails db:schema:dump
1194
+ rails db:schema:dump:primary
1195
+ rails db:schema:dump:animals
1196
+ rails db:schema:load
1197
+ rails db:schema:load:primary
1198
+ rails db:schema:load:animals
1199
+ rails db:structure:dump
1200
+ rails db:structure:dump:primary
1201
+ rails db:structure:dump:animals
1202
+ rails db:structure:load
1203
+ rails db:structure:load:primary
1204
+ rails db:structure:load:animals
1205
+ rails db:test:prepare
1206
+ rails db:test:prepare:primary
1207
+ rails db:test:prepare:animals
1208
+ ```
1610
1209
 
1611
- *Kassio Borges*
1210
+ *Kyle Thompson*
1612
1211
 
1613
- * Reset the cache when modifying a Relation with cached Arel.
1614
- Additionally display a warning message to make the user aware.
1212
+ * Add support for `strict_loading` mode on association declarations.
1615
1213
 
1616
- *Yves Senn*
1214
+ Raise an error if attempting to load a record from an association that has been marked as `strict_loading` unless it was explicitly eager loaded.
1617
1215
 
1618
- * PostgreSQL should internally use `:datetime` consistently for TimeStamp. Assures
1619
- different spellings of timestamps are treated the same.
1216
+ Usage:
1620
1217
 
1621
- Example:
1218
+ ```ruby
1219
+ class Developer < ApplicationRecord
1220
+ has_many :projects, strict_loading: true
1221
+ end
1622
1222
 
1623
- mytimestamp.simplified_type('timestamp without time zone')
1624
- # => :datetime
1625
- mytimestamp.simplified_type('timestamp(6) without time zone')
1626
- # => also :datetime (previously would be :timestamp)
1223
+ dev = Developer.first
1224
+ dev.projects.first
1225
+ # => ActiveRecord::StrictLoadingViolationError: The projects association is marked as strict_loading and cannot be lazily loaded.
1226
+ ```
1627
1227
 
1628
- See #14513.
1228
+ *Kevin Deisz*
1629
1229
 
1630
- *Jefferson Lai*
1230
+ * Add support for `strict_loading` mode to prevent lazy loading of records.
1631
1231
 
1632
- * `ActiveRecord::Base.no_touching` no longer triggers callbacks or start empty transactions.
1232
+ Raise an error if a parent record is marked as `strict_loading` and attempts to lazily load its associations. This is useful for finding places you may want to preload an association and avoid additional queries.
1633
1233
 
1634
- Fixes #14841.
1234
+ Usage:
1635
1235
 
1636
- *Lucas Mazza*
1236
+ ```ruby
1237
+ dev = Developer.strict_loading.first
1238
+ dev.audit_logs.to_a
1239
+ # => ActiveRecord::StrictLoadingViolationError: Developer is marked as strict_loading and AuditLog cannot be lazily loaded.
1240
+ ```
1637
1241
 
1638
- * Fix name collision with `Array#select!` with `Relation#select!`.
1242
+ *Eileen M. Uchitelle*, *Aaron Patterson*
1639
1243
 
1640
- Fixes #14752.
1244
+ * Add support for PostgreSQL 11+ partitioned indexes when using `upsert_all`.
1641
1245
 
1642
- *Earl St Sauver*
1246
+ *Sebastián Palma*
1643
1247
 
1644
- * Fix unexpected behavior for `has_many :through` associations going through
1645
- a scoped `has_many`.
1248
+ * Adds support for `if_not_exists` to `add_column` and `if_exists` to `remove_column`.
1646
1249
 
1647
- If a `has_many` association is adjusted using a scope, and another
1648
- `has_many :through` uses this association, then the scope adjustment is
1649
- unexpectedly neglected.
1250
+ Applications can set their migrations to ignore exceptions raised when adding a column that already exists or when removing a column that does not exist.
1650
1251
 
1651
- Fixes #14537.
1252
+ Example Usage:
1652
1253
 
1653
- *Jan Habermann*
1254
+ ```ruby
1255
+ class AddColumnTitle < ActiveRecord::Migration[6.1]
1256
+ def change
1257
+ add_column :posts, :title, :string, if_not_exists: true
1258
+ end
1259
+ end
1260
+ ```
1654
1261
 
1655
- * `@destroyed` should always be set to `false` when an object is duped.
1262
+ ```ruby
1263
+ class RemoveColumnTitle < ActiveRecord::Migration[6.1]
1264
+ def change
1265
+ remove_column :posts, :title, if_exists: true
1266
+ end
1267
+ end
1268
+ ```
1656
1269
 
1657
- *Kuldeep Aggarwal*
1270
+ *Eileen M. Uchitelle*
1658
1271
 
1659
- * Enable `has_many` associations to support irregular inflections.
1272
+ * Regexp-escape table name for MS SQL Server.
1660
1273
 
1661
- Fixes #8928.
1274
+ Add `Regexp.escape` to one method in ActiveRecord, so that table names with regular expression characters in them work as expected. Since MS SQL Server uses "[" and "]" to quote table and column names, and those characters are regular expression characters, methods like `pluck` and `select` fail in certain cases when used with the MS SQL Server adapter.
1662
1275
 
1663
- *arthurnn*, *Javier Goizueta*
1276
+ *Larry Reid*
1664
1277
 
1665
- * Fix `count` used with a grouping not returning a Hash.
1278
+ * Store advisory locks on their own named connection.
1666
1279
 
1667
- Fixes #14721.
1280
+ Previously advisory locks were taken out against a connection when a migration started. This works fine in single database applications but doesn't work well when migrations need to open new connections which results in the lock getting dropped.
1668
1281
 
1669
- *Eric Chahin*
1282
+ In order to fix this we are storing the advisory lock on a new connection with the connection specification name `AdvisoryLockBase`. The caveat is that we need to maintain at least 2 connections to a database while migrations are running in order to do this.
1670
1283
 
1671
- * `sanitize_sql_like` helper method to escape a string for safe use in an SQL
1672
- LIKE statement.
1284
+ *Eileen M. Uchitelle*, *John Crepezzi*
1673
1285
 
1674
- Example:
1286
+ * Allow schema cache path to be defined in the database configuration file.
1675
1287
 
1676
- class Article
1677
- def self.search(term)
1678
- where("title LIKE ?", sanitize_sql_like(term))
1679
- end
1680
- end
1288
+ For example:
1681
1289
 
1682
- Article.search("20% _reduction_")
1683
- # => Query looks like "... title LIKE '20\% \_reduction\_' ..."
1290
+ ```yaml
1291
+ development:
1292
+ adapter: postgresql
1293
+ database: blog_development
1294
+ pool: 5
1295
+ schema_cache_path: tmp/schema/main.yml
1296
+ ```
1684
1297
 
1685
- *Rob Gilson*, *Yves Senn*
1298
+ *Katrina Owen*
1686
1299
 
1687
- * Do not quote uuid default value on `change_column`.
1300
+ * Deprecate `#remove_connection` in favor of `#remove_connection_pool` when called on the handler.
1688
1301
 
1689
- Fixes #14604.
1302
+ `#remove_connection` is deprecated in order to support returning a `DatabaseConfig` object instead of a `Hash`. Use `#remove_connection_pool`, `#remove_connection` will be removed in 6.2.
1690
1303
 
1691
- *Eric Chahin*
1304
+ *Eileen M. Uchitelle*, *John Crepezzi*
1692
1305
 
1693
- * The comparison between `Relation` and `CollectionProxy` should be consistent.
1306
+ * Deprecate `#default_hash` and it's alias `#[]` on database configurations.
1694
1307
 
1695
- Example:
1308
+ Applications should use `configs_for`. `#default_hash` and `#[]` will be removed in 6.2.
1696
1309
 
1697
- author.posts == Post.where(author_id: author.id)
1698
- # => true
1699
- Post.where(author_id: author.id) == author.posts
1700
- # => true
1310
+ *Eileen M. Uchitelle*, *John Crepezzi*
1701
1311
 
1702
- Fixes #13506.
1312
+ * Add scale support to `ActiveRecord::Validations::NumericalityValidator`.
1703
1313
 
1704
- *Lauro Caetano*
1314
+ *Gannon McGibbon*
1705
1315
 
1706
- * Calling `delete_all` on an unloaded `CollectionProxy` no longer
1707
- generates an SQL statement containing each id of the collection:
1316
+ * Find orphans by looking for missing relations through chaining `where.missing`:
1708
1317
 
1709
1318
  Before:
1710
1319
 
1711
- DELETE FROM `model` WHERE `model`.`parent_id` = 1
1712
- AND `model`.`id` IN (1, 2, 3...)
1320
+ ```ruby
1321
+ Post.left_joins(:author).where(authors: { id: nil })
1322
+ ```
1713
1323
 
1714
1324
  After:
1715
1325
 
1716
- DELETE FROM `model` WHERE `model`.`parent_id` = 1
1717
-
1718
- *Eileen M. Uchitelle*, *Aaron Patterson*
1719
-
1720
- * Fix invalid SQL when aggregate methods (`empty?`, `any?`, `count`) used
1721
- with `select`.
1722
-
1723
- Fixes #13648.
1724
-
1725
- *Simon Woker*
1726
-
1727
- * PostgreSQL adapter only warns once for every missing OID per connection.
1326
+ ```ruby
1327
+ Post.where.missing(:author)
1328
+ ```
1728
1329
 
1729
- Fixes #14275.
1330
+ *Tom Rossi*
1730
1331
 
1731
- *Matthew Draper*, *Yves Senn*
1332
+ * Ensure `:reading` connections always raise if a write is attempted.
1732
1333
 
1733
- * PostgreSQL adapter automatically reloads it's type map when encountering
1734
- unknown OIDs.
1334
+ Now Rails will raise an `ActiveRecord::ReadOnlyError` if any connection on the reading handler attempts to make a write. If your reading role needs to write you should name the role something other than `:reading`.
1735
1335
 
1736
- Fixes #14678.
1336
+ *Eileen M. Uchitelle*
1737
1337
 
1738
- *Matthew Draper*, *Yves Senn*
1338
+ * Deprecate `"primary"` as the `connection_specification_name` for `ActiveRecord::Base`.
1739
1339
 
1740
- * Fix insertion of records via `has_many :through` association with scope.
1340
+ `"primary"` has been deprecated as the `connection_specification_name` for `ActiveRecord::Base` in favor of using `"ActiveRecord::Base"`. This change affects calls to `ActiveRecord::Base.connection_handler.retrieve_connection` and `ActiveRecord::Base.connection_handler.remove_connection`. If you're calling these methods with `"primary"`, please switch to `"ActiveRecord::Base"`.
1741
1341
 
1742
- Fixes #3548.
1342
+ *Eileen M. Uchitelle*, *John Crepezzi*
1743
1343
 
1744
- *Ivan Antropov*
1344
+ * Add `ActiveRecord::Validations::NumericalityValidator` with
1345
+ support for casting floats using a database columns' precision value.
1745
1346
 
1746
- * Auto-generate stable fixture UUIDs on PostgreSQL.
1347
+ *Gannon McGibbon*
1747
1348
 
1748
- Fixes #11524.
1349
+ * Enforce fresh ETag header after a collection's contents change by adding
1350
+ ActiveRecord::Relation#cache_key_with_version. This method will be used by
1351
+ ActionController::ConditionalGet to ensure that when collection cache versioning
1352
+ is enabled, requests using ConditionalGet don't return the same ETag header
1353
+ after a collection is modified.
1749
1354
 
1750
- *Roderick van Domburg*
1355
+ Fixes #38078.
1751
1356
 
1752
- * Fix a problem where an enum would overwrite values of another enum with the
1753
- same name in an unrelated class.
1357
+ *Aaron Lipman*
1754
1358
 
1755
- Fixes #14607.
1359
+ * Skip test database when running `db:create` or `db:drop` in development
1360
+ with `DATABASE_URL` set.
1756
1361
 
1757
- *Evan Whalen*
1362
+ *Brian Buchalter*
1758
1363
 
1759
- * PostgreSQL and SQLite string columns no longer have a default limit of 255.
1364
+ * Don't allow mutations on the database configurations hash.
1760
1365
 
1761
- Fixes #13435, #9153.
1366
+ Freeze the configurations hash to disallow directly changing it. If applications need to change the hash, for example to create databases for parallelization, they should use the `DatabaseConfig` object directly.
1762
1367
 
1763
- *Vladimir Sazhin*, *Toms Mikoss*, *Yves Senn*
1368
+ Before:
1764
1369
 
1765
- * Make possible to have an association called `records`.
1370
+ ```ruby
1371
+ @db_config = ActiveRecord::Base.configurations.configs_for(env_name: "test", spec_name: "primary")
1372
+ @db_config.configuration_hash.merge!(idle_timeout: "0.02")
1373
+ ```
1766
1374
 
1767
- Fixes #11645.
1375
+ After:
1768
1376
 
1769
- *prathamesh-sonpatki*
1377
+ ```ruby
1378
+ @db_config = ActiveRecord::Base.configurations.configs_for(env_name: "test", spec_name: "primary")
1379
+ config = @db_config.configuration_hash.merge(idle_timeout: "0.02")
1380
+ db_config = ActiveRecord::DatabaseConfigurations::HashConfig.new(@db_config.env_name, @db_config.spec_name, config)
1381
+ ```
1770
1382
 
1771
- * `to_sql` on an association now matches the query that is actually executed, where it
1772
- could previously have incorrectly accrued additional conditions (e.g. as a result of
1773
- a previous query). `CollectionProxy` now always defers to the association scope's
1774
- `arel` method so the (incorrect) inherited one should be entirely concealed.
1383
+ *Eileen M. Uchitelle*, *John Crepezzi*
1775
1384
 
1776
- Fixes #14003.
1385
+ * Remove `:connection_id` from the `sql.active_record` notification.
1777
1386
 
1778
- *Jefferson Lai*
1387
+ *Aaron Patterson*, *Rafael Mendonça França*
1779
1388
 
1780
- * Block a few default Class methods as scope name.
1389
+ * The `:name` key will no longer be returned as part of `DatabaseConfig#configuration_hash`. Please use `DatabaseConfig#owner_name` instead.
1781
1390
 
1782
- For instance, this will raise:
1391
+ *Eileen M. Uchitelle*, *John Crepezzi*
1783
1392
 
1784
- scope :public, -> { where(status: 1) }
1393
+ * ActiveRecord's `belongs_to_required_by_default` flag can now be set per model.
1785
1394
 
1786
- *arthurnn*
1395
+ You can now opt-out/opt-in specific models from having their associations required
1396
+ by default.
1787
1397
 
1788
- * Fix error when using `with_options` with lambda.
1398
+ This change is meant to ease the process of migrating all your models to have
1399
+ their association required.
1789
1400
 
1790
- Fixes #9805.
1401
+ *Edouard Chin*
1791
1402
 
1792
- *Lauro Caetano*
1403
+ * The `connection_config` method has been deprecated, please use `connection_db_config` instead which will return a `DatabaseConfigurations::DatabaseConfig` instead of a `Hash`.
1793
1404
 
1794
- * Switch `sqlite3:///` URLs (which were temporarily
1795
- deprecated in 4.1) from relative to absolute.
1405
+ *Eileen M. Uchitelle*, *John Crepezzi*
1796
1406
 
1797
- If you still want the previous interpretation, you should replace
1798
- `sqlite3:///my/path` with `sqlite3:my/path`.
1407
+ * Retain explicit selections on the base model after applying `includes` and `joins`.
1799
1408
 
1800
- *Matthew Draper*
1409
+ Resolves #34889.
1801
1410
 
1802
- * Treat blank UUID values as `nil`.
1411
+ *Patrick Rebsch*
1803
1412
 
1804
- Example:
1413
+ * The `database` kwarg is deprecated without replacement because it can't be used for sharding and creates an issue if it's used during a request. Applications that need to create new connections should use `connects_to` instead.
1805
1414
 
1806
- Sample.new(uuid_field: '') #=> <Sample id: nil, uuid_field: nil>
1415
+ *Eileen M. Uchitelle*, *John Crepezzi*
1807
1416
 
1808
- *Dmitry Lavrov*
1417
+ * Allow attributes to be fetched from Arel node groupings.
1809
1418
 
1810
- * Enable support for materialized views on PostgreSQL >= 9.3.
1419
+ *Jeff Emminger*, *Gannon McGibbon*
1811
1420
 
1812
- *Dave Lee*
1421
+ * A database URL can now contain a querystring value that contains an equal sign. This is needed to support passing PostgreSQL `options`.
1813
1422
 
1814
- * The PostgreSQL adapter supports custom domains. Fixes #14305.
1423
+ *Joshua Flanagan*
1815
1424
 
1816
- *Yves Senn*
1425
+ * Calling methods like `establish_connection` with a `Hash` which is invalid (eg: no `adapter`) will now raise an error the same way as connections defined in `config/database.yml`.
1817
1426
 
1818
- * PostgreSQL `Column#type` is now determined through the corresponding OID.
1819
- The column types stay the same except for enum columns. They no longer have
1820
- `nil` as type but `enum`.
1427
+ *John Crepezzi*
1821
1428
 
1822
- See #7814.
1429
+ * Specifying `implicit_order_column` now subsorts the records by primary key if available to ensure deterministic results.
1823
1430
 
1824
- *Yves Senn*
1431
+ *Paweł Urbanek*
1825
1432
 
1826
- * Fix error when specifying a non-empty default value on a PostgreSQL array
1827
- column.
1433
+ * `where(attr => [])` now loads an empty result without making a query.
1828
1434
 
1829
- Fixes #10613.
1435
+ *John Hawthorn*
1830
1436
 
1831
- *Luke Steensen*
1437
+ * Fixed the performance regression for `primary_keys` introduced MySQL 8.0.
1832
1438
 
1833
- * Fix error where `.persisted?` throws SystemStackError for an unsaved model with a
1834
- custom primary key that did not save due to validation error.
1439
+ *Hiroyuki Ishii*
1835
1440
 
1836
- Fixes #14393.
1441
+ * Add support for `belongs_to` to `has_many` inversing.
1837
1442
 
1838
- *Chris Finne*
1443
+ *Gannon McGibbon*
1839
1444
 
1840
- * Introduce `validate` as an alias for `valid?`.
1445
+ * Allow length configuration for `has_secure_token` method. The minimum length
1446
+ is set at 24 characters.
1841
1447
 
1842
- This is more intuitive when you want to run validations but don't care about the return value.
1448
+ Before:
1843
1449
 
1844
- *Henrik Nyh*
1450
+ ```ruby
1451
+ has_secure_token :auth_token
1452
+ ```
1845
1453
 
1846
- * Create indexes inline in CREATE TABLE for MySQL.
1454
+ After:
1847
1455
 
1848
- This is important, because adding an index on a temporary table after it has been created
1849
- would commit the transaction.
1456
+ ```ruby
1457
+ has_secure_token :default_token # 24 characters
1458
+ has_secure_token :auth_token, length: 36 # 36 characters
1459
+ has_secure_token :invalid_token, length: 12 # => ActiveRecord::SecureToken::MinimumLengthError
1460
+ ```
1850
1461
 
1851
- It also allows creating and dropping indexed tables with fewer queries and fewer permissions
1852
- required.
1462
+ *Bernardo de Araujo*
1853
1463
 
1854
- Example:
1464
+ * Deprecate `DatabaseConfigurations#to_h`. These connection hashes are still available via `ActiveRecord::Base.configurations.configs_for`.
1855
1465
 
1856
- create_table :temp, temporary: true, as: "SELECT id, name, zip FROM a_really_complicated_query" do |t|
1857
- t.index :zip
1858
- end
1859
- # => CREATE TEMPORARY TABLE temp (INDEX (zip)) AS SELECT id, name, zip FROM a_really_complicated_query
1466
+ *Eileen Uchitelle*, *John Crepezzi*
1860
1467
 
1861
- *Cody Cutrer*, *Steve Rice*, *Rafael Mendonça Franca*
1468
+ * Add `DatabaseConfig#configuration_hash` to return database configuration hashes with symbol keys, and use all symbol-key configuration hashes internally. Deprecate `DatabaseConfig#config` which returns a String-keyed `Hash` with the same values.
1862
1469
 
1863
- * Use singular table name in generated migrations when
1864
- `ActiveRecord::Base.pluralize_table_names` is `false`.
1470
+ *John Crepezzi*, *Eileen Uchitelle*
1865
1471
 
1866
- Fixes #13426.
1472
+ * Allow column names to be passed to `remove_index` positionally along with other options.
1867
1473
 
1868
- *Kuldeep Aggarwal*
1474
+ Passing other options can be necessary to make `remove_index` correctly reversible.
1869
1475
 
1870
- * `touch` accepts many attributes to be touched at once.
1476
+ Before:
1871
1477
 
1872
- Example:
1478
+ add_index :reports, :report_id # => works
1479
+ add_index :reports, :report_id, unique: true # => works
1480
+ remove_index :reports, :report_id # => works
1481
+ remove_index :reports, :report_id, unique: true # => ArgumentError
1873
1482
 
1874
- # touches :signed_at, :sealed_at, and :updated_at/on attributes.
1875
- Photo.last.touch(:signed_at, :sealed_at)
1483
+ After:
1876
1484
 
1877
- *James Pinto*
1485
+ remove_index :reports, :report_id, unique: true # => works
1878
1486
 
1879
- * `rake db:structure:dump` only dumps schema information if the schema
1880
- migration table exists.
1487
+ *Eugene Kenny*
1881
1488
 
1882
- Fixes #14217.
1489
+ * Allow bulk `ALTER` statements to drop and recreate indexes with the same name.
1883
1490
 
1884
- *Yves Senn*
1491
+ *Eugene Kenny*
1885
1492
 
1886
- * Reap connections that were checked out by now-dead threads, instead
1887
- of waiting until they disconnect by themselves. Before this change,
1888
- a suitably constructed series of short-lived threads could starve
1889
- the connection pool, without ever having more than a couple alive at
1890
- the same time.
1493
+ * `insert`, `insert_all`, `upsert`, and `upsert_all` now clear the query cache.
1891
1494
 
1892
- *Matthew Draper*
1495
+ *Eugene Kenny*
1893
1496
 
1894
- * `pk_and_sequence_for` now ensures that only the pg_depend entries
1895
- pointing to pg_class, and thus only sequence objects, are considered.
1497
+ * Call `while_preventing_writes` directly from `connected_to`.
1896
1498
 
1897
- *Josh Williams*
1499
+ 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)`.
1898
1500
 
1899
- * `where.not` adds `references` for `includes` like normal `where` calls do.
1501
+ 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.
1900
1502
 
1901
- Fixes #14406.
1503
+ *Eileen M. Uchitelle*
1902
1504
 
1903
- *Yves Senn*
1505
+ * Improve detection of ActiveRecord::StatementTimeout with mysql2 adapter in the edge case when the query is terminated during filesort.
1904
1506
 
1905
- * Extend fixture `$LABEL` replacement to allow string interpolation.
1507
+ *Kir Shatrov*
1906
1508
 
1907
- Example:
1509
+ * Stop trying to read yaml file fixtures when loading Active Record fixtures.
1908
1510
 
1909
- martin:
1910
- email: $LABEL@email.com
1511
+ *Gannon McGibbon*
1911
1512
 
1912
- users(:martin).email # => martin@email.com
1513
+ * Deprecate `.reorder(nil)` with `.first` / `.first!` taking non-deterministic result.
1913
1514
 
1914
- *Eric Steele*
1515
+ To continue taking non-deterministic result, use `.take` / `.take!` instead.
1915
1516
 
1916
- * Add support for `Relation` be passed as parameter on `QueryCache#select_all`.
1517
+ *Ryuta Kamizono*
1917
1518
 
1918
- Fixes #14361.
1519
+ * Preserve user supplied joins order as much as possible.
1919
1520
 
1920
- *arthurnn*
1521
+ Fixes #36761, #34328, #24281, #12953.
1921
1522
 
1922
- * Passing an Active Record object to `find` or `exists?` is now deprecated.
1923
- Call `.id` on the object first.
1523
+ *Ryuta Kamizono*
1924
1524
 
1925
- *Aaron Patterson*
1525
+ * Allow `matches_regex` and `does_not_match_regexp` on the MySQL Arel visitor.
1926
1526
 
1927
- * Only use BINARY for MySQL case sensitive uniqueness check when column
1928
- has a case insensitive collation.
1527
+ *James Pearson*
1929
1528
 
1930
- *Ryuta Kamizono*
1529
+ * Allow specifying fixtures to be ignored by setting `ignore` in YAML file's '_fixture' section.
1931
1530
 
1932
- * Support for MySQL 5.6 fractional seconds.
1531
+ *Tongfei Gao*
1933
1532
 
1934
- *arthurnn*, *Tatsuhiko Miyagawa*
1533
+ * Make the DATABASE_URL env variable only affect the primary connection. Add new env variables for multiple databases.
1935
1534
 
1936
- * Support for PostgreSQL `citext` data type enabling case-insensitive
1937
- `where` values without needing to wrap in UPPER/LOWER sql functions.
1535
+ *John Crepezzi*, *Eileen Uchitelle*
1938
1536
 
1939
- *Troy Kruthoff*, *Lachlan Sylvester*
1537
+ * Add a warning for enum elements with 'not_' prefix.
1940
1538
 
1941
- * Only save has_one associations if record has changes.
1942
- Previously after save related callbacks, such as `#after_commit`, were triggered when the has_one
1943
- object did not get saved to the db.
1539
+ class Foo
1540
+ enum status: [:sent, :not_sent]
1541
+ end
1944
1542
 
1945
- *Alan Kennedy*
1543
+ *Edu Depetris*
1946
1544
 
1947
- * Allow strings to specify the `#order` value.
1545
+ * Make currency symbols optional for money column type in PostgreSQL.
1948
1546
 
1949
- Example:
1547
+ *Joel Schneider*
1950
1548
 
1951
- Model.order(id: 'asc').to_sql == Model.order(id: :asc).to_sql
1549
+ * Add support for beginless ranges, introduced in Ruby 2.7.
1952
1550
 
1953
- *Marcelo Casiraghi*, *Robin Dupret*
1551
+ *Josh Goodall*
1954
1552
 
1955
- * Dynamically register PostgreSQL enum OIDs. This prevents "unknown OID"
1956
- warnings on enum columns.
1553
+ * Add `database_exists?` method to connection adapters to check if a database exists.
1957
1554
 
1958
- *Dieter Komendera*
1555
+ *Guilherme Mansur*
1959
1556
 
1960
- * `includes` is able to detect the right preloading strategy when string
1961
- joins are involved.
1557
+ * Loading the schema for a model that has no `table_name` raises a `TableNotSpecified` error.
1962
1558
 
1963
- Fixes #14109.
1559
+ *Guilherme Mansur*, *Eugene Kenny*
1964
1560
 
1965
- *Aaron Patterson*, *Yves Senn*
1561
+ * PostgreSQL: Fix GROUP BY with ORDER BY virtual count attribute.
1966
1562
 
1967
- * Fix error with validation with enum fields for records where the value for
1968
- any enum attribute is always evaluated as 0 during uniqueness validation.
1563
+ Fixes #36022.
1969
1564
 
1970
- Fixes #14172.
1565
+ *Ryuta Kamizono*
1971
1566
 
1972
- *Vilius Luneckas* *Ahmed AbouElhamayed*
1567
+ * Make ActiveRecord `ConnectionPool.connections` method thread-safe.
1973
1568
 
1974
- * `before_add` callbacks are fired before the record is saved on
1975
- `has_and_belongs_to_many` associations *and* on `has_many :through`
1976
- associations. Before this change, `before_add` callbacks would be fired
1977
- before the record was saved on `has_and_belongs_to_many` associations, but
1978
- *not* on `has_many :through` associations.
1569
+ Fixes #36465.
1979
1570
 
1980
- Fixes #14144.
1571
+ *Jeff Doering*
1981
1572
 
1982
- * Fix STI classes not defining an attribute method if there is a conflicting
1983
- private method defined on its ancestors.
1573
+ * Add support for multiple databases to `rails db:abort_if_pending_migrations`.
1984
1574
 
1985
- Fixes #11569.
1575
+ *Mark Lee*
1986
1576
 
1987
- *Godfrey Chan*
1577
+ * Fix sqlite3 collation parsing when using decimal columns.
1988
1578
 
1989
- * Coerce strings when reading attributes. Fixes #10485.
1579
+ *Martin R. Schuster*
1990
1580
 
1991
- Example:
1581
+ * Fix invalid schema when primary key column has a comment.
1992
1582
 
1993
- book = Book.new(title: 12345)
1994
- book.save!
1995
- book.title # => "12345"
1583
+ Fixes #29966.
1996
1584
 
1997
- *Yves Senn*
1585
+ *Guilherme Goettems Schneider*
1998
1586
 
1999
- * Deprecate half-baked support for PostgreSQL range values with excluding beginnings.
2000
- We currently map PostgreSQL ranges to Ruby ranges. This conversion is not fully
2001
- possible because the Ruby range does not support excluded beginnings.
1587
+ * Fix table comment also being applied to the primary key column.
2002
1588
 
2003
- The current solution of incrementing the beginning is not correct and is now
2004
- deprecated. For subtypes where we don't know how to increment (e.g. `#succ`
2005
- is not defined) it will raise an `ArgumentException` for ranges with excluding
2006
- beginnings.
1589
+ *Guilherme Goettems Schneider*
2007
1590
 
2008
- *Yves Senn*
1591
+ * Allow generated `create_table` migrations to include or skip timestamps.
2009
1592
 
2010
- * Support for user created range types in PostgreSQL.
1593
+ *Michael Duchemin*
2011
1594
 
2012
- *Yves Senn*
2013
1595
 
2014
- Please check [4-1-stable](https://github.com/rails/rails/blob/4-1-stable/activerecord/CHANGELOG.md) for previous changes.
1596
+ Please check [6-0-stable](https://github.com/rails/rails/blob/6-0-stable/activerecord/CHANGELOG.md) for previous changes.