activerecord 4.2.0 → 6.1.7.1

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