activerecord 5.0.7.2 → 6.1.1

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

Potentially problematic release.


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

Files changed (363) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +829 -2015
  3. data/MIT-LICENSE +3 -1
  4. data/README.rdoc +11 -9
  5. data/examples/performance.rb +31 -29
  6. data/examples/simple.rb +5 -3
  7. data/lib/active_record.rb +37 -29
  8. data/lib/active_record/aggregations.rb +249 -247
  9. data/lib/active_record/association_relation.rb +30 -18
  10. data/lib/active_record/associations.rb +1714 -1596
  11. data/lib/active_record/associations/alias_tracker.rb +36 -42
  12. data/lib/active_record/associations/association.rb +143 -68
  13. data/lib/active_record/associations/association_scope.rb +98 -94
  14. data/lib/active_record/associations/belongs_to_association.rb +76 -46
  15. data/lib/active_record/associations/belongs_to_polymorphic_association.rb +13 -12
  16. data/lib/active_record/associations/builder/association.rb +27 -28
  17. data/lib/active_record/associations/builder/belongs_to.rb +52 -60
  18. data/lib/active_record/associations/builder/collection_association.rb +12 -22
  19. data/lib/active_record/associations/builder/has_and_belongs_to_many.rb +40 -62
  20. data/lib/active_record/associations/builder/has_many.rb +10 -2
  21. data/lib/active_record/associations/builder/has_one.rb +35 -2
  22. data/lib/active_record/associations/builder/singular_association.rb +5 -1
  23. data/lib/active_record/associations/collection_association.rb +104 -259
  24. data/lib/active_record/associations/collection_proxy.rb +169 -125
  25. data/lib/active_record/associations/foreign_association.rb +22 -0
  26. data/lib/active_record/associations/has_many_association.rb +46 -31
  27. data/lib/active_record/associations/has_many_through_association.rb +66 -46
  28. data/lib/active_record/associations/has_one_association.rb +71 -52
  29. data/lib/active_record/associations/has_one_through_association.rb +20 -11
  30. data/lib/active_record/associations/join_dependency.rb +169 -180
  31. data/lib/active_record/associations/join_dependency/join_association.rb +53 -79
  32. data/lib/active_record/associations/join_dependency/join_base.rb +10 -9
  33. data/lib/active_record/associations/join_dependency/join_part.rb +14 -14
  34. data/lib/active_record/associations/preloader.rb +97 -104
  35. data/lib/active_record/associations/preloader/association.rb +109 -97
  36. data/lib/active_record/associations/preloader/through_association.rb +77 -76
  37. data/lib/active_record/associations/singular_association.rb +12 -45
  38. data/lib/active_record/associations/through_association.rb +27 -15
  39. data/lib/active_record/attribute_assignment.rb +55 -60
  40. data/lib/active_record/attribute_methods.rb +111 -141
  41. data/lib/active_record/attribute_methods/before_type_cast.rb +17 -9
  42. data/lib/active_record/attribute_methods/dirty.rb +172 -112
  43. data/lib/active_record/attribute_methods/primary_key.rb +88 -91
  44. data/lib/active_record/attribute_methods/query.rb +6 -8
  45. data/lib/active_record/attribute_methods/read.rb +18 -50
  46. data/lib/active_record/attribute_methods/serialization.rb +38 -10
  47. data/lib/active_record/attribute_methods/time_zone_conversion.rb +38 -66
  48. data/lib/active_record/attribute_methods/write.rb +25 -32
  49. data/lib/active_record/attributes.rb +69 -31
  50. data/lib/active_record/autosave_association.rb +102 -66
  51. data/lib/active_record/base.rb +16 -25
  52. data/lib/active_record/callbacks.rb +202 -43
  53. data/lib/active_record/coders/json.rb +2 -0
  54. data/lib/active_record/coders/yaml_column.rb +11 -12
  55. data/lib/active_record/connection_adapters.rb +50 -0
  56. data/lib/active_record/connection_adapters/abstract/connection_pool.rb +661 -375
  57. data/lib/active_record/connection_adapters/abstract/database_limits.rb +14 -38
  58. data/lib/active_record/connection_adapters/abstract/database_statements.rb +269 -105
  59. data/lib/active_record/connection_adapters/abstract/query_cache.rb +54 -35
  60. data/lib/active_record/connection_adapters/abstract/quoting.rb +137 -93
  61. data/lib/active_record/connection_adapters/abstract/savepoints.rb +5 -3
  62. data/lib/active_record/connection_adapters/abstract/schema_creation.rb +155 -113
  63. data/lib/active_record/connection_adapters/abstract/schema_definitions.rb +328 -162
  64. data/lib/active_record/connection_adapters/abstract/schema_dumper.rb +68 -80
  65. data/lib/active_record/connection_adapters/abstract/schema_statements.rb +591 -259
  66. data/lib/active_record/connection_adapters/abstract/transaction.rb +229 -91
  67. data/lib/active_record/connection_adapters/abstract_adapter.rb +392 -244
  68. data/lib/active_record/connection_adapters/abstract_mysql_adapter.rb +457 -582
  69. data/lib/active_record/connection_adapters/column.rb +55 -13
  70. data/lib/active_record/connection_adapters/deduplicable.rb +29 -0
  71. data/lib/active_record/connection_adapters/legacy_pool_manager.rb +31 -0
  72. data/lib/active_record/connection_adapters/mysql/column.rb +8 -31
  73. data/lib/active_record/connection_adapters/mysql/database_statements.rb +135 -49
  74. data/lib/active_record/connection_adapters/mysql/explain_pretty_printer.rb +24 -23
  75. data/lib/active_record/connection_adapters/mysql/quoting.rb +50 -20
  76. data/lib/active_record/connection_adapters/mysql/schema_creation.rb +79 -49
  77. data/lib/active_record/connection_adapters/mysql/schema_definitions.rb +66 -56
  78. data/lib/active_record/connection_adapters/mysql/schema_dumper.rb +70 -36
  79. data/lib/active_record/connection_adapters/mysql/schema_statements.rb +268 -0
  80. data/lib/active_record/connection_adapters/mysql/type_metadata.rb +20 -12
  81. data/lib/active_record/connection_adapters/mysql2_adapter.rb +74 -37
  82. data/lib/active_record/connection_adapters/pool_config.rb +63 -0
  83. data/lib/active_record/connection_adapters/pool_manager.rb +43 -0
  84. data/lib/active_record/connection_adapters/postgresql/column.rb +39 -28
  85. data/lib/active_record/connection_adapters/postgresql/database_statements.rb +70 -101
  86. data/lib/active_record/connection_adapters/postgresql/explain_pretty_printer.rb +5 -3
  87. data/lib/active_record/connection_adapters/postgresql/oid.rb +26 -21
  88. data/lib/active_record/connection_adapters/postgresql/oid/array.rb +22 -11
  89. data/lib/active_record/connection_adapters/postgresql/oid/bit.rb +6 -5
  90. data/lib/active_record/connection_adapters/postgresql/oid/bit_varying.rb +2 -0
  91. data/lib/active_record/connection_adapters/postgresql/oid/bytea.rb +2 -0
  92. data/lib/active_record/connection_adapters/postgresql/oid/cidr.rb +6 -6
  93. data/lib/active_record/connection_adapters/postgresql/oid/date.rb +23 -0
  94. data/lib/active_record/connection_adapters/postgresql/oid/date_time.rb +14 -4
  95. data/lib/active_record/connection_adapters/postgresql/oid/decimal.rb +3 -1
  96. data/lib/active_record/connection_adapters/postgresql/oid/enum.rb +5 -4
  97. data/lib/active_record/connection_adapters/postgresql/oid/hstore.rb +19 -18
  98. data/lib/active_record/connection_adapters/postgresql/oid/inet.rb +2 -0
  99. data/lib/active_record/connection_adapters/postgresql/oid/interval.rb +49 -0
  100. data/lib/active_record/connection_adapters/postgresql/oid/jsonb.rb +3 -11
  101. data/lib/active_record/connection_adapters/postgresql/oid/legacy_point.rb +44 -0
  102. data/lib/active_record/connection_adapters/postgresql/oid/macaddr.rb +25 -0
  103. data/lib/active_record/connection_adapters/postgresql/oid/money.rb +7 -5
  104. data/lib/active_record/connection_adapters/postgresql/oid/{json.rb → oid.rb} +6 -1
  105. data/lib/active_record/connection_adapters/postgresql/oid/point.rb +30 -9
  106. data/lib/active_record/connection_adapters/postgresql/oid/range.rb +52 -30
  107. data/lib/active_record/connection_adapters/postgresql/oid/specialized_string.rb +4 -1
  108. data/lib/active_record/connection_adapters/postgresql/oid/type_map_initializer.rb +58 -54
  109. data/lib/active_record/connection_adapters/postgresql/oid/uuid.rb +18 -4
  110. data/lib/active_record/connection_adapters/postgresql/oid/vector.rb +2 -0
  111. data/lib/active_record/connection_adapters/postgresql/oid/xml.rb +2 -0
  112. data/lib/active_record/connection_adapters/postgresql/quoting.rb +98 -38
  113. data/lib/active_record/connection_adapters/postgresql/referential_integrity.rb +21 -27
  114. data/lib/active_record/connection_adapters/postgresql/schema_creation.rb +80 -0
  115. data/lib/active_record/connection_adapters/postgresql/schema_definitions.rb +147 -105
  116. data/lib/active_record/connection_adapters/postgresql/schema_dumper.rb +34 -32
  117. data/lib/active_record/connection_adapters/postgresql/schema_statements.rb +426 -324
  118. data/lib/active_record/connection_adapters/postgresql/type_metadata.rb +32 -23
  119. data/lib/active_record/connection_adapters/postgresql/utils.rb +9 -6
  120. data/lib/active_record/connection_adapters/postgresql_adapter.rb +418 -293
  121. data/lib/active_record/connection_adapters/schema_cache.rb +135 -18
  122. data/lib/active_record/connection_adapters/sql_type_metadata.rb +22 -7
  123. data/lib/active_record/connection_adapters/sqlite3/database_statements.rb +144 -0
  124. data/lib/active_record/connection_adapters/sqlite3/explain_pretty_printer.rb +3 -1
  125. data/lib/active_record/connection_adapters/sqlite3/quoting.rb +72 -18
  126. data/lib/active_record/connection_adapters/sqlite3/schema_creation.rb +5 -6
  127. data/lib/active_record/connection_adapters/sqlite3/schema_definitions.rb +19 -0
  128. data/lib/active_record/connection_adapters/sqlite3/schema_dumper.rb +18 -0
  129. data/lib/active_record/connection_adapters/sqlite3/schema_statements.rb +170 -0
  130. data/lib/active_record/connection_adapters/sqlite3_adapter.rb +282 -290
  131. data/lib/active_record/connection_adapters/statement_pool.rb +9 -8
  132. data/lib/active_record/connection_handling.rb +287 -45
  133. data/lib/active_record/core.rb +385 -181
  134. data/lib/active_record/counter_cache.rb +60 -28
  135. data/lib/active_record/database_configurations.rb +272 -0
  136. data/lib/active_record/database_configurations/connection_url_resolver.rb +98 -0
  137. data/lib/active_record/database_configurations/database_config.rb +80 -0
  138. data/lib/active_record/database_configurations/hash_config.rb +96 -0
  139. data/lib/active_record/database_configurations/url_config.rb +53 -0
  140. data/lib/active_record/delegated_type.rb +209 -0
  141. data/lib/active_record/destroy_association_async_job.rb +36 -0
  142. data/lib/active_record/dynamic_matchers.rb +87 -87
  143. data/lib/active_record/enum.rb +122 -47
  144. data/lib/active_record/errors.rb +153 -22
  145. data/lib/active_record/explain.rb +13 -8
  146. data/lib/active_record/explain_registry.rb +3 -1
  147. data/lib/active_record/explain_subscriber.rb +9 -4
  148. data/lib/active_record/fixture_set/file.rb +20 -22
  149. data/lib/active_record/fixture_set/model_metadata.rb +32 -0
  150. data/lib/active_record/fixture_set/render_context.rb +17 -0
  151. data/lib/active_record/fixture_set/table_row.rb +152 -0
  152. data/lib/active_record/fixture_set/table_rows.rb +46 -0
  153. data/lib/active_record/fixtures.rb +246 -507
  154. data/lib/active_record/gem_version.rb +6 -4
  155. data/lib/active_record/inheritance.rb +168 -95
  156. data/lib/active_record/insert_all.rb +208 -0
  157. data/lib/active_record/integration.rb +114 -25
  158. data/lib/active_record/internal_metadata.rb +30 -24
  159. data/lib/active_record/legacy_yaml_adapter.rb +11 -5
  160. data/lib/active_record/locking/optimistic.rb +81 -85
  161. data/lib/active_record/locking/pessimistic.rb +22 -6
  162. data/lib/active_record/log_subscriber.rb +68 -31
  163. data/lib/active_record/middleware/database_selector.rb +77 -0
  164. data/lib/active_record/middleware/database_selector/resolver.rb +92 -0
  165. data/lib/active_record/middleware/database_selector/resolver/session.rb +48 -0
  166. data/lib/active_record/migration.rb +439 -342
  167. data/lib/active_record/migration/command_recorder.rb +152 -98
  168. data/lib/active_record/migration/compatibility.rb +229 -60
  169. data/lib/active_record/migration/join_table.rb +8 -7
  170. data/lib/active_record/model_schema.rb +230 -122
  171. data/lib/active_record/nested_attributes.rb +213 -203
  172. data/lib/active_record/no_touching.rb +11 -2
  173. data/lib/active_record/null_relation.rb +12 -34
  174. data/lib/active_record/persistence.rb +471 -97
  175. data/lib/active_record/query_cache.rb +23 -12
  176. data/lib/active_record/querying.rb +43 -25
  177. data/lib/active_record/railtie.rb +155 -43
  178. data/lib/active_record/railties/console_sandbox.rb +2 -0
  179. data/lib/active_record/railties/controller_runtime.rb +34 -33
  180. data/lib/active_record/railties/databases.rake +507 -195
  181. data/lib/active_record/readonly_attributes.rb +9 -4
  182. data/lib/active_record/reflection.rb +245 -269
  183. data/lib/active_record/relation.rb +475 -324
  184. data/lib/active_record/relation/batches.rb +125 -72
  185. data/lib/active_record/relation/batches/batch_enumerator.rb +28 -10
  186. data/lib/active_record/relation/calculations.rb +267 -171
  187. data/lib/active_record/relation/delegation.rb +73 -69
  188. data/lib/active_record/relation/finder_methods.rb +238 -248
  189. data/lib/active_record/relation/from_clause.rb +7 -9
  190. data/lib/active_record/relation/merger.rb +95 -77
  191. data/lib/active_record/relation/predicate_builder.rb +109 -110
  192. data/lib/active_record/relation/predicate_builder/array_handler.rb +22 -17
  193. data/lib/active_record/relation/predicate_builder/association_query_value.rb +42 -0
  194. data/lib/active_record/relation/predicate_builder/basic_object_handler.rb +6 -4
  195. data/lib/active_record/relation/predicate_builder/polymorphic_array_value.rb +55 -0
  196. data/lib/active_record/relation/predicate_builder/range_handler.rb +7 -18
  197. data/lib/active_record/relation/predicate_builder/relation_handler.rb +7 -1
  198. data/lib/active_record/relation/query_attribute.rb +33 -2
  199. data/lib/active_record/relation/query_methods.rb +654 -374
  200. data/lib/active_record/relation/record_fetch_warning.rb +8 -6
  201. data/lib/active_record/relation/spawn_methods.rb +15 -14
  202. data/lib/active_record/relation/where_clause.rb +171 -109
  203. data/lib/active_record/result.rb +88 -51
  204. data/lib/active_record/runtime_registry.rb +5 -3
  205. data/lib/active_record/sanitization.rb +73 -100
  206. data/lib/active_record/schema.rb +7 -14
  207. data/lib/active_record/schema_dumper.rb +101 -69
  208. data/lib/active_record/schema_migration.rb +16 -12
  209. data/lib/active_record/scoping.rb +20 -20
  210. data/lib/active_record/scoping/default.rb +92 -95
  211. data/lib/active_record/scoping/named.rb +39 -30
  212. data/lib/active_record/secure_token.rb +19 -9
  213. data/lib/active_record/serialization.rb +7 -3
  214. data/lib/active_record/signed_id.rb +116 -0
  215. data/lib/active_record/statement_cache.rb +80 -29
  216. data/lib/active_record/store.rb +122 -42
  217. data/lib/active_record/suppressor.rb +6 -3
  218. data/lib/active_record/table_metadata.rb +51 -39
  219. data/lib/active_record/tasks/database_tasks.rb +332 -115
  220. data/lib/active_record/tasks/mysql_database_tasks.rb +66 -104
  221. data/lib/active_record/tasks/postgresql_database_tasks.rb +84 -56
  222. data/lib/active_record/tasks/sqlite_database_tasks.rb +40 -19
  223. data/lib/active_record/test_databases.rb +24 -0
  224. data/lib/active_record/test_fixtures.rb +246 -0
  225. data/lib/active_record/timestamp.rb +70 -38
  226. data/lib/active_record/touch_later.rb +26 -24
  227. data/lib/active_record/transactions.rb +121 -184
  228. data/lib/active_record/translation.rb +3 -1
  229. data/lib/active_record/type.rb +29 -17
  230. data/lib/active_record/type/adapter_specific_registry.rb +44 -48
  231. data/lib/active_record/type/date.rb +2 -0
  232. data/lib/active_record/type/date_time.rb +2 -0
  233. data/lib/active_record/type/decimal_without_scale.rb +15 -0
  234. data/lib/active_record/type/hash_lookup_type_map.rb +5 -4
  235. data/lib/active_record/type/internal/timezone.rb +2 -0
  236. data/lib/active_record/type/json.rb +30 -0
  237. data/lib/active_record/type/serialized.rb +20 -9
  238. data/lib/active_record/type/text.rb +11 -0
  239. data/lib/active_record/type/time.rb +12 -1
  240. data/lib/active_record/type/type_map.rb +14 -17
  241. data/lib/active_record/type/unsigned_integer.rb +16 -0
  242. data/lib/active_record/type_caster.rb +4 -2
  243. data/lib/active_record/type_caster/connection.rb +17 -13
  244. data/lib/active_record/type_caster/map.rb +10 -6
  245. data/lib/active_record/validations.rb +8 -5
  246. data/lib/active_record/validations/absence.rb +2 -0
  247. data/lib/active_record/validations/associated.rb +4 -3
  248. data/lib/active_record/validations/length.rb +2 -0
  249. data/lib/active_record/validations/numericality.rb +35 -0
  250. data/lib/active_record/validations/presence.rb +4 -2
  251. data/lib/active_record/validations/uniqueness.rb +52 -45
  252. data/lib/active_record/version.rb +3 -1
  253. data/lib/arel.rb +54 -0
  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.rb +70 -0
  269. data/lib/arel/nodes/and.rb +32 -0
  270. data/lib/arel/nodes/ascending.rb +23 -0
  271. data/lib/arel/nodes/binary.rb +126 -0
  272. data/lib/arel/nodes/bind_param.rb +44 -0
  273. data/lib/arel/nodes/case.rb +55 -0
  274. data/lib/arel/nodes/casted.rb +62 -0
  275. data/lib/arel/nodes/comment.rb +29 -0
  276. data/lib/arel/nodes/count.rb +12 -0
  277. data/lib/arel/nodes/delete_statement.rb +45 -0
  278. data/lib/arel/nodes/descending.rb +23 -0
  279. data/lib/arel/nodes/equality.rb +15 -0
  280. data/lib/arel/nodes/extract.rb +24 -0
  281. data/lib/arel/nodes/false.rb +16 -0
  282. data/lib/arel/nodes/full_outer_join.rb +8 -0
  283. data/lib/arel/nodes/function.rb +44 -0
  284. data/lib/arel/nodes/grouping.rb +11 -0
  285. data/lib/arel/nodes/homogeneous_in.rb +72 -0
  286. data/lib/arel/nodes/in.rb +15 -0
  287. data/lib/arel/nodes/infix_operation.rb +92 -0
  288. data/lib/arel/nodes/inner_join.rb +8 -0
  289. data/lib/arel/nodes/insert_statement.rb +37 -0
  290. data/lib/arel/nodes/join_source.rb +20 -0
  291. data/lib/arel/nodes/matches.rb +18 -0
  292. data/lib/arel/nodes/named_function.rb +23 -0
  293. data/lib/arel/nodes/node.rb +51 -0
  294. data/lib/arel/nodes/node_expression.rb +13 -0
  295. data/lib/arel/nodes/ordering.rb +27 -0
  296. data/lib/arel/nodes/outer_join.rb +8 -0
  297. data/lib/arel/nodes/over.rb +15 -0
  298. data/lib/arel/nodes/regexp.rb +16 -0
  299. data/lib/arel/nodes/right_outer_join.rb +8 -0
  300. data/lib/arel/nodes/select_core.rb +67 -0
  301. data/lib/arel/nodes/select_statement.rb +41 -0
  302. data/lib/arel/nodes/sql_literal.rb +19 -0
  303. data/lib/arel/nodes/string_join.rb +11 -0
  304. data/lib/arel/nodes/table_alias.rb +31 -0
  305. data/lib/arel/nodes/terminal.rb +16 -0
  306. data/lib/arel/nodes/true.rb +16 -0
  307. data/lib/arel/nodes/unary.rb +44 -0
  308. data/lib/arel/nodes/unary_operation.rb +20 -0
  309. data/lib/arel/nodes/unqualified_column.rb +22 -0
  310. data/lib/arel/nodes/update_statement.rb +41 -0
  311. data/lib/arel/nodes/values_list.rb +9 -0
  312. data/lib/arel/nodes/window.rb +126 -0
  313. data/lib/arel/nodes/with.rb +11 -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.rb +13 -0
  321. data/lib/arel/visitors/dot.rb +308 -0
  322. data/lib/arel/visitors/mysql.rb +93 -0
  323. data/lib/arel/visitors/postgresql.rb +120 -0
  324. data/lib/arel/visitors/sqlite.rb +38 -0
  325. data/lib/arel/visitors/to_sql.rb +899 -0
  326. data/lib/arel/visitors/visitor.rb +45 -0
  327. data/lib/arel/window_predications.rb +9 -0
  328. data/lib/rails/generators/active_record.rb +7 -5
  329. data/lib/rails/generators/active_record/application_record/application_record_generator.rb +26 -0
  330. data/lib/rails/generators/active_record/{model/templates/application_record.rb → application_record/templates/application_record.rb.tt} +0 -0
  331. data/lib/rails/generators/active_record/migration.rb +22 -3
  332. data/lib/rails/generators/active_record/migration/migration_generator.rb +38 -35
  333. data/lib/rails/generators/active_record/migration/templates/{create_table_migration.rb → create_table_migration.rb.tt} +3 -1
  334. data/lib/rails/generators/active_record/migration/templates/{migration.rb → migration.rb.tt} +7 -5
  335. data/lib/rails/generators/active_record/model/model_generator.rb +41 -25
  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 → model.rb.tt} +10 -1
  338. data/lib/rails/generators/active_record/model/templates/{module.rb → module.rb.tt} +0 -0
  339. metadata +141 -57
  340. data/lib/active_record/associations/preloader/belongs_to.rb +0 -17
  341. data/lib/active_record/associations/preloader/collection_association.rb +0 -17
  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 -15
  345. data/lib/active_record/associations/preloader/has_one_through.rb +0 -9
  346. data/lib/active_record/associations/preloader/singular_association.rb +0 -20
  347. data/lib/active_record/attribute.rb +0 -213
  348. data/lib/active_record/attribute/user_provided_default.rb +0 -28
  349. data/lib/active_record/attribute_decorators.rb +0 -67
  350. data/lib/active_record/attribute_mutation_tracker.rb +0 -70
  351. data/lib/active_record/attribute_set.rb +0 -110
  352. data/lib/active_record/attribute_set/builder.rb +0 -132
  353. data/lib/active_record/collection_cache_key.rb +0 -50
  354. data/lib/active_record/connection_adapters/connection_specification.rb +0 -263
  355. data/lib/active_record/connection_adapters/determine_if_preparable_visitor.rb +0 -22
  356. data/lib/active_record/connection_adapters/postgresql/oid/rails_5_1_point.rb +0 -50
  357. data/lib/active_record/railties/jdbcmysql_error.rb +0 -16
  358. data/lib/active_record/relation/predicate_builder/association_query_handler.rb +0 -88
  359. data/lib/active_record/relation/predicate_builder/base_handler.rb +0 -17
  360. data/lib/active_record/relation/predicate_builder/class_handler.rb +0 -27
  361. data/lib/active_record/relation/predicate_builder/polymorphic_array_handler.rb +0 -57
  362. data/lib/active_record/relation/where_clause_factory.rb +0 -38
  363. data/lib/active_record/type/internal/abstract_json.rb +0 -33
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 235a713e47ff9449c9c0ccceb33b51cfddf8aac53284ca0693c4a57d7578502a
4
- data.tar.gz: 0a106230b5c2b5f05a9e64cdab3a084b1c6c406c2a2adb7f703d59a27ae376a4
3
+ metadata.gz: 56f128436e13685f9715b6dbe295150f61a11e7af686fc5d758044f080fe1879
4
+ data.tar.gz: b80991c1de4020e4e770f64464683e6e3cd88f38dbc93e8909c270ade9f32d20
5
5
  SHA512:
6
- metadata.gz: c585c0592c49ebe5ee2d6c1ccf1e0f3cd37f0b41ca26cb49246c1f8e99ee07a508bbc24c519114c5fe3dcd09960ca54d71af8ecbdb7cb13ee371e9054a842080
7
- data.tar.gz: b7b18c7ccb0c602aa135e9420a1f9e7fc60dee5a1b81912c0fb936dcf7a3f3abf4e7ac857c9e061e80d033e245c5b2203078356635f1f2a87a5e8848201347c1
6
+ metadata.gz: 10f8bd5fccf212ad4807ae6c08a8264333af73373606dce2eb2338e2f6edcfa7469351f5a905836e4be6764548e580d0c205564c8aa2493cbb1476f02ed555a4
7
+ data.tar.gz: 2ff2988d43a99595a0a14d796afeca8aa53b54a8f7e516721a026a053cdc7bb0c23fcf934d180a165023b58c5e9335d42bb1c0e0b9daf1b6df078c1e969fc8c1
data/CHANGELOG.md CHANGED
@@ -1,2549 +1,1363 @@
1
- ## Rails 5.0.7.2 (March 11, 2019) ##
1
+ ## Rails 6.1.1 (January 07, 2021) ##
2
2
 
3
- * No changes.
3
+ * Fix fixtures loading when strict loading is enabled for the association.
4
4
 
5
+ *Alex Ghiculescu*
5
6
 
6
- ## Rails 5.0.7.1 (November 27, 2018) ##
7
+ * Fix `where` with custom primary key for belongs_to association.
7
8
 
8
- * No changes.
9
-
10
-
11
- ## Rails 5.0.7 (March 29, 2018) ##
12
-
13
- * Apply time column precision on assignment.
14
-
15
- PR #20317 changed the behavior of datetime columns so that when they
16
- have a specified precision then on assignment the value is rounded to
17
- that precision. This behavior is now applied to time columns as well.
18
-
19
- Fixes #30301.
20
-
21
- *Andrew White*
22
-
23
- * Normalize time column values for SQLite database.
24
-
25
- For legacy reasons, time columns in SQLite are stored as full datetimes
26
- because until #24542 the quoting for time columns didn't remove the date
27
- component. To ensure that values are consistent we now normalize the
28
- date component to 2001-01-01 on reading and writing.
29
-
30
- *Andrew White*
31
-
32
- * Ensure that the date component is removed when quoting times.
33
-
34
- PR #24542 altered the quoting for time columns so that the date component
35
- was removed however it only removed it when it was 2001-01-01. Now the
36
- date component is removed irrespective of what the date is.
37
-
38
- *Andrew White*
39
-
40
- * Query cache was unavailable when entering the `ActiveRecord::Base.cache` block
41
- without being connected.
42
-
43
- *Tsukasa Oishi*
9
+ *Ryuta Kamizono*
44
10
 
45
- * Fix `bin/rails db:setup` and `bin/rails db:test:prepare` create wrong
46
- ar_internal_metadata's data for a test database.
11
+ * Fix `where` with aliased associations.
47
12
 
48
- Before:
49
- ```
50
- $ RAILS_ENV=test rails dbconsole
51
- > SELECT * FROM ar_internal_metadata;
52
- key|value|created_at|updated_at
53
- environment|development|2017-09-11 23:14:10.815679|2017-09-11 23:14:10.815679
54
- ```
13
+ *Ryuta Kamizono*
55
14
 
56
- After:
57
- ```
58
- $ RAILS_ENV=test rails dbconsole
59
- > SELECT * FROM ar_internal_metadata;
60
- key|value|created_at|updated_at
61
- environment|test|2017-09-11 23:14:10.815679|2017-09-11 23:14:10.815679
62
- ```
15
+ * Fix `composed_of` with symbol mapping.
63
16
 
64
- Fixes #26731.
17
+ *Ryuta Kamizono*
65
18
 
66
- *bogdanvlviv*
19
+ * Don't skip money's type cast for pluck and calculations.
67
20
 
68
- * Fix longer sequence name detection for serial columns.
21
+ *Ryuta Kamizono*
69
22
 
70
- Fixes #28332.
23
+ * Fix `where` on polymorphic association with non Active Record object.
71
24
 
72
25
  *Ryuta Kamizono*
73
26
 
74
- * Use `max_identifier_length` for `index_name_length` in PostgreSQL adapter.
27
+ * Make sure `db:prepare` works even the schema file doesn't exist.
75
28
 
76
- *Ryuta Kamizono*
29
+ *Rafael Mendonça França*
77
30
 
31
+ * Fix complicated `has_many :through` with nested where condition.
78
32
 
79
- ## Rails 5.0.6 (September 07, 2017) ##
33
+ *Ryuta Kamizono*
80
34
 
81
- * No changes.
35
+ * Handle STI models for `has_many dependent: :destroy_async`.
82
36
 
37
+ *Muhammad Usman*
83
38
 
84
- ## Rails 5.0.6.rc1 (August 24, 2017) ##
39
+ * Restore possibility of passing `false` to :polymorphic option of `belongs_to`.
85
40
 
86
- * Ensure `sum` honors `distinct` on `has_many :through` associations
41
+ Previously, passing `false` would trigger the option validation logic
42
+ to throw an error saying :polymorphic would not be a valid option.
87
43
 
88
- Fixes #16791
44
+ *glaszig*
89
45
 
90
- *Aaron Wortham
46
+ * Allow adding nonnamed expression indexes to be revertible.
91
47
 
48
+ Fixes #40732.
92
49
 
93
- ## Rails 5.0.5 (July 31, 2017) ##
50
+ Previously, the following code would raise an error, when executed while rolling back,
51
+ and the index name should be specified explicitly. Now, the index name is inferred
52
+ automatically.
94
53
 
95
- * No changes.
54
+ ```ruby
55
+ add_index(:items, "to_tsvector('english', description)")
56
+ ```
96
57
 
58
+ *fatkodima*
97
59
 
98
- ## Rails 5.0.5.rc2 (July 25, 2017) ##
99
60
 
100
- * No changes.
61
+ ## Rails 6.1.0 (December 09, 2020) ##
101
62
 
63
+ * Only warn about negative enums if a positive form that would cause conflicts exists.
102
64
 
103
- ## Rails 5.0.5.rc1 (July 19, 2017) ##
65
+ Fixes #39065.
104
66
 
105
- * `Relation#joins` is no longer affected by the target model's
106
- `current_scope`, with the exception of `unscoped`.
67
+ *Alex Ghiculescu*
107
68
 
108
- Fixes #29338.
69
+ * Change `attribute_for_inspect` to take `filter_attributes` in consideration.
109
70
 
110
- *Sean Griffin*
71
+ *Rafael Mendonça França*
111
72
 
73
+ * Fix odd behavior of inverse_of with multiple belongs_to to same class.
112
74
 
113
- ## Rails 5.0.4 (June 19, 2017) ##
75
+ Fixes #35204.
114
76
 
115
- * Restore previous behavior of collection proxies: their values can have
116
- methods stubbed, and they respect extension modules applied by a default
117
- scope.
77
+ *Tomoyuki Kai*
118
78
 
119
- *Ryuta Kamizono*
79
+ * Build predicate conditions with objects that delegate `#id` and primary key:
120
80
 
121
- * Loading model schema from database is now thread-safe.
81
+ ```ruby
82
+ class AdminAuthor
83
+ delegate_missing_to :@author
122
84
 
123
- Fixes #28589.
85
+ def initialize(author)
86
+ @author = author
87
+ end
88
+ end
124
89
 
125
- *Vikrant Chaudhary*, *David Abdemoulaie*
90
+ Post.where(author: AdminAuthor.new(author))
91
+ ```
126
92
 
93
+ *Sean Doyle*
127
94
 
128
- ## Rails 5.0.3 (May 12, 2017) ##
95
+ * Add `connected_to_many` API.
129
96
 
130
- * Check whether `Rails.application` defined before calling it
97
+ This API allows applications to connect to multiple databases at once without switching all of them or implementing a deeply nested stack.
131
98
 
132
- In #27674 we changed the migration generator to generate migrations at the
133
- path defined in `Rails.application.config.paths` however the code checked
134
- for the presence of the `Rails` constant but not the `Rails.application`
135
- method which caused problems when using Active Record and generators outside
136
- of the context of a Rails application.
99
+ Before:
137
100
 
138
- Fixes #28325.
101
+ AnimalsRecord.connected_to(role: :reading) do
102
+ MealsRecord.connected_to(role: :reading) do
103
+ Dog.first # read from animals replica
104
+ Dinner.first # read from meals replica
105
+ Person.first # read from primary writer
106
+ end
107
+ end
139
108
 
140
- * Fix `deserialize` with JSON array.
109
+ After:
141
110
 
142
- Fixes #28285.
111
+ ActiveRecord::Base.connected_to_many([AnimalsRecord, MealsRecord], role: :reading) do
112
+ Dog.first # read from animals replica
113
+ Dinner.first # read from meals replica
114
+ Person.first # read from primary writer
115
+ end
143
116
 
144
- *Ryuta Kamizono*
117
+ *Eileen M. Uchitelle*, *John Crepezzi*
145
118
 
146
- * Fix `rake db:schema:load` with subdirectories.
119
+ * Add option to raise or log for `ActiveRecord::StrictLoadingViolationError`.
147
120
 
148
- *Ryuta Kamizono*
121
+ 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.
149
122
 
150
- * Fix `rake db:migrate:status` with subdirectories.
123
+ Set `config.active_record.action_on_strict_loading_violation` to `:log` errors instead of raising.
151
124
 
152
- *Ryuta Kamizono*
125
+ *Eileen M. Uchitelle*
153
126
 
154
- * Don't share options between reference id and type columns
127
+ * Allow the inverse of a `has_one` association that was previously autosaved to be loaded.
155
128
 
156
- When using a polymorphic reference column in a migration, sharing options
157
- between the two columns doesn't make sense since they are different types.
158
- The `reference_id` column is usually an integer and the `reference_type`
159
- column a string so options like `unsigned: true` will result in an invalid
160
- table definition.
129
+ Fixes #34255.
161
130
 
162
- *Ryuta Kamizono*
131
+ *Steven Weber*
163
132
 
164
- * Fix regression of #1969 with SELECT aliases in HAVING clause.
133
+ * Optimise the length of index names for polymorphic references by using the reference name rather than the type and id column names.
165
134
 
166
- *Eugene Kenny*
135
+ 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.
167
136
 
137
+ This change reduces the chance of that happening by using the reference name, e.g. `index_my_table_on_my_reference`.
168
138
 
169
- ## Rails 5.0.2 (March 01, 2017) ##
139
+ Fixes #38655.
170
140
 
171
- * Fix `wait_timeout` to configurable for mysql2 adapter.
141
+ *Luke Redpath*
172
142
 
173
- Fixes #26556.
143
+ * MySQL: Uniqueness validator now respects default database collation,
144
+ no longer enforce case sensitive comparison by default.
174
145
 
175
146
  *Ryuta Kamizono*
176
147
 
177
- * Make `table_name=` reset current statement cache,
178
- so queries are not run against the previous table name.
148
+ * Remove deprecated methods from `ActiveRecord::ConnectionAdapters::DatabaseLimits`.
179
149
 
180
- *namusyaka*
150
+ `column_name_length`
151
+ `table_name_length`
152
+ `columns_per_table`
153
+ `indexes_per_table`
154
+ `columns_per_multicolumn_index`
155
+ `sql_query_length`
156
+ `joins_per_query`
181
157
 
182
- * Allow ActiveRecord::Base#as_json to be passed a frozen Hash.
158
+ *Rafael Mendonça França*
183
159
 
184
- *Isaac Betesh*
160
+ * Remove deprecated `ActiveRecord::ConnectionAdapters::AbstractAdapter#supports_multi_insert?`.
185
161
 
186
- * Fix inspection behavior when the :id column is not primary key.
162
+ *Rafael Mendonça França*
187
163
 
188
- *namusyaka*
164
+ * Remove deprecated `ActiveRecord::ConnectionAdapters::AbstractAdapter#supports_foreign_keys_in_create?`.
189
165
 
190
- * Fix `association_primary_key_type` for reflections with symbol primary key
166
+ *Rafael Mendonça França*
191
167
 
192
- Fixes #27864
168
+ * Remove deprecated `ActiveRecord::ConnectionAdapters::PostgreSQLAdapter#supports_ranges?`.
193
169
 
194
- *Daniel Colson*
170
+ *Rafael Mendonça França*
195
171
 
196
- * Place generated migrations into the path set by `config.paths["db/migrate"]`
172
+ * Remove deprecated `ActiveRecord::Base#update_attributes` and `ActiveRecord::Base#update_attributes!`.
197
173
 
198
- *Kevin Glowacz*
174
+ *Rafael Mendonça França*
199
175
 
200
- * Compare deserialized values for `PostgreSQL::OID::Hstore` types when
201
- calling `ActiveRecord::Dirty#changed_in_place?`
176
+ * Remove deprecated `migrations_path` argument in `ActiveRecord::ConnectionAdapter::SchemaStatements#assume_migrated_upto_version`.
202
177
 
203
- Fixes #27502.
178
+ *Rafael Mendonça França*
204
179
 
205
- *Jon Moss*
180
+ * Remove deprecated `config.active_record.sqlite3.represent_boolean_as_integer`.
206
181
 
207
- * Respect precision option for arrays of timestamps.
182
+ *Rafael Mendonça França*
208
183
 
209
- Fixes #27514.
184
+ * `relation.create` does no longer leak scope to class level querying methods
185
+ in initialization block and callbacks.
210
186
 
211
- *Sean Griffin*
187
+ Before:
212
188
 
189
+ User.where(name: "John").create do |john|
190
+ User.find_by(name: "David") # => nil
191
+ end
213
192
 
214
- ## Rails 5.0.1 (December 21, 2016) ##
193
+ After:
215
194
 
216
- * No changes.
195
+ User.where(name: "John").create do |john|
196
+ User.find_by(name: "David") # => #<User name: "David", ...>
197
+ end
217
198
 
199
+ *Ryuta Kamizono*
218
200
 
219
- ## Rails 5.0.1.rc2 (December 10, 2016) ##
201
+ * Named scope chain does no longer leak scope to class level querying methods.
220
202
 
221
- * Correct resolution of associated class in `has_many :through`
222
- associations' `*_ids` setters.
203
+ class User < ActiveRecord::Base
204
+ scope :david, -> { User.where(name: "David") }
205
+ end
223
206
 
224
- Fixes #27297.
207
+ Before:
225
208
 
226
- *Matthew Draper*
209
+ User.where(name: "John").david
210
+ # SELECT * FROM users WHERE name = 'John' AND name = 'David'
227
211
 
228
- * Support index length and order options using both string and symbol
229
- column names.
212
+ After:
230
213
 
231
- Fixes #27243.
214
+ User.where(name: "John").david
215
+ # SELECT * FROM users WHERE name = 'David'
232
216
 
233
217
  *Ryuta Kamizono*
234
218
 
219
+ * Remove deprecated methods from `ActiveRecord::DatabaseConfigurations`.
235
220
 
236
- ## Rails 5.0.1.rc1 (December 01, 2016) ##
237
-
238
- * Fix that unsigned with zerofill is treated as signed.
239
-
240
- Fixes #27125.
221
+ `fetch`
222
+ `each`
223
+ `first`
224
+ `values`
225
+ `[]=`
241
226
 
242
- *Ryuta Kamizono*
227
+ *Rafael Mendonça França*
243
228
 
244
- * Fix the uniqueness validation scope with a polymorphic association.
229
+ * `where.not` now generates NAND predicates instead of NOR.
245
230
 
246
- *Sergey Alekseev*
231
+ Before:
247
232
 
248
- * Raise ActiveRecord::RecordNotFound from collection `*_ids` setters
249
- for unknown IDs with a better error message.
233
+ User.where.not(name: "Jon", role: "admin")
234
+ # SELECT * FROM users WHERE name != 'Jon' AND role != 'admin'
250
235
 
251
- Changes the collection `*_ids` setters to cast provided IDs the data
252
- type of the primary key set in the association, not the model
253
- primary key.
236
+ After:
254
237
 
255
- *Dominic Cleal*
238
+ User.where.not(name: "Jon", role: "admin")
239
+ # SELECT * FROM users WHERE NOT (name == 'Jon' AND role == 'admin')
256
240
 
257
- * Introduce `Model#reload_<association>` to bring back the behavior
258
- of `Article.category(true)` where `category` is a singular
259
- association.
241
+ *Rafael Mendonça França*
260
242
 
261
- The force reloading of the association reader was deprecated
262
- in #20888. Unfortunately the suggested alternative of
263
- `article.reload.category` does not expose the same behavior.
243
+ * Remove deprecated `ActiveRecord::Result#to_hash` method.
264
244
 
265
- This patch adds a reader method with the prefix `reload_` for
266
- singular associations. This method has the same semantics as
267
- passing true to the association reader used to have.
245
+ *Rafael Mendonça França*
268
246
 
269
- *Yves Senn*
247
+ * Deprecate `ActiveRecord::Base.allow_unsafe_raw_sql`.
270
248
 
271
- * Make sure eager loading `ActiveRecord::Associations` also loads
272
- constants defined in `ActiveRecord::Associations::Preloader`.
249
+ *Rafael Mendonça França*
273
250
 
274
- *Yves Senn*
251
+ * Remove deprecated support for using unsafe raw SQL in `ActiveRecord::Relation` methods.
275
252
 
276
- * Allow `ActionController::Parameters`-like objects to be passed as
277
- values for Postgres HStore columns.
253
+ *Rafael Mendonça França*
278
254
 
279
- Fixes #26904.
255
+ * Allow users to silence the "Rails couldn't infer whether you are using multiple databases..."
256
+ message using `config.active_record.suppress_multiple_database_warning`.
280
257
 
281
- *Jon Moss*
258
+ *Omri Gabay*
282
259
 
283
- * Configure query caching (per thread) on the connection pool.
260
+ * Connections can be granularly switched for abstract classes when `connected_to` is called.
284
261
 
285
- Moving the configuration to the pool means we don't allocate a connection
286
- until it's actually needed.
262
+ 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.
287
263
 
288
- Applications that manually interact with the connection pool and/or query
289
- cache may notice that the connection's cache is now cleared and disabled
290
- when it gets returned to the pool, even if the request is not yet completed.
264
+ Example usage:
291
265
 
292
- *Samuel Cochran*, *Matthew Draper*
266
+ 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`.
293
267
 
294
- * Fixed support for case insensitive comparisons of `text` columns in
295
- PostgreSQL.
268
+ ```ruby
269
+ ActiveRecord::Base.connected_to(role: :reading) do
270
+ User.first # reads from default replica
271
+ Dog.first # reads from default replica
296
272
 
297
- *Edho Arief*
273
+ AnimalsRecord.connected_to(role: :writing, shard: :one) do
274
+ User.first # reads from default replica
275
+ Dog.first # reads from shard one primary
276
+ end
298
277
 
299
- * Return `true` from `update_attribute` when the value of the attribute
300
- to be updated is unchanged.
278
+ User.first # reads from default replica
279
+ Dog.first # reads from default replica
301
280
 
302
- Fixes #26593.
281
+ ApplicationRecord.connected_to(role: :writing, shard: :two) do
282
+ User.first # reads from shard two primary
283
+ Dog.first # reads from default replica
284
+ end
285
+ end
286
+ ```
303
287
 
304
- *Prathamesh Sonpatki*
288
+ *Eileen M. Uchitelle*, *John Crepezzi*
305
289
 
306
- * Serialize JSON attribute value `nil` as SQL `NULL`, not JSON `null`
290
+ * Allow double-dash comment syntax when querying read-only databases
307
291
 
308
- *Trung Duc Tran*
292
+ *James Adam*
309
293
 
310
- * Always store errors details information with symbols.
294
+ * Add `values_at` method.
311
295
 
312
- When the association is autosaved we were storing the details with
313
- string keys. This was creating inconsistency with other details that are
314
- added using the `Errors#add` method. It was also inconsistent with the
315
- `Errors#messages` storage.
296
+ Returns an array containing the values associated with the given methods.
316
297
 
317
- To fix this inconsistency we are always storing with symbols. This will
318
- cause a small breaking change because in those cases the details could
319
- be accessed as strings keys but now it can not.
298
+ ```ruby
299
+ topic = Topic.first
300
+ topic.values_at(:title, :author_name)
301
+ # => ["Budget", "Jason"]
302
+ ```
320
303
 
321
- Fix #26499.
304
+ Similar to `Hash#values_at` but on an Active Record instance.
322
305
 
323
- *Rafael Mendonça França*, *Marcus Vieira*
306
+ *Guillaume Briday*
324
307
 
325
- * Using a mysql2 connection after it fails to reconnect will now have an error message
326
- saying the connection is closed rather than an undefined method error message.
308
+ * Fix `read_attribute_before_type_cast` to consider attribute aliases.
327
309
 
328
- *Dylan Thacker-Smith*
310
+ *Marcelo Lauxen*
329
311
 
330
- * Remove unnecessarily association load when a `belongs_to` association has already been
331
- loaded then the foreign key is changed directly and the record saved.
312
+ * Support passing record to uniqueness validator `:conditions` callable:
332
313
 
333
- *James Coleman*
314
+ ```ruby
315
+ class Article < ApplicationRecord
316
+ validates_uniqueness_of :title, conditions: ->(article) {
317
+ published_at = article.published_at
318
+ where(published_at: published_at.beginning_of_year..published_at.end_of_year)
319
+ }
320
+ end
321
+ ```
334
322
 
335
- * PostgreSQL array columns will now respect the encoding of strings contained
336
- in the array.
323
+ *Eliot Sykes*
337
324
 
338
- Fixes #26326.
325
+ * `BatchEnumerator#update_all` and `BatchEnumerator#delete_all` now return the
326
+ total number of rows affected, just like their non-batched counterparts.
339
327
 
340
- *Sean Griffin*
328
+ ```ruby
329
+ Person.in_batches.update_all("first_name = 'Eugene'") # => 42
330
+ Person.in_batches.delete_all # => 42
331
+ ```
341
332
 
342
- * Inverse association instances will now be set before `after_find` or
343
- `after_initialize` callbacks are run.
333
+ Fixes #40287.
344
334
 
345
- Fixes #26320.
335
+ *Eugene Kenny*
346
336
 
347
- *Sean Griffin*
337
+ * Add support for PostgreSQL `interval` data type with conversion to
338
+ `ActiveSupport::Duration` when loading records from database and
339
+ serialization to ISO 8601 formatted duration string on save.
340
+ Add support to define a column in migrations and get it in a schema dump.
341
+ Optional column precision is supported.
348
342
 
349
- * Avoid loading records from database when they are already loaded using
350
- the `pluck` method on a collection.
343
+ To use this in 6.1, you need to place the next string to your model file:
351
344
 
352
- Fixes #25921.
345
+ attribute :duration, :interval
353
346
 
354
- *Ryuta Kamizono*
347
+ To keep old behavior until 6.2 is released:
355
348
 
356
- * Sqlite3 migrations to add a column to an existing table can now be
357
- successfully rolled back when the column was given and invalid column
358
- type.
349
+ attribute :duration, :string
359
350
 
360
- Fixes #26087
351
+ Example:
361
352
 
362
- *Travis O'Neill*
353
+ create_table :events do |t|
354
+ t.string :name
355
+ t.interval :duration
356
+ end
363
357
 
364
- * Hashes can once again be passed to setters of `composed_of`, if all of the
365
- mapping methods are methods implemented on `Hash`.
358
+ class Event < ApplicationRecord
359
+ attribute :duration, :interval
360
+ end
366
361
 
367
- Fixes #25978.
362
+ Event.create!(name: 'Rock Fest', duration: 2.days)
363
+ Event.last.duration # => 2 days
364
+ Event.last.duration.iso8601 # => "P2D"
365
+ Event.new(duration: 'P1DT12H3S').duration # => 1 day, 12 hours, and 3 seconds
366
+ Event.new(duration: '1 day') # Unknown value will be ignored and NULL will be written to database
368
367
 
369
- *Sean Griffin*
368
+ *Andrey Novikov*
370
369
 
371
- * Doing count on relations that contain LEFT OUTER JOIN Arel node no longer
372
- force a DISTINCT. This solves issues when using count after a left_joins.
370
+ * Allow associations supporting the `dependent:` key to take `dependent: :destroy_async`.
373
371
 
374
- *Maxime Handfield Lapointe*
372
+ ```ruby
373
+ class Account < ActiveRecord::Base
374
+ belongs_to :supplier, dependent: :destroy_async
375
+ end
376
+ ```
375
377
 
376
- * RecordNotFound raised by association.find exposes `id`, `primary_key` and
377
- `model` methods to be consistent with RecordNotFound raised by Record.find.
378
+ `:destroy_async` will enqueue a job to destroy associated records in the background.
378
379
 
379
- *Michel Pigassou*
380
+ *DHH*, *George Claghorn*, *Cory Gwin*, *Rafael Mendonça França*, *Adrianna Chang*
380
381
 
381
- * Fix the SELECT statement in `#table_comment` for MySQL.
382
+ * Add `SKIP_TEST_DATABASE` environment variable to disable modifying the test database when `rails db:create` and `rails db:drop` are called.
382
383
 
383
- *Takeshi Akima*
384
+ *Jason Schweier*
384
385
 
385
- * Virtual attributes will no longer raise when read on models loaded from the
386
- database
386
+ * `connects_to` can only be called on `ActiveRecord::Base` or abstract classes.
387
387
 
388
- *Sean Griffin*
388
+ 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.
389
389
 
390
- * Fixes multi-parameter attributes conversion with invalid params.
390
+ *Eileen M. Uchitelle*, *John Crepezzi*
391
391
 
392
- *Hiroyuki Ishii*
392
+ * All connection adapters `execute` now raises `ActiveRecord::ConnectionNotEstablished` rather than
393
+ `ActiveRecord::StatementInvalid` when they encounter a connection error.
393
394
 
394
- * Add newline between each migration in `structure.sql`.
395
+ *Jean Boussier*
395
396
 
396
- Keeps schema migration inserts as a single commit, but allows for easier
397
- git diff-ing. Fixes #25504.
397
+ * `Mysql2Adapter#quote_string` now raises `ActiveRecord::ConnectionNotEstablished` rather than
398
+ `ActiveRecord::StatementInvalid` when it can't connect to the MySQL server.
398
399
 
399
- *Grey Baker*, *Norberto Lopes*
400
+ *Jean Boussier*
400
401
 
401
- * Using `group` with an attribute that has a custom type will properly cast
402
- the hash keys after calling a calculation method like `count`.
402
+ * Add support for check constraints that are `NOT VALID` via `validate: false` (PostgreSQL-only).
403
403
 
404
- Fixes #25595.
404
+ *Alex Robbin*
405
405
 
406
- *Sean Griffin*
406
+ * Ensure the default configuration is considered primary or first for an environment
407
407
 
408
- * Ensure concurrent invocations of the connection reaper cannot allocate the
409
- same connection to two threads.
408
+ 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.
410
409
 
411
- Fixes #25585.
410
+ *Eileen M. Uchitelle*
412
411
 
413
- *Matthew Draper*
412
+ * Allow `where` references association names as joined table name aliases.
414
413
 
415
- * Fixed dumping of foreign key's referential actions when MySQL connection
416
- uses `sql_mode = ANSI_QUOTES`.
414
+ ```ruby
415
+ class Comment < ActiveRecord::Base
416
+ enum label: [:default, :child]
417
+ has_many :children, class_name: "Comment", foreign_key: :parent_id
418
+ end
417
419
 
418
- Fixes #25300.
420
+ # ... FROM comments LEFT OUTER JOIN comments children ON ... WHERE children.label = 1
421
+ Comment.includes(:children).where("children.label": "child")
422
+ ```
419
423
 
420
424
  *Ryuta Kamizono*
421
425
 
426
+ * Support storing demodulized class name for polymorphic type.
422
427
 
423
- ## Rails 5.0.0 (June 30, 2016) ##
424
-
425
- * Inspecting an object with an associated array of over 10 elements no longer
426
- truncates the array, preventing `inspect` from looping infinitely in some
427
- cases.
428
-
429
- *Kevin McPhillips*
430
-
431
- * Ensure hashes can be assigned to attributes created using `composed_of`.
428
+ Before Rails 6.1, storing demodulized class name is supported only for STI type
429
+ by `store_full_sti_class` class attribute.
432
430
 
433
- Fixes #25210.
431
+ Now `store_full_class_name` class attribute can handle both STI and polymorphic types.
434
432
 
435
- *Sean Griffin*
436
-
437
- * Fix logging edge case where if an attribute was of the binary type and
438
- was provided as a Hash.
439
-
440
- *Jon Moss*
433
+ *Ryuta Kamizono*
441
434
 
442
- * Handle JSON deserialization correctly if the column default from database
443
- adapter returns `''` instead of `nil`.
435
+ * Deprecate `rails db:structure:{load, dump}` tasks and extend
436
+ `rails db:schema:{load, dump}` tasks to work with either `:ruby` or `:sql` format,
437
+ depending on `config.active_record.schema_format` configuration value.
444
438
 
445
- *Johannes Opper*
439
+ *fatkodima*
446
440
 
447
- * PostgreSQL: Support Expression Indexes and Operator Classes.
441
+ * Respect the `select` values for eager loading.
448
442
 
449
- Example:
443
+ ```ruby
444
+ post = Post.select("UPPER(title) AS title").first
445
+ post.title # => "WELCOME TO THE WEBLOG"
446
+ post.body # => ActiveModel::MissingAttributeError
450
447
 
451
- create_table :users do |t|
452
- t.string :name
453
- t.index 'lower(name) varchar_pattern_ops'
454
- end
448
+ # Rails 6.0 (ignore the `select` values)
449
+ post = Post.select("UPPER(title) AS title").eager_load(:comments).first
450
+ post.title # => "Welcome to the weblog"
451
+ post.body # => "Such a lovely day"
455
452
 
456
- Fixes #19090, #21765, #21819, #24359.
453
+ # Rails 6.1 (respect the `select` values)
454
+ post = Post.select("UPPER(title) AS title").eager_load(:comments).first
455
+ post.title # => "WELCOME TO THE WEBLOG"
456
+ post.body # => ActiveModel::MissingAttributeError
457
+ ```
457
458
 
458
459
  *Ryuta Kamizono*
459
460
 
460
- * MySQL: Prepared statements support.
461
-
462
- To enable, set `prepared_statements: true` in config/database.yml.
463
- Requires mysql2 0.4.4+.
464
-
465
- *Ryuta Kamizono*
461
+ * Allow attribute's default to be configured but keeping its own type.
466
462
 
467
- * Schema dumper: Indexes are now included in the `create_table` block
468
- instead of listed afterward as separate `add_index` lines.
463
+ ```ruby
464
+ class Post < ActiveRecord::Base
465
+ attribute :written_at, default: -> { Time.now.utc }
466
+ end
469
467
 
470
- This tidies up schema.rb and makes it easy to read as a list of tables.
468
+ # Rails 6.0
469
+ Post.type_for_attribute(:written_at) # => #<Type::Value ... precision: nil, ...>
471
470
 
472
- Bonus: Allows databases that support it (MySQL) to perform as single
473
- `CREATE TABLE` query, no additional query per index.
471
+ # Rails 6.1
472
+ Post.type_for_attribute(:written_at) # => #<Type::DateTime ... precision: 6, ...>
473
+ ```
474
474
 
475
475
  *Ryuta Kamizono*
476
476
 
477
- * SQLite: Fix uniqueness validation when values exceed the column limit.
478
-
479
- SQLite doesn't impose length restrictions on strings, BLOBs, or numeric
480
- values. It treats them as helpful metadata. When we truncate strings
481
- before checking uniqueness, we'd miss values that exceed the column limit.
482
-
483
- Other databases enforce length limits. A large value will pass uniqueness
484
- validation since the column limit guarantees no value that long exists.
485
- When we insert the row, it'll raise `ActiveRecord::ValueTooLong` as we
486
- expect.
477
+ * Allow default to be configured for Enum.
487
478
 
488
- This fixes edge-case incorrect validation failures for values that exceed
489
- the column limit but are identical to an existing value *when truncated*.
490
- Now these will pass validation and raise an exception.
479
+ ```ruby
480
+ class Book < ActiveRecord::Base
481
+ enum status: [:proposed, :written, :published], _default: :published
482
+ end
491
483
 
492
- *Ryuta Kamizono*
493
-
494
- * Raise `ActiveRecord::ValueTooLong` when column limits are exceeded.
495
- Supported by MySQL and PostgreSQL adapters.
484
+ Book.new.status # => "published"
485
+ ```
496
486
 
497
487
  *Ryuta Kamizono*
498
488
 
499
- * Migrations: `#foreign_key` respects `table_name_prefix` and `_suffix`.
489
+ * Deprecate YAML loading from legacy format older than Rails 5.0.
500
490
 
501
491
  *Ryuta Kamizono*
502
492
 
503
- * SQLite: Force NOT NULL primary keys.
493
+ * Added the setting `ActiveRecord::Base.immutable_strings_by_default`, which
494
+ allows you to specify that all string columns should be frozen unless
495
+ otherwise specified. This will reduce memory pressure for applications which
496
+ do not generally mutate string properties of Active Record objects.
504
497
 
505
- From SQLite docs: https://www.sqlite.org/lang_createtable.html
506
- According to the SQL standard, PRIMARY KEY should always imply NOT
507
- NULL. Unfortunately, due to a bug in some early versions, this is not
508
- the case in SQLite. Unless the column is an INTEGER PRIMARY KEY or the
509
- table is a WITHOUT ROWID table or the column is declared NOT NULL,
510
- SQLite allows NULL values in a PRIMARY KEY column. SQLite could be
511
- fixed to conform to the standard, but doing so might break legacy
512
- applications. Hence, it has been decided to merely document the fact
513
- that SQLite allowing NULLs in most PRIMARY KEY columns.
498
+ *Sean Griffin*, *Ryuta Kamizono*
514
499
 
515
- Now we override column options to explicitly set NOT NULL rather than rely
516
- on implicit NOT NULL like MySQL and PostgreSQL adapters.
500
+ * Deprecate `map!` and `collect!` on `ActiveRecord::Result`.
517
501
 
518
502
  *Ryuta Kamizono*
519
503
 
520
- * Added notice when a database is successfully created or dropped.
504
+ * Support `relation.and` for intersection as Set theory.
521
505
 
522
- Example:
506
+ ```ruby
507
+ david_and_mary = Author.where(id: [david, mary])
508
+ mary_and_bob = Author.where(id: [mary, bob])
523
509
 
524
- $ bin/rails db:create
525
- Created database 'blog_development'
526
- Created database 'blog_test'
510
+ david_and_mary.merge(mary_and_bob) # => [mary, bob]
527
511
 
528
- $ bin/rails db:drop
529
- Dropped database 'blog_development'
530
- Dropped database 'blog_test'
512
+ david_and_mary.and(mary_and_bob) # => [mary]
513
+ david_and_mary.or(mary_and_bob) # => [david, mary, bob]
514
+ ```
531
515
 
532
- Changed older notices
533
- `blog_development already exists` to `Database 'blog_development' already exists`.
534
- and
535
- `Couldn't drop blog_development` to `Couldn't drop database 'blog_development'`.
516
+ *Ryuta Kamizono*
536
517
 
537
- *bogdanvlviv*
518
+ * Merging conditions on the same column no longer maintain both conditions,
519
+ and will be consistently replaced by the latter condition in Rails 6.2.
520
+ To migrate to Rails 6.2's behavior, use `relation.merge(other, rewhere: true)`.
538
521
 
539
- * Database comments. Annotate database objects (tables, columns, indexes)
540
- with comments stored in database metadata. PostgreSQL & MySQL support.
522
+ ```ruby
523
+ # Rails 6.1 (IN clause is replaced by merger side equality condition)
524
+ Author.where(id: [david.id, mary.id]).merge(Author.where(id: bob)) # => [bob]
541
525
 
542
- create_table :pages, force: :cascade, comment: 'CMS content pages' do |t|
543
- t.string :path, comment: 'Path fragment of page URL used for routing'
544
- t.string :locale, comment: 'RFC 3066 locale code of website language section'
545
- t.index [:path, :locale], comment: 'Look up pages by URI'
546
- end
526
+ # Rails 6.1 (both conflict conditions exists, deprecated)
527
+ Author.where(id: david.id..mary.id).merge(Author.where(id: bob)) # => []
547
528
 
548
- *Andrey Novikov*
529
+ # Rails 6.1 with rewhere to migrate to Rails 6.2's behavior
530
+ Author.where(id: david.id..mary.id).merge(Author.where(id: bob), rewhere: true) # => [bob]
549
531
 
550
- * Add `quoted_time` for truncating the date part of a TIME column value.
551
- This fixes queries on TIME column on MariaDB, as it doesn't ignore the
552
- date part of the string when it coerces to time.
532
+ # Rails 6.2 (same behavior with IN clause, mergee side condition is consistently replaced)
533
+ Author.where(id: [david.id, mary.id]).merge(Author.where(id: bob)) # => [bob]
534
+ Author.where(id: david.id..mary.id).merge(Author.where(id: bob)) # => [bob]
535
+ ```
553
536
 
554
537
  *Ryuta Kamizono*
555
538
 
556
- * Properly accept all valid JSON primitives in the JSON data type.
557
-
558
- Fixes #24234
559
-
560
- *Sean Griffin*
539
+ * Do not mark Postgresql MAC address and UUID attributes as changed when the assigned value only varies by case.
561
540
 
562
- * MariaDB 5.3+ supports microsecond datetime precision.
541
+ *Peter Fry*
563
542
 
564
- *Jeremy Daer*
543
+ * Resolve issue with insert_all unique_by option when used with expression index.
565
544
 
566
- * Delegate `none?` and `one?`. Now they can be invoked as model class methods.
545
+ When the `:unique_by` option of `ActiveRecord::Persistence.insert_all` and
546
+ `ActiveRecord::Persistence.upsert_all` was used with the name of an expression index, an error
547
+ was raised. Adding a guard around the formatting behavior for the `:unique_by` corrects this.
567
548
 
568
- Example:
569
-
570
- # When no record is found on the table
571
- Topic.none? # => true
572
-
573
- # When only one record is found on the table
574
- Topic.one? # => true
575
-
576
- *Kenta Shirai*
549
+ Usage:
577
550
 
578
- * The form builder now properly displays values when passing a proc form
579
- default to the attributes API.
551
+ ```ruby
552
+ create_table :books, id: :integer, force: true do |t|
553
+ t.column :name, :string
554
+ t.index "lower(name)", unique: true
555
+ end
580
556
 
581
- Fixes #24249.
557
+ Book.insert_all [{ name: "MyTest" }], unique_by: :index_books_on_lower_name
558
+ ```
582
559
 
583
- *Sean Griffin*
560
+ Fixes #39516.
584
561
 
585
- * The schema cache is now cleared after the `db:migrate` task is run.
562
+ *Austen Madden*
586
563
 
587
- Closes #24273.
564
+ * Add basic support for CHECK constraints to database migrations.
588
565
 
589
- *Chris Arcand*
566
+ Usage:
590
567
 
591
- * MySQL: strict mode respects other SQL modes rather than overwriting them.
592
- Setting `strict: true` adds `STRICT_ALL_TABLES` to `sql_mode`. Setting
593
- `strict: false` removes `STRICT_TRANS_TABLES`, `STRICT_ALL_TABLES`, and
594
- `TRADITIONAL` from `sql_mode`.
568
+ ```ruby
569
+ add_check_constraint :products, "price > 0", name: "price_check"
570
+ remove_check_constraint :products, name: "price_check"
571
+ ```
595
572
 
596
- *Ryuta Kamizono*
573
+ *fatkodima*
597
574
 
598
- * Execute default_scope defined by abstract class in the context of subclass.
575
+ * Add `ActiveRecord::Base.strict_loading_by_default` and `ActiveRecord::Base.strict_loading_by_default=`
576
+ to enable/disable strict_loading mode by default for a model. The configuration's value is
577
+ inheritable by subclasses, but they can override that value and it will not impact parent class.
599
578
 
600
- Fixes #23413.
601
- Fixes #10658.
579
+ Usage:
602
580
 
603
- *Mehmet Emin İNAÇ*
581
+ ```ruby
582
+ class Developer < ApplicationRecord
583
+ self.strict_loading_by_default = true
604
584
 
605
- * Fix an issue when preloading associations with extensions.
606
- Previously every association with extension methods was transformed into an
607
- instance dependent scope. This is no longer the case.
585
+ has_many :projects
586
+ end
608
587
 
609
- Fixes #23934.
588
+ dev = Developer.first
589
+ dev.projects.first
590
+ # => ActiveRecord::StrictLoadingViolationError Exception: Developer is marked as strict_loading and Project cannot be lazily loaded.
591
+ ```
610
592
 
611
- *Yves Senn*
593
+ *bogdanvlviv*
612
594
 
613
- * Deprecate `{insert|update|delete}_sql` in `DatabaseStatements`.
614
- Use the `{insert|update|delete}` public methods instead.
595
+ * Deprecate passing an Active Record object to `quote`/`type_cast` directly.
615
596
 
616
597
  *Ryuta Kamizono*
617
598
 
618
- * Added a configuration option to have active record raise an ArgumentError
619
- if the order or limit is ignored in a batch query, rather than logging a
620
- warning message.
621
-
622
- *Scott Ringwelski*
599
+ * Default engine `ENGINE=InnoDB` is no longer dumped to make schema more agnostic.
623
600
 
624
- * Honour the order of the joining model in a `has_many :through` association when eager loading.
601
+ Before:
625
602
 
626
- Example:
603
+ ```ruby
604
+ create_table "accounts", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci", force: :cascade do |t|
605
+ end
606
+ ```
627
607
 
628
- The below will now follow the order of `by_lines` when eager loading `authors`.
608
+ After:
629
609
 
630
- class Article < ActiveRecord::Base
631
- has_many :by_lines, -> { order(:position) }
632
- has_many :authors, through: :by_lines
633
- end
610
+ ```ruby
611
+ create_table "accounts", charset: "utf8mb4", collation: "utf8mb4_0900_ai_ci", force: :cascade do |t|
612
+ end
613
+ ```
634
614
 
635
- Fixes #17864.
615
+ *Ryuta Kamizono*
636
616
 
637
- *Yasyf Mohamedali*, *Joel Turkel*
617
+ * Added delegated type as an alternative to single-table inheritance for representing class hierarchies.
618
+ See ActiveRecord::DelegatedType for the full description.
638
619
 
639
- * Ensure that the Suppressor runs before validations.
620
+ *DHH*
640
621
 
641
- This moves the suppressor up to be run before validations rather than after
642
- validations. There's no reason to validate a record you aren't planning on saving.
622
+ * Deprecate aggregations with group by duplicated fields.
643
623
 
644
- *Eileen M. Uchitelle*
624
+ To migrate to Rails 6.2's behavior, use `uniq!(:group)` to deduplicate group fields.
645
625
 
646
- * Save many-to-many objects based on association primary key.
626
+ ```ruby
627
+ accounts = Account.group(:firm_id)
647
628
 
648
- Fixes #20995.
629
+ # duplicated group fields, deprecated.
630
+ accounts.merge(accounts.where.not(credit_limit: nil)).sum(:credit_limit)
631
+ # => {
632
+ # [1, 1] => 50,
633
+ # [2, 2] => 60
634
+ # }
649
635
 
650
- *himesh-r*
636
+ # use `uniq!(:group)` to deduplicate group fields.
637
+ accounts.merge(accounts.where.not(credit_limit: nil)).uniq!(:group).sum(:credit_limit)
638
+ # => {
639
+ # 1 => 50,
640
+ # 2 => 60
641
+ # }
642
+ ```
651
643
 
652
- * Ensure that mutations of the array returned from `ActiveRecord::Relation#to_a`
653
- do not affect the original relation, by returning a duplicate array each time.
644
+ *Ryuta Kamizono*
654
645
 
655
- This brings the behavior in line with `CollectionProxy#to_a`, which was
656
- already more careful.
646
+ * Deprecate duplicated query annotations.
657
647
 
658
- *Matthew Draper*
648
+ To migrate to Rails 6.2's behavior, use `uniq!(:annotate)` to deduplicate query annotations.
659
649
 
660
- * Fixed `where` for polymorphic associations when passed an array containing different types.
650
+ ```ruby
651
+ accounts = Account.where(id: [1, 2]).annotate("david and mary")
661
652
 
662
- Fixes #17011.
653
+ # duplicated annotations, deprecated.
654
+ accounts.merge(accounts.rewhere(id: 3))
655
+ # SELECT accounts.* FROM accounts WHERE accounts.id = 3 /* david and mary */ /* david and mary */
663
656
 
664
- Example:
657
+ # use `uniq!(:annotate)` to deduplicate annotations.
658
+ accounts.merge(accounts.rewhere(id: 3)).uniq!(:annotate)
659
+ # SELECT accounts.* FROM accounts WHERE accounts.id = 3 /* david and mary */
660
+ ```
665
661
 
666
- PriceEstimate.where(estimate_of: [Treasure.find(1), Car.find(2)])
667
- # => SELECT "price_estimates".* FROM "price_estimates"
668
- WHERE (("price_estimates"."estimate_of_type" = 'Treasure' AND "price_estimates"."estimate_of_id" = 1)
669
- OR ("price_estimates"."estimate_of_type" = 'Car' AND "price_estimates"."estimate_of_id" = 2))
662
+ *Ryuta Kamizono*
670
663
 
671
- *Philippe Huibonhoa*
664
+ * Resolve conflict between counter cache and optimistic locking.
672
665
 
673
- * Fix a bug where using `t.foreign_key` twice with the same `to_table` within
674
- the same table definition would only create one foreign key.
666
+ Bump an Active Record instance's lock version after updating its counter
667
+ cache. This avoids raising an unnecessary `ActiveRecord::StaleObjectError`
668
+ upon subsequent transactions by maintaining parity with the corresponding
669
+ database record's `lock_version` column.
675
670
 
676
- *George Millo*
671
+ Fixes #16449.
677
672
 
678
- * Fix a regression on has many association, where calling a child from parent in child's callback
679
- results in same child records getting added repeatedly to target.
673
+ *Aaron Lipman*
680
674
 
681
- Fixes #13387.
675
+ * Support merging option `:rewhere` to allow mergee side condition to be replaced exactly.
682
676
 
683
- *Bogdan Gusiev*, *Jon Hinson*
677
+ ```ruby
678
+ david_and_mary = Author.where(id: david.id..mary.id)
684
679
 
685
- * Rework `ActiveRecord::Relation#last`.
680
+ # both conflict conditions exists
681
+ david_and_mary.merge(Author.where(id: bob)) # => []
686
682
 
687
- 1. Never perform additional SQL on loaded relation
688
- 2. Use SQL reverse order instead of loading relation if relation doesn't have limit
689
- 3. Deprecated relation loading when SQL order can not be automatically reversed
683
+ # mergee side condition is replaced by rewhere
684
+ david_and_mary.merge(Author.rewhere(id: bob)) # => [bob]
690
685
 
691
- Topic.order("title").load.last(3)
692
- # before: SELECT ...
693
- # after: No SQL
686
+ # mergee side condition is replaced by rewhere option
687
+ david_and_mary.merge(Author.where(id: bob), rewhere: true) # => [bob]
688
+ ```
694
689
 
695
- Topic.order("title").last
696
- # before: SELECT * FROM `topics`
697
- # after: SELECT * FROM `topics` ORDER BY `topics`.`title` DESC LIMIT 1
690
+ *Ryuta Kamizono*
698
691
 
699
- Topic.order("coalesce(author, title)").last
700
- # before: SELECT * FROM `topics`
701
- # after: Deprecation Warning for irreversible order
692
+ * Add support for finding records based on signed ids, which are tamper-proof, verified ids that can be
693
+ set to expire and scoped with a purpose. This is particularly useful for things like password reset
694
+ or email verification, where you want the bearer of the signed id to be able to interact with the
695
+ underlying record, but usually only within a certain time period.
702
696
 
703
- *Bogdan Gusiev*
697
+ ```ruby
698
+ signed_id = User.first.signed_id expires_in: 15.minutes, purpose: :password_reset
704
699
 
705
- * Allow `joins` to be unscoped.
700
+ User.find_signed signed_id # => nil, since the purpose does not match
706
701
 
707
- Fixes #13775.
702
+ travel 16.minutes
703
+ User.find_signed signed_id, purpose: :password_reset # => nil, since the signed id has expired
708
704
 
709
- *Takashi Kokubun*
705
+ travel_back
706
+ User.find_signed signed_id, purpose: :password_reset # => User.first
710
707
 
711
- * Add `#second_to_last` and `#third_to_last` finder methods.
708
+ User.find_signed! "bad data" # => ActiveSupport::MessageVerifier::InvalidSignature
709
+ ```
712
710
 
713
- *Brian Christian*
711
+ *DHH*
714
712
 
715
- * Added `numeric` helper into migrations.
713
+ * Support `ALGORITHM = INSTANT` DDL option for index operations on MySQL.
716
714
 
717
- Example:
715
+ *Ryuta Kamizono*
718
716
 
719
- create_table(:numeric_types) do |t|
720
- t.numeric :numeric_type, precision: 10, scale: 2
721
- end
717
+ * Fix index creation to preserve index comment in bulk change table on MySQL.
722
718
 
723
- *Mehmet Emin İNAÇ*
719
+ *Ryuta Kamizono*
724
720
 
725
- * Bumped the minimum supported version of PostgreSQL to >= 9.1.
726
- Both PG 9.0 and 8.4 are past their end of life date:
727
- http://www.postgresql.org/support/versioning/
721
+ * Allow `unscope` to be aware of table name qualified values.
728
722
 
729
- *Remo Mueller*
723
+ It is possible to unscope only the column in the specified table.
730
724
 
731
- * `ActiveRecord::Relation#reverse_order` throws `ActiveRecord::IrreversibleOrderError`
732
- when the order can not be reversed using current trivial algorithm.
733
- Also raises the same error when `#reverse_order` is called on
734
- relation without any order and table has no primary key:
725
+ ```ruby
726
+ posts = Post.joins(:comments).group(:"posts.hidden")
727
+ posts = posts.where("posts.hidden": false, "comments.hidden": false)
735
728
 
736
- Topic.order("concat(author_name, title)").reverse_order
737
- # Before: SELECT `topics`.* FROM `topics` ORDER BY concat(author_name DESC, title) DESC
738
- # After: raises ActiveRecord::IrreversibleOrderError
739
- Edge.all.reverse_order
740
- # Before: SELECT `edges`.* FROM `edges` ORDER BY `edges`.`` DESC
741
- # After: raises ActiveRecord::IrreversibleOrderError
729
+ posts.count
730
+ # => { false => 10 }
742
731
 
743
- *Bogdan Gusiev*
732
+ # unscope both hidden columns
733
+ posts.unscope(where: :hidden).count
734
+ # => { false => 11, true => 1 }
744
735
 
745
- * Improve schema_migrations insertion performance by inserting all versions
746
- in one INSERT SQL.
736
+ # unscope only comments.hidden column
737
+ posts.unscope(where: :"comments.hidden").count
738
+ # => { false => 11 }
739
+ ```
747
740
 
748
- *Akira Matsuda*, *Naoto Koshikawa*
741
+ *Ryuta Kamizono*, *Slava Korolev*
749
742
 
750
- * Using `references` or `belongs_to` in migrations will always add index
751
- for the referenced column by default, without adding `index: true` option
752
- to generated migration file. Users can opt out of this by passing
753
- `index: false`.
743
+ * Fix `rewhere` to truly overwrite collided where clause by new where clause.
754
744
 
755
- Fixes #18146.
745
+ ```ruby
746
+ steve = Person.find_by(name: "Steve")
747
+ david = Author.find_by(name: "David")
756
748
 
757
- *Matthew Draper*, *Prathamesh Sonpatki*
749
+ relation = Essay.where(writer: steve)
758
750
 
759
- * Run `type` attributes through attributes API type-casting before
760
- instantiating the corresponding subclass. This makes it possible to define
761
- custom STI mappings.
751
+ # Before
752
+ relation.rewhere(writer: david).to_a # => []
762
753
 
763
- Fixes #21986.
754
+ # After
755
+ relation.rewhere(writer: david).to_a # => [david]
756
+ ```
764
757
 
765
- *Yves Senn*
758
+ *Ryuta Kamizono*
766
759
 
767
- * Don't try to quote functions or expressions passed to `:default` option if
768
- they are passed as procs.
760
+ * Inspect time attributes with subsec and time zone offset.
769
761
 
770
- This will generate proper query with the passed function or expression for
771
- the default option, instead of trying to quote it in incorrect fashion.
762
+ ```ruby
763
+ p Knot.create
764
+ => #<Knot id: 1, created_at: "2016-05-05 01:29:47.116928000 +0000">
765
+ ```
772
766
 
773
- Example:
767
+ *akinomaeni*, *Jonathan Hefner*
774
768
 
775
- create_table :posts do |t|
776
- t.datetime :published_at, default: -> { 'NOW()' }
777
- end
769
+ * Deprecate passing a column to `type_cast`.
778
770
 
779
771
  *Ryuta Kamizono*
780
772
 
781
- * Fix regression when loading fixture files with symbol keys.
773
+ * Deprecate `in_clause_length` and `allowed_index_name_length` in `DatabaseLimits`.
782
774
 
783
- Fixes #22584.
775
+ *Ryuta Kamizono*
784
776
 
785
- *Yves Senn*
777
+ * Support bulk insert/upsert on relation to preserve scope values.
786
778
 
787
- * Use `version` column as primary key for schema_migrations table because
788
- `schema_migrations` versions are guaranteed to be unique.
779
+ *Josef Šimánek*, *Ryuta Kamizono*
789
780
 
790
- This makes it possible to use `update_attributes` on models that do
791
- not have a primary key.
781
+ * Preserve column comment value on changing column name on MySQL.
792
782
 
793
- *Richard Schneeman*
783
+ *Islam Taha*
794
784
 
795
- * Add short-hand methods for text and blob types in MySQL.
785
+ * Add support for `if_exists` option for removing an index.
796
786
 
797
- In Pg and Sqlite3, `:text` and `:binary` have variable unlimited length.
798
- But in MySQL, these have limited length for each types (ref #21591, #21619).
799
- This change adds short-hand methods for each text and blob types.
787
+ 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.
800
788
 
801
- Example:
789
+ *Eileen M. Uchitelle*
802
790
 
803
- create_table :foos do |t|
804
- t.tinyblob :tiny_blob
805
- t.mediumblob :medium_blob
806
- t.longblob :long_blob
807
- t.tinytext :tiny_text
808
- t.mediumtext :medium_text
809
- t.longtext :long_text
810
- end
791
+ * Remove ibm_db, informix, mssql, oracle, and oracle12 Arel visitors which are not used in the code base.
811
792
 
812
793
  *Ryuta Kamizono*
813
794
 
814
- * Take into account UTC offset when assigning string representation of
815
- timestamp with offset specified to attribute of time type.
795
+ * Prevent `build_association` from `touching` a parent record if the record isn't persisted for `has_one` associations.
816
796
 
817
- *Andrey Novikov*
818
-
819
- * When calling `first` with a `limit` argument, return directly from the
820
- `loaded?` records if available.
797
+ Fixes #38219.
821
798
 
822
- *Ben Woosley*
799
+ *Josh Brody*
823
800
 
824
- * Deprecate sending the `offset` argument to `find_nth`. Please use the
825
- `offset` method on relation instead.
801
+ * Add support for `if_not_exists` option for adding index.
826
802
 
827
- *Ben Woosley*
803
+ The `add_index` method respects `if_not_exists` option. If it is set to true
804
+ index won't be added.
828
805
 
829
- * Limit record touching to once per transaction.
806
+ Usage:
830
807
 
831
- If you have a parent/grand-parent relation like:
832
-
833
- Comment belongs_to :message, touch: true
834
- Message belongs_to :project, touch: true
835
- Project belongs_to :account, touch: true
808
+ ```ruby
809
+ add_index :users, :account_id, if_not_exists: true
810
+ ```
836
811
 
837
- When the lowest entry(`Comment`) is saved, now, it won't repeat the touch
838
- call multiple times for the parent records.
812
+ The `if_not_exists` option passed to `create_table` also gets propagated to indexes
813
+ created within that migration so that if table and its indexes exist then there is no
814
+ attempt to create them again.
839
815
 
840
- Related #18606.
816
+ *Prathamesh Sonpatki*
841
817
 
842
- *arthurnn*
818
+ * Add `ActiveRecord::Base#previously_new_record?` to show if a record was new before the last save.
843
819
 
844
- * Order the result of `find(ids)` to match the passed array, if the relation
845
- has no explicit order defined.
820
+ *Tom Ward*
846
821
 
847
- Fixes #20338.
822
+ * Support descending order for `find_each`, `find_in_batches`, and `in_batches`.
848
823
 
849
- *Miguel Grazziotin*, *Matthew Draper*
824
+ 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.
850
825
 
851
- * Omit default limit values in dumped schema. It's tidier, and if the defaults
852
- change in the future, we can address that via Migration API Versioning.
826
+ This change allows reversing the order, batching from newest to oldest. This is useful when you need to process newer batches of records first.
853
827
 
854
- *Jean Boussier*
828
+ Pass `order: :desc` to yield batches in descending order. The default remains `order: :asc`.
855
829
 
856
- * Support passing the schema name as a prefix to table name in
857
- `ConnectionAdapters::SchemaStatements#indexes`. Previously the prefix would
858
- be considered a full part of the index name, and only the schema in the
859
- current search path would be considered.
830
+ ```ruby
831
+ Person.find_each(order: :desc) do |person|
832
+ person.party_all_night!
833
+ end
834
+ ```
860
835
 
861
- *Grey Baker*
836
+ *Alexey Vasiliev*
862
837
 
863
- * Ignore index name in `index_exists?` and `remove_index` when not passed a
864
- name to check for.
838
+ * Fix `insert_all` with enum values.
865
839
 
866
- *Grey Baker*
840
+ Fixes #38716.
867
841
 
868
- * Extract support for the legacy `mysql` database adapter from core. It will
869
- live on in a separate gem for now, but most users should just use `mysql2`.
842
+ *Joel Blum*
870
843
 
871
- *Abdelkader Boudih*
844
+ * Add support for `db:rollback:name` for multiple database applications.
872
845
 
873
- * ApplicationRecord is a new superclass for all app models, analogous to app
874
- controllers subclassing ApplicationController instead of
875
- ActionController::Base. This gives apps a single spot to configure app-wide
876
- model behavior.
846
+ Multiple database applications will now raise if `db:rollback` is call and recommend using the `db:rollback:[NAME]` to rollback migrations.
877
847
 
878
- Newly generated applications have `app/models/application_record.rb`
879
- present by default.
848
+ *Eileen M. Uchitelle*
880
849
 
881
- *Genadi Samokovarov*
850
+ * `Relation#pick` now uses already loaded results instead of making another query.
882
851
 
883
- * Version the API presented to migration classes, so we can change parameter
884
- defaults without breaking existing migrations, or forcing them to be
885
- rewritten through a deprecation cycle.
852
+ *Eugene Kenny*
886
853
 
887
- New migrations specify the Rails version they were written for:
854
+ * Deprecate using `return`, `break` or `throw` to exit a transaction block after writes.
888
855
 
889
- class AddStatusToOrders < ActiveRecord::Migration[5.0]
890
- def change
891
- # ...
892
- end
893
- end
856
+ *Dylan Thacker-Smith*
894
857
 
895
- *Matthew Draper*, *Ravil Bayramgalin*
858
+ * Dump the schema or structure of a database when calling `db:migrate:name`.
896
859
 
897
- * Use bind params for `limit` and `offset`. This will generate significantly
898
- fewer prepared statements for common tasks like pagination. To support this
899
- change, passing a string containing a comma to `limit` has been deprecated,
900
- and passing an Arel node to `limit` is no longer supported.
860
+ 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.
901
861
 
902
- Fixes #22250.
862
+ Going forward, calls to `rails db:migrate:name` will dump the schema (or structure) of the database being migrated.
903
863
 
904
- *Sean Griffin*
864
+ *Kyle Thompson*
905
865
 
906
- * Introduce after_{create,update,delete}_commit callbacks.
866
+ * Reset the `ActiveRecord::Base` connection after `rails db:migrate:name`.
907
867
 
908
- Before:
868
+ 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.
909
869
 
910
- after_commit :add_to_index_later, on: :create
911
- after_commit :update_in_index_later, on: :update
912
- after_commit :remove_from_index_later, on: :destroy
870
+ *Kyle Thompson*
913
871
 
914
- After:
872
+ * Disallow calling `connected_to` on subclasses of `ActiveRecord::Base`.
915
873
 
916
- after_create_commit :add_to_index_later
917
- after_update_commit :update_in_index_later
918
- after_destroy_commit :remove_from_index_later
874
+ 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.
919
875
 
920
- Fixes #22515.
876
+ *Eileen M. Uchitelle*, *John Crepezzi*
921
877
 
922
- *Genadi Samokovarov*
878
+ * Add support for horizontal sharding to `connects_to` and `connected_to`.
923
879
 
924
- * Respect the column default values for `inheritance_column` when
925
- instantiating records through the base class.
880
+ 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.
926
881
 
927
- Fixes #17121.
882
+ Usage:
928
883
 
929
- Example:
884
+ Given the following configuration:
930
885
 
931
- # The schema of BaseModel has `t.string :type, default: 'SubType'`
932
- subtype = BaseModel.new
933
- assert_equals SubType, subtype.class
886
+ ```yaml
887
+ # config/database.yml
888
+ production:
889
+ primary:
890
+ database: my_database
891
+ primary_shard_one:
892
+ database: my_database_shard_one
893
+ ```
934
894
 
935
- *Kuldeep Aggarwal*
895
+ Connect to multiple shards:
936
896
 
937
- * Fix `rake db:structure:dump` on Postgres when multiple schemas are used.
897
+ ```ruby
898
+ class ApplicationRecord < ActiveRecord::Base
899
+ self.abstract_class = true
938
900
 
939
- Fixes #22346.
901
+ connects_to shards: {
902
+ default: { writing: :primary },
903
+ shard_one: { writing: :primary_shard_one }
904
+ }
905
+ ```
940
906
 
941
- *Nick Muerdter*, *ckoenig*
907
+ Swap between shards in your controller / model code:
942
908
 
943
- * Add schema dumping support for PostgreSQL geometric data types.
909
+ ```ruby
910
+ ActiveRecord::Base.connected_to(shard: :shard_one) do
911
+ # Read from shard one
912
+ end
913
+ ```
944
914
 
945
- *Ryuta Kamizono*
915
+ The horizontal sharding API also supports read replicas. See guides for more details.
946
916
 
947
- * Except keys of `build_record`'s argument from `create_scope` in `initialize_attributes`.
917
+ *Eileen M. Uchitelle*, *John Crepezzi*
948
918
 
949
- Fixes #21893.
919
+ * Deprecate `spec_name` in favor of `name` on database configurations.
950
920
 
951
- *Yuichiro Kaneko*
921
+ The accessors for `spec_name` on `configs_for` and `DatabaseConfig` are deprecated. Please use `name` instead.
952
922
 
953
- * Deprecate `connection.tables` on the SQLite3 and MySQL adapters.
954
- Also deprecate passing arguments to `#tables`.
955
- And deprecate `table_exists?`.
923
+ Deprecated behavior:
956
924
 
957
- The `#tables` method of some adapters (mysql, mysql2, sqlite3) would return
958
- both tables and views while others (postgresql) just return tables. To make
959
- their behavior consistent, `#tables` will return only tables in the future.
925
+ ```ruby
926
+ db_config = ActiveRecord::Base.configs_for(env_name: "development", spec_name: "primary")
927
+ db_config.spec_name
928
+ ```
960
929
 
961
- The `#table_exists?` method would check both tables and views. To make
962
- their behavior consistent with `#tables`, `#table_exists?` will check only
963
- tables in the future.
930
+ New behavior:
964
931
 
965
- *Yuichiro Kaneko*
932
+ ```ruby
933
+ db_config = ActiveRecord::Base.configs_for(env_name: "development", name: "primary")
934
+ db_config.name
935
+ ```
966
936
 
967
- * Improve support for non Active Record objects on `validates_associated`
937
+ *Eileen M. Uchitelle*
968
938
 
969
- Skipping `marked_for_destruction?` when the associated object does not responds
970
- to it make easier to validate virtual associations built on top of Active Model
971
- objects and/or serialized objects that implement a `valid?` instance method.
939
+ * Add additional database-specific rake tasks for multi-database users.
972
940
 
973
- *Kassio Borges*, *Lucas Mazza*
941
+ Previously, `rails db:create`, `rails db:drop`, and `rails db:migrate` were the only rails tasks that could operate on a single
942
+ database. For example:
974
943
 
975
- * Change connection management middleware to return a new response with
976
- a body proxy, rather than mutating the original.
944
+ ```
945
+ rails db:create
946
+ rails db:create:primary
947
+ rails db:create:animals
948
+ rails db:drop
949
+ rails db:drop:primary
950
+ rails db:drop:animals
951
+ rails db:migrate
952
+ rails db:migrate:primary
953
+ rails db:migrate:animals
954
+ ```
977
955
 
978
- *Kevin Buchanan*
956
+ With these changes, `rails db:schema:dump`, `rails db:schema:load`, `rails db:structure:dump`, `rails db:structure:load` and
957
+ `rails db:test:prepare` can additionally operate on a single database. For example:
979
958
 
980
- * Make `db:migrate:status` to render `1_some.rb` format migrate files.
959
+ ```
960
+ rails db:schema:dump
961
+ rails db:schema:dump:primary
962
+ rails db:schema:dump:animals
963
+ rails db:schema:load
964
+ rails db:schema:load:primary
965
+ rails db:schema:load:animals
966
+ rails db:structure:dump
967
+ rails db:structure:dump:primary
968
+ rails db:structure:dump:animals
969
+ rails db:structure:load
970
+ rails db:structure:load:primary
971
+ rails db:structure:load:animals
972
+ rails db:test:prepare
973
+ rails db:test:prepare:primary
974
+ rails db:test:prepare:animals
975
+ ```
981
976
 
982
- These files are in `db/migrate`:
977
+ *Kyle Thompson*
983
978
 
984
- * 1_valid_people_have_last_names.rb
985
- * 20150819202140_irreversible_migration.rb
986
- * 20150823202140_add_admin_flag_to_users.rb
987
- * 20150823202141_migration_tests.rb
988
- * 2_we_need_reminders.rb
989
- * 3_innocent_jointable.rb
979
+ * Add support for `strict_loading` mode on association declarations.
990
980
 
991
- Before:
981
+ 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.
992
982
 
993
- $ bundle exec rake db:migrate:status
994
- ...
983
+ Usage:
995
984
 
996
- Status Migration ID Migration Name
997
- --------------------------------------------------
998
- up 001 ********** NO FILE **********
999
- up 002 ********** NO FILE **********
1000
- up 003 ********** NO FILE **********
1001
- up 20150819202140 Irreversible migration
1002
- up 20150823202140 Add admin flag to users
1003
- up 20150823202141 Migration tests
985
+ ```ruby
986
+ class Developer < ApplicationRecord
987
+ has_many :projects, strict_loading: true
988
+ end
1004
989
 
1005
- After:
990
+ dev = Developer.first
991
+ dev.projects.first
992
+ # => ActiveRecord::StrictLoadingViolationError: The projects association is marked as strict_loading and cannot be lazily loaded.
993
+ ```
1006
994
 
1007
- $ bundle exec rake db:migrate:status
1008
- ...
995
+ *Kevin Deisz*
1009
996
 
1010
- Status Migration ID Migration Name
1011
- --------------------------------------------------
1012
- up 001 Valid people have last names
1013
- up 002 We need reminders
1014
- up 003 Innocent jointable
1015
- up 20150819202140 Irreversible migration
1016
- up 20150823202140 Add admin flag to users
1017
- up 20150823202141 Migration tests
997
+ * Add support for `strict_loading` mode to prevent lazy loading of records.
1018
998
 
1019
- *Yuichiro Kaneko*
999
+ 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.
1020
1000
 
1021
- * Define `ActiveRecord::Sanitization.sanitize_sql_for_order` and use it inside
1022
- `preprocess_order_args`.
1001
+ Usage:
1023
1002
 
1024
- *Yuichiro Kaneko*
1003
+ ```ruby
1004
+ dev = Developer.strict_loading.first
1005
+ dev.audit_logs.to_a
1006
+ # => ActiveRecord::StrictLoadingViolationError: Developer is marked as strict_loading and AuditLog cannot be lazily loaded.
1007
+ ```
1025
1008
 
1026
- * Allow bigint with default nil for avoiding auto increment primary key.
1009
+ *Eileen M. Uchitelle*, *Aaron Patterson*
1027
1010
 
1028
- *Ryuta Kamizono*
1011
+ * Add support for PostgreSQL 11+ partitioned indexes when using `upsert_all`.
1029
1012
 
1030
- * Remove `DEFAULT_CHARSET` and `DEFAULT_COLLATION` in `MySQLDatabaseTasks`.
1013
+ *Sebastián Palma*
1031
1014
 
1032
- We should omit the collation entirely rather than providing a default.
1033
- Then the choice is the responsibility of the server and MySQL distribution.
1015
+ * Adds support for `if_not_exists` to `add_column` and `if_exists` to `remove_column`.
1034
1016
 
1035
- *Ryuta Kamizono*
1017
+ 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.
1036
1018
 
1037
- * Alias `ActiveRecord::Relation#left_joins` to
1038
- `ActiveRecord::Relation#left_outer_joins`.
1019
+ Example Usage:
1039
1020
 
1040
- *Takashi Kokubun*
1021
+ ```ruby
1022
+ class AddColumnTitle < ActiveRecord::Migration[6.1]
1023
+ def change
1024
+ add_column :posts, :title, :string, if_not_exists: true
1025
+ end
1026
+ end
1027
+ ```
1041
1028
 
1042
- * Use advisory locking to raise a `ConcurrentMigrationError` instead of
1043
- attempting to migrate when another migration is currently running.
1029
+ ```ruby
1030
+ class RemoveColumnTitle < ActiveRecord::Migration[6.1]
1031
+ def change
1032
+ remove_column :posts, :title, if_exists: true
1033
+ end
1034
+ end
1035
+ ```
1044
1036
 
1045
- *Sam Davies*
1037
+ *Eileen M. Uchitelle*
1046
1038
 
1047
- * Added `ActiveRecord::Relation#left_outer_joins`.
1039
+ * Regexp-escape table name for MS SQL Server.
1048
1040
 
1049
- Example:
1041
+ 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.
1050
1042
 
1051
- User.left_outer_joins(:posts)
1052
- # => SELECT "users".* FROM "users" LEFT OUTER JOIN "posts" ON
1053
- "posts"."user_id" = "users"."id"
1043
+ *Larry Reid*
1054
1044
 
1055
- *Florian Thomas*
1045
+ * Store advisory locks on their own named connection.
1056
1046
 
1057
- * Support passing an array to `order` for SQL parameter sanitization.
1047
+ 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.
1058
1048
 
1059
- *Aaron Suggs*
1049
+ 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.
1060
1050
 
1061
- * Avoid disabling errors on the PostgreSQL connection when enabling the
1062
- `standard_conforming_strings` setting. Errors were previously disabled because
1063
- the setting wasn't writable in Postgres 8.1 and didn't exist in earlier
1064
- versions. Now Rails only supports Postgres 8.2+ we're fine to assume the
1065
- setting exists. Disabling errors caused problems when using a connection
1066
- pooling tool like PgBouncer because it's not guaranteed to have the same
1067
- connection between calls to `execute` and it could leave the connection
1068
- with errors disabled.
1051
+ *Eileen M. Uchitelle*, *John Crepezzi*
1069
1052
 
1070
- Fixes #22101.
1053
+ * Allow schema cache path to be defined in the database configuration file.
1071
1054
 
1072
- *Harry Marr*
1055
+ For example:
1073
1056
 
1074
- * Set `scope.reordering_value` to `true` if `:reordering`-values are specified.
1057
+ ```yaml
1058
+ development:
1059
+ adapter: postgresql
1060
+ database: blog_development
1061
+ pool: 5
1062
+ schema_cache_path: tmp/schema/main.yml
1063
+ ```
1075
1064
 
1076
- Fixes #21886.
1065
+ *Katrina Owen*
1077
1066
 
1078
- *Hiroaki Izu*
1067
+ * Deprecate `#remove_connection` in favor of `#remove_connection_pool` when called on the handler.
1079
1068
 
1080
- * Add support for bidirectional destroy dependencies.
1069
+ `#remove_connection` is deprecated in order to support returning a `DatabaseConfig` object instead of a `Hash`. Use `#remove_connection_pool`, `#remove_connection` will be removed in 6.2.
1081
1070
 
1082
- Fixes #13609.
1071
+ *Eileen M. Uchitelle*, *John Crepezzi*
1083
1072
 
1084
- Example:
1073
+ * Deprecate `#default_hash` and it's alias `#[]` on database configurations.
1085
1074
 
1086
- class Content < ActiveRecord::Base
1087
- has_one :position, dependent: :destroy
1088
- end
1075
+ Applications should use `configs_for`. `#default_hash` and `#[]` will be removed in 6.2.
1089
1076
 
1090
- class Position < ActiveRecord::Base
1091
- belongs_to :content, dependent: :destroy
1092
- end
1077
+ *Eileen M. Uchitelle*, *John Crepezzi*
1093
1078
 
1094
- *Seb Jacobs*
1079
+ * Add scale support to `ActiveRecord::Validations::NumericalityValidator`.
1095
1080
 
1096
- * Includes HABTM returns correct size now. It's caused by the join dependency
1097
- only instantiates one HABTM object because the join table hasn't a primary key.
1081
+ *Gannon McGibbon*
1098
1082
 
1099
- Fixes #16032.
1083
+ * Find orphans by looking for missing relations through chaining `where.missing`:
1100
1084
 
1101
- Examples:
1085
+ Before:
1102
1086
 
1103
- before:
1087
+ ```ruby
1088
+ Post.left_joins(:author).where(authors: { id: nil })
1089
+ ```
1104
1090
 
1105
- Project.first.salaried_developers.size # => 3
1106
- Project.includes(:salaried_developers).first.salaried_developers.size # => 1
1091
+ After:
1107
1092
 
1108
- after:
1093
+ ```ruby
1094
+ Post.where.missing(:author)
1095
+ ```
1109
1096
 
1110
- Project.first.salaried_developers.size # => 3
1111
- Project.includes(:salaried_developers).first.salaried_developers.size # => 3
1097
+ *Tom Rossi*
1112
1098
 
1113
- *Bigxiang*
1099
+ * Ensure `:reading` connections always raise if a write is attempted.
1114
1100
 
1115
- * Add option to index errors in nested attributes.
1101
+ 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`.
1116
1102
 
1117
- For models which have nested attributes, errors within those models will
1118
- now be indexed if `:index_errors` option is set to true when defining a
1119
- `has_many` relationship or by setting the configuration option
1120
- `config.active_record.index_nested_attribute_errors` to true.
1103
+ *Eileen M. Uchitelle*
1121
1104
 
1122
- Example:
1105
+ * Deprecate `"primary"` as the `connection_specification_name` for `ActiveRecord::Base`.
1123
1106
 
1124
- class Guitar < ActiveRecord::Base
1125
- has_many :tuning_pegs, index_errors: true
1126
- accepts_nested_attributes_for :tuning_pegs
1127
- end
1107
+ `"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"`.
1128
1108
 
1129
- class TuningPeg < ActiveRecord::Base
1130
- belongs_to :guitar
1131
- validates_numericality_of :pitch
1132
- end
1109
+ *Eileen M. Uchitelle*, *John Crepezzi*
1133
1110
 
1134
- # Before
1135
- guitar.errors["tuning_pegs.pitch"] = ["is not a number"]
1111
+ * Add `ActiveRecord::Validations::NumericalityValidator` with
1112
+ support for casting floats using a database columns' precision value.
1136
1113
 
1137
- # After
1138
- guitar.errors["tuning_pegs[1].pitch"] = ["is not a number"]
1114
+ *Gannon McGibbon*
1139
1115
 
1140
- *Michael Probber*, *Terence Sun*
1116
+ * Enforce fresh ETag header after a collection's contents change by adding
1117
+ ActiveRecord::Relation#cache_key_with_version. This method will be used by
1118
+ ActionController::ConditionalGet to ensure that when collection cache versioning
1119
+ is enabled, requests using ConditionalGet don't return the same ETag header
1120
+ after a collection is modified.
1141
1121
 
1142
- * Exit with non-zero status for failed database rake tasks.
1122
+ Fixes #38078.
1143
1123
 
1144
- *Jay Hayes*
1124
+ *Aaron Lipman*
1145
1125
 
1146
- * Queries such as `Computer.joins(:monitor).group(:status).count` will now be
1147
- interpreted as `Computer.joins(:monitor).group('computers.status').count`
1148
- so that when `Computer` and `Monitor` have both `status` columns we don't
1149
- have conflicts in projection.
1126
+ * Skip test database when running `db:create` or `db:drop` in development
1127
+ with `DATABASE_URL` set.
1150
1128
 
1151
- *Rafael Sales*
1129
+ *Brian Buchalter*
1152
1130
 
1153
- * Add ability to default to `uuid` as primary key when generating database migrations.
1131
+ * Don't allow mutations on the database configurations hash.
1154
1132
 
1155
- Example:
1133
+ 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.
1156
1134
 
1157
- config.generators do |g|
1158
- g.orm :active_record, primary_key_type: :uuid
1159
- end
1135
+ Before:
1160
1136
 
1161
- *Jon McCartie*
1137
+ ```ruby
1138
+ @db_config = ActiveRecord::Base.configurations.configs_for(env_name: "test", spec_name: "primary")
1139
+ @db_config.configuration_hash.merge!(idle_timeout: "0.02")
1140
+ ```
1162
1141
 
1163
- * Don't cache arguments in `#find_by` if they are an `ActiveRecord::Relation`.
1142
+ After:
1164
1143
 
1165
- Fixes #20817.
1144
+ ```ruby
1145
+ @db_config = ActiveRecord::Base.configurations.configs_for(env_name: "test", spec_name: "primary")
1146
+ config = @db_config.configuration_hash.merge(idle_timeout: "0.02")
1147
+ db_config = ActiveRecord::DatabaseConfigurations::HashConfig.new(@db_config.env_name, @db_config.spec_name, config)
1148
+ ```
1166
1149
 
1167
- *Hiroaki Izu*
1150
+ *Eileen M. Uchitelle*, *John Crepezzi*
1168
1151
 
1169
- * Qualify column name inserted by `group` in calculation.
1152
+ * Remove `:connection_id` from the `sql.active_record` notification.
1170
1153
 
1171
- Giving `group` an unqualified column name now works, even if the relation
1172
- has `JOIN` with another table which also has a column of the name.
1154
+ *Aaron Patterson*, *Rafael Mendonça França*
1173
1155
 
1174
- *Soutaro Matsumoto*
1156
+ * The `:name` key will no longer be returned as part of `DatabaseConfig#configuration_hash`. Please use `DatabaseConfig#owner_name` instead.
1175
1157
 
1176
- * Don't cache prepared statements containing an IN clause or a SQL literal, as
1177
- these queries will change often and are unlikely to have a cache hit.
1158
+ *Eileen M. Uchitelle*, *John Crepezzi*
1178
1159
 
1179
- *Sean Griffin*
1160
+ * ActiveRecord's `belongs_to_required_by_default` flag can now be set per model.
1180
1161
 
1181
- * Fix `rewhere` in a `has_many` association.
1162
+ You can now opt-out/opt-in specific models from having their associations required
1163
+ by default.
1182
1164
 
1183
- Fixes #21955.
1165
+ This change is meant to ease the process of migrating all your models to have
1166
+ their association required.
1184
1167
 
1185
- *Josh Branchaud*, *Kal*
1168
+ *Edouard Chin*
1186
1169
 
1187
- * `where` raises ArgumentError on unsupported types.
1170
+ * The `connection_config` method has been deprecated, please use `connection_db_config` instead which will return a `DatabaseConfigurations::DatabaseConfig` instead of a `Hash`.
1188
1171
 
1189
- Fixes #20473.
1172
+ *Eileen M. Uchitelle*, *John Crepezzi*
1190
1173
 
1191
- *Jake Worth*
1174
+ * Retain explicit selections on the base model after applying `includes` and `joins`.
1192
1175
 
1193
- * Add an immutable string type to help reduce memory usage for apps which do
1194
- not need mutation detection on strings.
1176
+ Resolves #34889.
1195
1177
 
1196
- *Sean Griffin*
1178
+ *Patrick Rebsch*
1197
1179
 
1198
- * Give `ActiveRecord::Relation#update` its own deprecation warning when
1199
- passed an `ActiveRecord::Base` instance.
1180
+ * 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.
1200
1181
 
1201
- Fixes #21945.
1182
+ *Eileen M. Uchitelle*, *John Crepezzi*
1202
1183
 
1203
- *Ted Johansson*
1184
+ * Allow attributes to be fetched from Arel node groupings.
1204
1185
 
1205
- * Make it possible to pass `:to_table` when adding a foreign key through
1206
- `add_reference`.
1186
+ *Jeff Emminger*, *Gannon McGibbon*
1207
1187
 
1208
- Fixes #21563.
1188
+ * A database URL can now contain a querystring value that contains an equal sign. This is needed to support passing PostgreSQL `options`.
1209
1189
 
1210
- *Yves Senn*
1190
+ *Joshua Flanagan*
1211
1191
 
1212
- * No longer pass deprecated option `-i` to `pg_dump`.
1192
+ * 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`.
1213
1193
 
1214
- *Paul Sadauskas*
1194
+ *John Crepezzi*
1215
1195
 
1216
- * Concurrent `AR::Base#increment!` and `#decrement!` on the same record
1217
- are all reflected in the database rather than overwriting each other.
1196
+ * Specifying `implicit_order_column` now subsorts the records by primary key if available to ensure deterministic results.
1218
1197
 
1219
- *Bogdan Gusiev*
1198
+ *Paweł Urbanek*
1220
1199
 
1221
- * Avoid leaking the first relation we call `first` on, per model.
1200
+ * `where(attr => [])` now loads an empty result without making a query.
1222
1201
 
1223
- Fixes #21921.
1202
+ *John Hawthorn*
1224
1203
 
1225
- *Matthew Draper*, *Jean Boussier*
1204
+ * Fixed the performance regression for `primary_keys` introduced MySQL 8.0.
1226
1205
 
1227
- * Remove unused `pk_and_sequence_for` in `AbstractMysqlAdapter`.
1206
+ *Hiroyuki Ishii*
1228
1207
 
1229
- *Ryuta Kamizono*
1208
+ * Add support for `belongs_to` to `has_many` inversing.
1230
1209
 
1231
- * Allow fixtures files to set the model class in the YAML file itself.
1210
+ *Gannon McGibbon*
1232
1211
 
1233
- To load the fixtures file `accounts.yml` as the `User` model, use:
1212
+ * Allow length configuration for `has_secure_token` method. The minimum length
1213
+ is set at 24 characters.
1234
1214
 
1235
- _fixture:
1236
- model_class: User
1237
- david:
1238
- name: David
1215
+ Before:
1239
1216
 
1240
- Fixes #9516.
1217
+ ```ruby
1218
+ has_secure_token :auth_token
1219
+ ```
1241
1220
 
1242
- *Roque Pinel*
1221
+ After:
1243
1222
 
1244
- * Don't require a database connection to load a class which uses acceptance
1245
- validations.
1223
+ ```ruby
1224
+ has_secure_token :default_token # 24 characters
1225
+ has_secure_token :auth_token, length: 36 # 36 characters
1226
+ has_secure_token :invalid_token, length: 12 # => ActiveRecord::SecureToken::MinimumLengthError
1227
+ ```
1246
1228
 
1247
- *Sean Griffin*
1229
+ *Bernardo de Araujo*
1248
1230
 
1249
- * Correctly apply `unscope` when preloading through associations.
1231
+ * Deprecate `DatabaseConfigurations#to_h`. These connection hashes are still available via `ActiveRecord::Base.configurations.configs_for`.
1250
1232
 
1251
- *Jimmy Bourassa*
1233
+ *Eileen Uchitelle*, *John Crepezzi*
1252
1234
 
1253
- * Fixed taking precision into count when assigning a value to timestamp attribute.
1235
+ * 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.
1254
1236
 
1255
- Timestamp column can have less precision than ruby timestamp
1256
- In result in how big a fraction of a second can be stored in the
1257
- database.
1237
+ *John Crepezzi*, *Eileen Uchitelle*
1258
1238
 
1239
+ * Allow column names to be passed to `remove_index` positionally along with other options.
1259
1240
 
1260
- m = Model.create!
1261
- m.created_at.usec == m.reload.created_at.usec # => false
1262
- # due to different precision in Time.now and database column
1241
+ Passing other options can be necessary to make `remove_index` correctly reversible.
1263
1242
 
1264
- If the precision is low enough, (mysql default is 0, so it is always low
1265
- enough by default) the value changes when model is reloaded from the
1266
- database. This patch fixes that issue ensuring that any timestamp
1267
- assigned as an attribute is converted to column precision under the
1268
- attribute.
1243
+ Before:
1269
1244
 
1270
- *Bogdan Gusiev*
1245
+ add_index :reports, :report_id # => works
1246
+ add_index :reports, :report_id, unique: true # => works
1247
+ remove_index :reports, :report_id # => works
1248
+ remove_index :reports, :report_id, unique: true # => ArgumentError
1271
1249
 
1272
- * Introduce `connection.data_sources` and `connection.data_source_exists?`.
1273
- These methods determine what relations can be used to back Active Record
1274
- models (usually tables and views).
1250
+ After:
1275
1251
 
1276
- Also deprecate `SchemaCache#tables`, `SchemaCache#table_exists?` and
1277
- `SchemaCache#clear_table_cache!` in favor of their new data source
1278
- counterparts.
1252
+ remove_index :reports, :report_id, unique: true # => works
1279
1253
 
1280
- *Yves Senn*, *Matthew Draper*
1254
+ *Eugene Kenny*
1281
1255
 
1282
- * Add `ActiveRecord::Base.ignored_columns` to make some columns
1283
- invisible from Active Record.
1256
+ * Allow bulk `ALTER` statements to drop and recreate indexes with the same name.
1284
1257
 
1285
- *Jean Boussier*
1258
+ *Eugene Kenny*
1286
1259
 
1287
- * `ActiveRecord::Tasks::MySQLDatabaseTasks` fails if shellout to
1288
- mysql commands (like `mysqldump`) is not successful.
1260
+ * `insert`, `insert_all`, `upsert`, and `upsert_all` now clear the query cache.
1289
1261
 
1290
- *Steve Mitchell*
1262
+ *Eugene Kenny*
1291
1263
 
1292
- * Ensure `select` quotes aliased attributes, even when using `from`.
1264
+ * Call `while_preventing_writes` directly from `connected_to`.
1293
1265
 
1294
- Fixes #21488.
1266
+ 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)`.
1295
1267
 
1296
- *Sean Griffin*, *@johanlunds*
1268
+ 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.
1297
1269
 
1298
- * MySQL: support `unsigned` numeric data types.
1270
+ *Eileen M. Uchitelle*
1299
1271
 
1300
- Example:
1272
+ * Improve detection of ActiveRecord::StatementTimeout with mysql2 adapter in the edge case when the query is terminated during filesort.
1301
1273
 
1302
- create_table :foos do |t|
1303
- t.unsigned_integer :quantity
1304
- t.unsigned_bigint :total
1305
- t.unsigned_float :percentage
1306
- t.unsigned_decimal :price, precision: 10, scale: 2
1307
- end
1274
+ *Kir Shatrov*
1308
1275
 
1309
- The `unsigned: true` option may be used for the primary key:
1276
+ * Stop trying to read yaml file fixtures when loading Active Record fixtures.
1310
1277
 
1311
- create_table :foos, id: :bigint, unsigned: true do |t|
1312
-
1313
- end
1278
+ *Gannon McGibbon*
1314
1279
 
1315
- *Ryuta Kamizono*
1280
+ * Deprecate `.reorder(nil)` with `.first` / `.first!` taking non-deterministic result.
1316
1281
 
1317
- * Add `#views` and `#view_exists?` methods on connection adapters.
1282
+ To continue taking non-deterministic result, use `.take` / `.take!` instead.
1318
1283
 
1319
1284
  *Ryuta Kamizono*
1320
1285
 
1321
- * Correctly dump composite primary key.
1322
-
1323
- Example:
1286
+ * Preserve user supplied joins order as much as possible.
1324
1287
 
1325
- create_table :barcodes, primary_key: ["region", "code"] do |t|
1326
- t.string :region
1327
- t.integer :code
1328
- end
1288
+ Fixes #36761, #34328, #24281, #12953.
1329
1289
 
1330
1290
  *Ryuta Kamizono*
1331
1291
 
1332
- * Lookup the attribute name for `restrict_with_error` messages on the
1333
- model class that defines the association.
1334
-
1335
- *kuboon*, *Ronak Jangir*
1336
-
1337
- * Correct query for PostgreSQL 8.2 compatibility.
1338
-
1339
- *Ben Murphy*, *Matthew Draper*
1340
-
1341
- * `bin/rails db:migrate` uses
1342
- `ActiveRecord::Tasks::DatabaseTasks.migrations_paths` instead of
1343
- `Migrator.migrations_paths`.
1344
-
1345
- *Tobias Bielohlawek*
1346
-
1347
- * Support dropping indexes concurrently in PostgreSQL.
1348
-
1349
- See http://www.postgresql.org/docs/9.4/static/sql-dropindex.html for more
1350
- details.
1351
-
1352
- *Grey Baker*
1353
-
1354
- * Deprecate passing conditions to `ActiveRecord::Relation#delete_all`
1355
- and `ActiveRecord::Relation#destroy_all`.
1356
-
1357
- *Wojciech Wnętrzak*
1358
-
1359
- * Instantiating an AR model with `ActionController::Parameters` now raises
1360
- an `ActiveModel::ForbiddenAttributesError` if the parameters include a
1361
- `type` field that has not been explicitly permitted. Previously, the
1362
- `type` field was simply ignored in the same situation.
1363
-
1364
- *Prem Sichanugrist*
1365
-
1366
- * PostgreSQL, `create_schema`, `drop_schema` and `rename_table` now quote
1367
- schema names.
1368
-
1369
- Fixes #21418.
1292
+ * Allow `matches_regex` and `does_not_match_regexp` on the MySQL Arel visitor.
1370
1293
 
1371
- Example:
1372
-
1373
- create_schema("my.schema")
1374
- # CREATE SCHEMA "my.schema";
1375
-
1376
- *Yves Senn*
1377
-
1378
- * PostgreSQL, add `:if_exists` option to `#drop_schema`. This makes it
1379
- possible to drop a schema that might exist without raising an exception if
1380
- it doesn't.
1381
-
1382
- *Yves Senn*
1383
-
1384
- * Only try to nullify has_one target association if the record is persisted.
1385
-
1386
- Fixes #21223.
1387
-
1388
- *Agis Anastasopoulos*
1294
+ *James Pearson*
1389
1295
 
1390
- * Uniqueness validator raises descriptive error when running on a persisted
1391
- record without primary key.
1296
+ * Allow specifying fixtures to be ignored by setting `ignore` in YAML file's '_fixture' section.
1392
1297
 
1393
- Fixes #21304.
1298
+ *Tongfei Gao*
1394
1299
 
1395
- *Yves Senn*
1300
+ * Make the DATABASE_URL env variable only affect the primary connection. Add new env variables for multiple databases.
1396
1301
 
1397
- * Add a native JSON data type support in MySQL.
1302
+ *John Crepezzi*, *Eileen Uchitelle*
1398
1303
 
1399
- Example:
1304
+ * Add a warning for enum elements with 'not_' prefix.
1400
1305
 
1401
- create_table :json_data_type do |t|
1402
- t.json :settings
1306
+ class Foo
1307
+ enum status: [:sent, :not_sent]
1403
1308
  end
1404
1309
 
1405
- *Ryuta Kamizono*
1406
-
1407
- * Descriptive error message when fixtures contain a missing column.
1408
-
1409
- Fixes #21201.
1310
+ *Edu Depetris*
1410
1311
 
1411
- *Yves Senn*
1312
+ * Make currency symbols optional for money column type in PostgreSQL.
1412
1313
 
1413
- * `ActiveRecord::Tasks::PostgreSQLDatabaseTasks` fail if shellout to
1414
- postgresql commands (like `pg_dump`) is not successful.
1314
+ *Joel Schneider*
1415
1315
 
1416
- *Bryan Paxton*, *Nate Berkopec*
1316
+ * Add support for beginless ranges, introduced in Ruby 2.7.
1417
1317
 
1418
- * Add `ActiveRecord::Relation#in_batches` to work with records and relations
1419
- in batches.
1318
+ *Josh Goodall*
1420
1319
 
1421
- Available options are `of` (batch size), `load`, `start`, and `finish`.
1320
+ * Add `database_exists?` method to connection adapters to check if a database exists.
1422
1321
 
1423
- Examples:
1322
+ *Guilherme Mansur*
1424
1323
 
1425
- Person.in_batches.each_record(&:party_all_night!)
1426
- Person.in_batches.update_all(awesome: true)
1427
- Person.in_batches.delete_all
1428
- Person.in_batches.each do |relation|
1429
- relation.delete_all
1430
- sleep 10 # Throttles the delete queries
1431
- end
1324
+ * Loading the schema for a model that has no `table_name` raises a `TableNotSpecified` error.
1432
1325
 
1433
- Fixes #20933.
1326
+ *Guilherme Mansur*, *Eugene Kenny*
1434
1327
 
1435
- *Sina Siadat*
1328
+ * PostgreSQL: Fix GROUP BY with ORDER BY virtual count attribute.
1436
1329
 
1437
- * Added methods for PostgreSQL geometric data types to use in migrations.
1330
+ Fixes #36022.
1438
1331
 
1439
- Example:
1332
+ *Ryuta Kamizono*
1440
1333
 
1441
- create_table :foo do |t|
1442
- t.line :foo_line
1443
- t.lseg :foo_lseg
1444
- t.box :foo_box
1445
- t.path :foo_path
1446
- t.polygon :foo_polygon
1447
- t.circle :foo_circle
1448
- end
1334
+ * Make ActiveRecord `ConnectionPool.connections` method thread-safe.
1449
1335
 
1450
- *Mehmet Emin İNAÇ*
1336
+ Fixes #36465.
1451
1337
 
1452
- * Add `cache_key` to `ActiveRecord::Relation`.
1338
+ *Jeff Doering*
1453
1339
 
1454
- Example:
1455
-
1456
- @users = User.where("name like ?", "%Alberto%")
1457
- @users.cache_key
1458
- # => "/users/query-5942b155a43b139f2471b872ac54251f-3-20150714212107656125000"
1459
-
1460
- *Alberto Fernández-Capel*
1461
-
1462
- * Properly allow uniqueness validations on primary keys.
1463
-
1464
- Fixes #20966.
1465
-
1466
- *Sean Griffin*, *presskey*
1467
-
1468
- * Don't raise an error if an association failed to destroy when `destroy` was
1469
- called on the parent (as opposed to `destroy!`).
1470
-
1471
- Fixes #20991.
1472
-
1473
- *Sean Griffin*
1474
-
1475
- * `ActiveRecord::RecordNotFound` modified to store model name, primary_key and
1476
- id of the caller model. It allows the catcher of this exception to make
1477
- a better decision to what to do with it.
1478
-
1479
- Example:
1480
-
1481
- class SomeAbstractController < ActionController::Base
1482
- rescue_from ActiveRecord::RecordNotFound, with: :redirect_to_404
1483
-
1484
- private def redirect_to_404(e)
1485
- return redirect_to(posts_url) if e.model == 'Post'
1486
- raise
1487
- end
1488
- end
1489
-
1490
- *Sameer Rahmani*
1491
-
1492
- * Deprecate the keys for association `restrict_dependent_destroy` errors in favor
1493
- of new key names.
1494
-
1495
- Previously `has_one` and `has_many` associations were using the
1496
- `one` and `many` keys respectively. Both of these keys have special
1497
- meaning in I18n (they are considered to be pluralizations) so by
1498
- renaming them to `has_one` and `has_many` we make the messages more explicit
1499
- and most importantly they don't clash with linguistical systems that need to
1500
- validate translation keys (and their pluralizations).
1501
-
1502
- The `:'restrict_dependent_destroy.one'` key should be replaced with
1503
- `:'restrict_dependent_destroy.has_one'`, and `:'restrict_dependent_destroy.many'`
1504
- with `:'restrict_dependent_destroy.has_many'`.
1505
-
1506
- *Roque Pinel*, *Christopher Dell*
1507
-
1508
- * Fix state being carried over from previous transaction.
1509
-
1510
- Considering the following example where `name` is a required attribute.
1511
- Before we had `new_record?` returning `true` for a persisted record:
1512
-
1513
- author = Author.create! name: 'foo'
1514
- author.name = nil
1515
- author.save # => false
1516
- author.new_record? # => true
1517
-
1518
- Fixes #20824.
1519
-
1520
- *Roque Pinel*
1521
-
1522
- * Correctly ignore `mark_for_destruction` when `autosave` isn't set to `true`
1523
- when validating associations.
1524
-
1525
- Fixes #20882.
1526
-
1527
- *Sean Griffin*
1528
-
1529
- * Fix a bug where counter_cache doesn't always work with polymorphic
1530
- relations.
1531
-
1532
- Fixes #16407.
1533
-
1534
- *Stefan Kanev*, *Sean Griffin*
1535
-
1536
- * Ensure that cyclic associations with autosave don't cause duplicate errors
1537
- to be added to the parent record.
1538
-
1539
- Fixes #20874.
1540
-
1541
- *Sean Griffin*
1542
-
1543
- * Ensure that `ActionController::Parameters` can still be passed to nested
1544
- attributes.
1545
-
1546
- Fixes #20922.
1547
-
1548
- *Sean Griffin*
1549
-
1550
- * Deprecate force association reload by passing a truthy argument to
1551
- association method.
1552
-
1553
- For collection association, you can call `#reload` on association proxy to
1554
- force a reload:
1555
-
1556
- @user.posts.reload # Instead of @user.posts(true)
1557
-
1558
- For singular association, you can call `#reload` on the parent object to
1559
- clear its association cache then call the association method:
1560
-
1561
- @user.reload.profile # Instead of @user.profile(true)
1562
-
1563
- Passing a truthy argument to force association to reload will be removed in
1564
- Rails 5.1.
1565
-
1566
- *Prem Sichanugrist*
1567
-
1568
- * Replaced `ActiveSupport::Concurrency::Latch` with `Concurrent::CountDownLatch`
1569
- from the concurrent-ruby gem.
1570
-
1571
- *Jerry D'Antonio*
1572
-
1573
- * Fix through associations using scopes having the scope merged multiple
1574
- times.
1575
-
1576
- Fixes #20721.
1577
- Fixes #20727.
1578
-
1579
- *Sean Griffin*
1580
-
1581
- * `ActiveRecord::Base.dump_schema_after_migration` applies migration tasks
1582
- other than `db:migrate`. (eg. `db:rollback`, `db:migrate:dup`, ...)
1583
-
1584
- Fixes #20743.
1585
-
1586
- *Yves Senn*
1587
-
1588
- * Add alternate syntax to make `change_column_default` reversible.
1589
-
1590
- User can pass in `:from` and `:to` to make `change_column_default` command
1591
- become reversible.
1592
-
1593
- Example:
1594
-
1595
- change_column_default :posts, :status, from: nil, to: "draft"
1596
- change_column_default :users, :authorized, from: true, to: false
1597
-
1598
- *Prem Sichanugrist*
1599
-
1600
- * Prevent error when using `force_reload: true` on an unassigned polymorphic
1601
- belongs_to association.
1602
-
1603
- Fixes #20426.
1604
-
1605
- *James Dabbs*
1606
-
1607
- * Correctly raise `ActiveRecord::AssociationTypeMismatch` when assigning
1608
- a wrong type to a namespaced association.
1609
-
1610
- Fixes #20545.
1611
-
1612
- *Diego Carrion*
1613
-
1614
- * `validates_absence_of` respects `marked_for_destruction?`.
1615
-
1616
- Fixes #20449.
1617
-
1618
- *Yves Senn*
1619
-
1620
- * Include the `Enumerable` module in `ActiveRecord::Relation`
1621
-
1622
- *Sean Griffin*, *bogdan*
1623
-
1624
- * Use `Enumerable#sum` in `ActiveRecord::Relation` if a block is given.
1625
-
1626
- *Sean Griffin*
1627
-
1628
- * Let `WITH` queries (Common Table Expressions) be explainable.
1629
-
1630
- *Vladimir Kochnev*
1631
-
1632
- * Make `remove_index :table, :column` reversible.
1633
-
1634
- *Yves Senn*
1635
-
1636
- * Fixed an error which would occur in dirty checking when calling
1637
- `update_attributes` from a getter.
1638
-
1639
- Fixes #20531.
1640
-
1641
- *Sean Griffin*
1642
-
1643
- * Make `remove_foreign_key` reversible. Any foreign key options must be
1644
- specified, similar to `remove_column`.
1645
-
1646
- *Aster Ryan*
1647
-
1648
- * Add `:_prefix` and `:_suffix` options to `enum` definition.
1649
-
1650
- Fixes #17511, #17415.
1651
-
1652
- *Igor Kapkov*
1653
-
1654
- * Correctly handle decimal arrays with defaults in the schema dumper.
1655
-
1656
- Fixes #20515.
1657
-
1658
- *Sean Griffin*, *jmondo*
1659
-
1660
- * Deprecate the PostgreSQL `:point` type in favor of a new one which will return
1661
- `Point` objects instead of an `Array`
1662
-
1663
- *Sean Griffin*
1664
-
1665
- * Ensure symbols passed to `ActiveRecord::Relation#select` are always treated
1666
- as columns.
1667
-
1668
- Fixes #20360.
1669
-
1670
- *Sean Griffin*
1671
-
1672
- * Do not set `sql_mode` if `strict: :default` is specified.
1673
-
1674
- # config/database.yml
1675
- production:
1676
- adapter: mysql2
1677
- database: foo_prod
1678
- user: foo
1679
- strict: :default
1680
-
1681
- *Ryuta Kamizono*
1682
-
1683
- * Allow proc defaults to be passed to the attributes API. See documentation
1684
- for examples.
1685
-
1686
- *Sean Griffin*, *Kir Shatrov*
1687
-
1688
- * SQLite: `:collation` support for string and text columns.
1689
-
1690
- Example:
1691
-
1692
- create_table :foo do |t|
1693
- t.string :string_nocase, collation: 'NOCASE'
1694
- t.text :text_rtrim, collation: 'RTRIM'
1695
- end
1696
-
1697
- add_column :foo, :title, :string, collation: 'RTRIM'
1698
-
1699
- change_column :foo, :title, :string, collation: 'NOCASE'
1700
-
1701
- *Akshay Vishnoi*
1702
-
1703
- * Allow the use of symbols or strings to specify enum values in test
1704
- fixtures:
1705
-
1706
- awdr:
1707
- title: "Agile Web Development with Rails"
1708
- status: :proposed
1709
-
1710
- *George Claghorn*
1711
-
1712
- * Clear query cache when `ActiveRecord::Base#reload` is called.
1713
-
1714
- *Shane Hender, Pierre Nespo*
1715
-
1716
- * Include stored procedures and function on the MySQL structure dump.
1717
-
1718
- *Jonathan Worek*
1719
-
1720
- * Pass `:extend` option for `has_and_belongs_to_many` associations to the
1721
- underlying `has_many :through`.
1722
-
1723
- *Jaehyun Shin*
1724
-
1725
- * Deprecate `Relation#uniq` use `Relation#distinct` instead.
1726
-
1727
- See #9683.
1728
-
1729
- *Yves Senn*
1730
-
1731
- * Allow single table inheritance instantiation to work when storing
1732
- demodulized class names.
1733
-
1734
- *Alex Robbin*
1735
-
1736
- * Correctly pass MySQL options when using `structure_dump` or
1737
- `structure_load`.
1738
-
1739
- Specifically, it fixes an issue when using SSL authentication.
1740
-
1741
- *Alex Coomans*
1742
-
1743
- * Correctly dump `:options` on `create_table` for MySQL.
1744
-
1745
- *Ryuta Kamizono*
1746
-
1747
- * PostgreSQL: `:collation` support for string and text columns.
1748
-
1749
- Example:
1750
-
1751
- create_table :foos do |t|
1752
- t.string :string_en, collation: 'en_US.UTF-8'
1753
- t.text :text_ja, collation: 'ja_JP.UTF-8'
1754
- end
1755
-
1756
- *Ryuta Kamizono*
1757
-
1758
- * Remove `ActiveRecord::Serialization::XmlSerializer` from core.
1759
-
1760
- *Zachary Scott*
1761
-
1762
- * Make `unscope` aware of "less than" and "greater than" conditions.
1763
-
1764
- *TAKAHASHI Kazuaki*
1765
-
1766
- * `find_by` and `find_by!` raise `ArgumentError` when called without
1767
- arguments.
1768
-
1769
- *Kohei Suzuki*
1770
-
1771
- * Revert behavior of `db:schema:load` back to loading the full
1772
- environment. This ensures that initializers are run.
1773
-
1774
- Fixes #19545.
1775
-
1776
- *Yves Senn*
1777
-
1778
- * Fix missing index when using `timestamps` with the `index` option.
1779
-
1780
- The `index` option used with `timestamps` should be passed to both
1781
- `column` definitions for `created_at` and `updated_at` rather than just
1782
- the first.
1783
-
1784
- *Paul Mucur*
1785
-
1786
- * Rename `:class` to `:anonymous_class` in association options.
1787
-
1788
- Fixes #19659.
1789
-
1790
- *Andrew White*
1791
-
1792
- * Autosave existing records on a has many through association when the parent
1793
- is new.
1794
-
1795
- Fixes #19782.
1796
-
1797
- *Sean Griffin*
1798
-
1799
- * Fixed a bug where uniqueness validations would error on out of range values,
1800
- even if an validation should have prevented it from hitting the database.
1801
-
1802
- *Andrey Voronkov*
1803
-
1804
- * MySQL: `:charset` and `:collation` support for string and text columns.
1805
-
1806
- Example:
1807
-
1808
- create_table :foos do |t|
1809
- t.string :string_utf8_bin, charset: 'utf8', collation: 'utf8_bin'
1810
- t.text :text_ascii, charset: 'ascii'
1811
- end
1812
-
1813
- *Ryuta Kamizono*
1814
-
1815
- * Foreign key related methods in the migration DSL respect
1816
- `ActiveRecord::Base.pluralize_table_names = false`.
1817
-
1818
- Fixes #19643.
1819
-
1820
- *Mehmet Emin İNAÇ*
1821
-
1822
- * Reduce memory usage from loading types on PostgreSQL.
1823
-
1824
- Fixes #19578.
1825
-
1826
- *Sean Griffin*
1827
-
1828
- * Add `config.active_record.warn_on_records_fetched_greater_than` option.
1829
-
1830
- When set to an integer, a warning will be logged whenever a result set
1831
- larger than the specified size is returned by a query.
1832
-
1833
- Fixes #16463.
1834
-
1835
- *Jason Nochlin*
1836
-
1837
- * Ignore `.psqlrc` when loading database structure.
1838
-
1839
- *Jason Weathered*
1840
-
1841
- * Fix referencing wrong table aliases while joining tables of has many through
1842
- association (only when calling calculation methods).
1843
-
1844
- Fixes #19276.
1845
-
1846
- *pinglamb*
1847
-
1848
- * Correctly persist a serialized attribute that has been returned to
1849
- its default value by an in-place modification.
1850
-
1851
- Fixes #19467.
1852
-
1853
- *Matthew Draper*
1854
-
1855
- * Fix generating the schema file when using PostgreSQL `BigInt[]` data type.
1856
- Previously the `limit: 8` was not coming through, and this caused it to
1857
- become `Int[]` data type after rebuilding from the schema.
1858
-
1859
- Fixes #19420.
1860
-
1861
- *Jake Waller*
1862
-
1863
- * Reuse the `CollectionAssociation#reader` cache when the foreign key is
1864
- available prior to save.
1865
-
1866
- *Ben Woosley*
1867
-
1868
- * Add `config.active_record.dump_schemas` to fix `db:structure:dump`
1869
- when using schema_search_path and PostgreSQL extensions.
1870
-
1871
- Fixes #17157.
1872
-
1873
- *Ryan Wallace*
1874
-
1875
- * Renaming `use_transactional_fixtures` to `use_transactional_tests` for clarity.
1876
-
1877
- Fixes #18864.
1878
-
1879
- *Brandon Weiss*
1880
-
1881
- * Increase pg gem version requirement to `~> 0.18`. Earlier versions of the
1882
- pg gem are known to have problems with Ruby 2.2.
1883
-
1884
- *Matt Brictson*
1885
-
1886
- * Correctly dump `serial` and `bigserial`.
1887
-
1888
- *Ryuta Kamizono*
1889
-
1890
- * Fix default `format` value in `ActiveRecord::Tasks::DatabaseTasks#schema_file`.
1891
-
1892
- *James Cox*
1893
-
1894
- * Don't enroll records in the transaction if they don't have commit callbacks.
1895
- This was causing a memory leak when creating many records inside a transaction.
1896
-
1897
- Fixes #15549.
1898
-
1899
- *Will Bryant*, *Aaron Patterson*
1900
-
1901
- * Correctly create through records when created on a has many through
1902
- association when using `where`.
1903
-
1904
- Fixes #19073.
1905
-
1906
- *Sean Griffin*
1907
-
1908
- * Add `SchemaMigration.create_table` support for any unicode charsets with MySQL.
1909
-
1910
- *Ryuta Kamizono*
1911
-
1912
- * PostgreSQL no longer disables user triggers if system triggers can't be
1913
- disabled. Disabling user triggers does not fulfill what the method promises.
1914
- Rails currently requires superuser privileges for this method.
1915
-
1916
- If you absolutely rely on this behavior, consider patching
1917
- `disable_referential_integrity`.
1918
-
1919
- *Yves Senn*
1920
-
1921
- * Restore aborted transaction state when `disable_referential_integrity` fails
1922
- due to missing permissions.
1923
-
1924
- *Toby Ovod-Everett*, *Yves Senn*
1925
-
1926
- * In PostgreSQL, print a warning message if `disable_referential_integrity`
1927
- fails due to missing permissions.
1928
-
1929
- *Andrey Nering*, *Yves Senn*
1930
-
1931
- * Allow a `:limit` option for MySQL bigint primary key support.
1932
-
1933
- Example:
1934
-
1935
- create_table :foos, id: :primary_key, limit: 8 do |t|
1936
- end
1937
-
1938
- # or
1939
-
1940
- create_table :foos, id: false do |t|
1941
- t.primary_key :id, limit: 8
1942
- end
1943
-
1944
- *Ryuta Kamizono*
1945
-
1946
- * `belongs_to` will now trigger a validation error by default if the association is not present.
1947
- You can turn this off on a per-association basis with `optional: true`.
1948
- (Note this new default only applies to new Rails apps that will be generated with
1949
- `config.active_record.belongs_to_required_by_default = true` in initializer.)
1950
-
1951
- *Josef Šimánek*
1952
-
1953
- * Fixed `ActiveRecord::Relation#becomes!` and `changed_attributes` issues for type
1954
- columns.
1955
-
1956
- Fixes #17139.
1957
-
1958
- *Miklos Fazekas*
1959
-
1960
- * Format the time string according to the precision of the time column.
1961
-
1962
- *Ryuta Kamizono*
1963
-
1964
- * Allow a `:precision` option for time type columns.
1965
-
1966
- *Ryuta Kamizono*
1967
-
1968
- * Add `ActiveRecord::Base.suppress` to prevent the receiver from being saved
1969
- during the given block.
1970
-
1971
- For example, here's a pattern of creating notifications when new comments
1972
- are posted. (The notification may in turn trigger an email, a push
1973
- notification, or just appear in the UI somewhere):
1974
-
1975
- class Comment < ActiveRecord::Base
1976
- belongs_to :commentable, polymorphic: true
1977
- after_create -> { Notification.create! comment: self,
1978
- recipients: commentable.recipients }
1979
- end
1980
-
1981
- That's what you want the bulk of the time. A new comment creates a new
1982
- Notification. There may be edge cases where you don't want that, like
1983
- when copying a commentable and its comments, in which case write a
1984
- concern with something like this:
1985
-
1986
- module Copyable
1987
- def copy_to(destination)
1988
- Notification.suppress do
1989
- # Copy logic that creates new comments that we do not want triggering
1990
- # notifications.
1991
- end
1992
- end
1993
- end
1994
-
1995
- *Michael Ryan*
1996
-
1997
- * `:time` option added for `#touch`.
1998
-
1999
- Fixes #18905.
2000
-
2001
- *Hyonjee Joo*
2002
-
2003
- * Add `foreign_key_exists?` method.
2004
-
2005
- *Tõnis Simo*
2006
-
2007
- * Use SQL COUNT and LIMIT 1 queries for `none?` and `one?` methods
2008
- if no block or limit is given, instead of loading the entire
2009
- collection into memory. This applies to relations (e.g. `User.all`)
2010
- as well as associations (e.g. `account.users`)
2011
-
2012
- # Before:
2013
-
2014
- users.none?
2015
- # SELECT "users".* FROM "users"
2016
-
2017
- users.one?
2018
- # SELECT "users".* FROM "users"
2019
-
2020
- # After:
2021
-
2022
- users.none?
2023
- # SELECT 1 AS one FROM "users" LIMIT 1
2024
-
2025
- users.one?
2026
- # SELECT COUNT(*) FROM "users"
2027
-
2028
- *Eugene Gilburg*
2029
-
2030
- * Have `enum` perform type casting consistently with the rest of Active
2031
- Record, such as `where`.
2032
-
2033
- *Sean Griffin*
2034
-
2035
- * `scoping` no longer pollutes the current scope of sibling classes when using
2036
- STI.
2037
-
2038
- Fixes #18806.
2039
-
2040
- Example:
2041
-
2042
- StiOne.none.scoping do
2043
- StiTwo.all
2044
- end
2045
-
2046
-
2047
- *Sean Griffin*
2048
-
2049
- * `remove_reference` with `foreign_key: true` removes the foreign key before
2050
- removing the column. This fixes a bug where it was not possible to remove
2051
- the column on MySQL.
2052
-
2053
- Fixes #18664.
2054
-
2055
- *Yves Senn*
2056
-
2057
- * `find_in_batches` now accepts an `:finish` parameter that complements the `:start`
2058
- parameter to specify where to stop batch processing.
2059
-
2060
- *Vipul A M*
2061
-
2062
- * Fix a rounding problem for PostgreSQL timestamp columns.
2063
-
2064
- If a timestamp column has a precision specified, it needs to
2065
- format according to that.
2066
-
2067
- *Ryuta Kamizono*
2068
-
2069
- * Respect the database default charset for `schema_migrations` table.
2070
-
2071
- The charset of `version` column in `schema_migrations` table depends
2072
- on the database default charset and collation rather than the encoding
2073
- of the connection.
2074
-
2075
- *Ryuta Kamizono*
2076
-
2077
- * Raise `ArgumentError` when passing `nil` or `false` to `Relation#merge`.
2078
-
2079
- These are not valid values to merge in a relation, so it should warn users
2080
- early.
2081
-
2082
- *Rafael Mendonça França*
2083
-
2084
- * Use `SCHEMA` instead of `DB_STRUCTURE` for specifying a structure file.
2085
-
2086
- This makes the `db:structure` tasks consistent with `test:load_structure`.
2087
-
2088
- *Dieter Komendera*
2089
-
2090
- * Respect custom primary keys for associations when calling `Relation#where`
2091
-
2092
- Fixes #18813.
2093
-
2094
- *Sean Griffin*
2095
-
2096
- * Fix several edge cases which could result in a counter cache updating
2097
- twice or not updating at all for `has_many` and `has_many :through`.
2098
-
2099
- Fixes #10865.
2100
-
2101
- *Sean Griffin*
2102
-
2103
- * Foreign keys added by migrations were given random, generated names. This
2104
- meant a different `structure.sql` would be generated every time a developer
2105
- ran migrations on their machine.
2106
-
2107
- The generated part of foreign key names is now a hash of the table name and
2108
- column name, which is consistent every time you run the migration.
2109
-
2110
- *Chris Sinjakli*
2111
-
2112
- * Fix n+1 query problem when eager loading nil associations (fixes #18312)
2113
-
2114
- *Sammy Larbi*
2115
-
2116
- * Change the default error message from `can't be blank` to `must exist` for
2117
- the presence validator of the `:required` option on `belongs_to`/`has_one`
2118
- associations.
2119
-
2120
- *Henrik Nygren*
2121
-
2122
- * Fixed `ActiveRecord::Relation#group` method when an argument is an SQL
2123
- reserved keyword:
2124
-
2125
- Example:
2126
-
2127
- SplitTest.group(:key).count
2128
- Property.group(:value).count
2129
-
2130
- *Bogdan Gusiev*
2131
-
2132
- * Added the `#or` method on `ActiveRecord::Relation`, allowing use of the OR
2133
- operator to combine WHERE or HAVING clauses.
2134
-
2135
- Example:
2136
-
2137
- Post.where('id = 1').or(Post.where('id = 2'))
2138
- # => SELECT * FROM posts WHERE (id = 1) OR (id = 2)
2139
-
2140
- *Sean Griffin*, *Matthew Draper*, *Gael Muller*, *Olivier El Mekki*
2141
-
2142
- * Don't define autosave association callbacks twice from
2143
- `accepts_nested_attributes_for`.
2144
-
2145
- Fixes #18704.
2146
-
2147
- *Sean Griffin*
2148
-
2149
- * Integer types will no longer raise a `RangeError` when assigning an
2150
- attribute, but will instead raise when going to the database.
2151
-
2152
- Fixes several vague issues which were never reported directly. See the
2153
- commit message from the commit which added this line for some examples.
2154
-
2155
- *Sean Griffin*
2156
-
2157
- * Values which would error while being sent to the database (such as an
2158
- ASCII-8BIT string with invalid UTF-8 bytes on SQLite3), no longer error on
2159
- assignment. They will still error when sent to the database, but you are
2160
- given the ability to re-assign it to a valid value.
2161
-
2162
- Fixes #18580.
2163
-
2164
- *Sean Griffin*
2165
-
2166
- * Don't remove join dependencies in `Relation#exists?`
2167
-
2168
- Fixes #18632.
2169
-
2170
- *Sean Griffin*
2171
-
2172
- * Invalid values assigned to a JSON column are assumed to be `nil`.
2173
-
2174
- Fixes #18629.
2175
-
2176
- *Sean Griffin*
2177
-
2178
- * Add `ActiveRecord::Base#accessed_fields`, which can be used to quickly
2179
- discover which fields were read from a model when you are looking to only
2180
- select the data you need from the database.
2181
-
2182
- *Sean Griffin*
2183
-
2184
- * Introduce the `:if_exists` option for `drop_table`.
2185
-
2186
- Example:
2187
-
2188
- drop_table(:posts, if_exists: true)
2189
-
2190
- That would execute:
2191
-
2192
- DROP TABLE IF EXISTS posts
2193
-
2194
- If the table doesn't exist, `if_exists: false` (the default) raises an
2195
- exception whereas `if_exists: true` does nothing.
2196
-
2197
- *Cody Cutrer*, *Stefan Kanev*, *Ryuta Kamizono*
2198
-
2199
- * Don't run SQL if attribute value is not changed for update_attribute method.
2200
-
2201
- *Prathamesh Sonpatki*
2202
-
2203
- * `time` columns can now get affected by `time_zone_aware_attributes`. If you have
2204
- set `config.time_zone` to a value other than `'UTC'`, they will be treated
2205
- as in that time zone by default in Rails 5.1. If this is not the desired
2206
- behavior, you can set
2207
-
2208
- ActiveRecord::Base.time_zone_aware_types = [:datetime]
2209
-
2210
- A deprecation warning will be emitted if you have a `:time` column, and have
2211
- not explicitly opted out.
2212
-
2213
- Fixes #3145.
2214
-
2215
- *Sean Griffin*
2216
-
2217
- * Tests now run after_commit callbacks. You no longer have to declare
2218
- `uses_transaction ‘test name’` to test the results of an after_commit.
2219
-
2220
- after_commit callbacks run after committing a transaction whose parent
2221
- is not `joinable?`: un-nested transactions, transactions within test cases,
2222
- and transactions in `console --sandbox`.
2223
-
2224
- *arthurnn*, *Ravil Bayramgalin*, *Matthew Draper*
2225
-
2226
- * `nil` as a value for a binary column in a query no longer logs as
2227
- "<NULL binary data>", and instead logs as just "nil".
2228
-
2229
- *Sean Griffin*
2230
-
2231
- * `attribute_will_change!` will no longer cause non-persistable attributes to
2232
- be sent to the database.
2233
-
2234
- Fixes #18407.
2235
-
2236
- *Sean Griffin*
2237
-
2238
- * Remove support for the `protected_attributes` gem.
2239
-
2240
- *Carlos Antonio da Silva*, *Roberto Miranda*
2241
-
2242
- * Fix accessing of fixtures having non-string labels like Fixnum.
2243
-
2244
- *Prathamesh Sonpatki*
2245
-
2246
- * Remove deprecated support to preload instance-dependent associations.
2247
-
2248
- *Yves Senn*
2249
-
2250
- * Remove deprecated support for PostgreSQL ranges with exclusive lower bounds.
2251
-
2252
- *Yves Senn*
2253
-
2254
- * Remove deprecation when modifying a relation with cached Arel.
2255
- This raises an `ImmutableRelation` error instead.
2256
-
2257
- *Yves Senn*
2258
-
2259
- * Added `ActiveRecord::SecureToken` in order to encapsulate generation of
2260
- unique tokens for attributes in a model using `SecureRandom`.
2261
-
2262
- *Roberto Miranda*
2263
-
2264
- * Change the behavior of boolean columns to be closer to Ruby's semantics.
2265
-
2266
- Before this change we had a small set of "truthy", and all others are "falsy".
2267
-
2268
- Now, we have a small set of "falsy" values and all others are "truthy" matching
2269
- Ruby's semantics.
2270
-
2271
- *Rafael Mendonça França*
2272
-
2273
- * Deprecate `ActiveRecord::Base.errors_in_transactional_callbacks=`.
2274
-
2275
- *Rafael Mendonça França*
2276
-
2277
- * Change transaction callbacks to not swallow errors.
2278
-
2279
- Before this change any errors raised inside a transaction callback
2280
- were getting rescued and printed in the logs.
2281
-
2282
- Now these errors are not rescued anymore and just bubble up, as the other callbacks.
2283
-
2284
- *Rafael Mendonça França*
2285
-
2286
- * Remove deprecated `sanitize_sql_hash_for_conditions`.
2287
-
2288
- *Rafael Mendonça França*
2289
-
2290
- * Remove deprecated `Reflection#source_macro`.
2291
-
2292
- *Rafael Mendonça França*
2293
-
2294
- * Remove deprecated `symbolized_base_class` and `symbolized_sti_name`.
2295
-
2296
- *Rafael Mendonça França*
2297
-
2298
- * Remove deprecated `ActiveRecord::Base.disable_implicit_join_references=`.
2299
-
2300
- *Rafael Mendonça França*
2301
-
2302
- * Remove deprecated access to connection specification using a string accessor.
2303
-
2304
- Now all strings will be handled as a URL.
2305
-
2306
- *Rafael Mendonça França*
2307
-
2308
- * Change the default `null` value for `timestamps` to `false`.
2309
-
2310
- *Rafael Mendonça França*
2311
-
2312
- * Return an array of pools from `connection_pools`.
2313
-
2314
- *Rafael Mendonça França*
2315
-
2316
- * Return a null column from `column_for_attribute` when no column exists.
2317
-
2318
- *Rafael Mendonça França*
2319
-
2320
- * Remove deprecated `serialized_attributes`.
2321
-
2322
- *Rafael Mendonça França*
2323
-
2324
- * Remove deprecated automatic counter caches on `has_many :through`.
2325
-
2326
- *Rafael Mendonça França*
2327
-
2328
- * Change the way in which callback chains can be halted.
2329
-
2330
- The preferred method to halt a callback chain from now on is to explicitly
2331
- `throw(:abort)`.
2332
- In the past, returning `false` in an Active Record `before_` callback had the
2333
- side effect of halting the callback chain.
2334
- This is not recommended anymore and, depending on the value of the
2335
- `ActiveSupport.halt_callback_chains_on_return_false` option, will
2336
- either not work at all or display a deprecation warning.
2337
-
2338
- *claudiob*
2339
-
2340
- * Clear query cache on rollback.
2341
-
2342
- *Florian Weingarten*
2343
-
2344
- * Fix setting of foreign_key for through associations when building a new record.
2345
-
2346
- Fixes #12698.
2347
-
2348
- *Ivan Antropov*
2349
-
2350
- * Improve dumping of the primary key. If it is not a default primary key,
2351
- correctly dump the type and options.
2352
-
2353
- Fixes #14169, #16599.
2354
-
2355
- *Ryuta Kamizono*
2356
-
2357
- * Format the datetime string according to the precision of the datetime field.
2358
-
2359
- Incompatible to rounding behavior between MySQL 5.6 and earlier.
2360
-
2361
- In 5.5, when you insert `2014-08-17 12:30:00.999999` the fractional part
2362
- is ignored. In 5.6, it's rounded to `2014-08-17 12:30:01`:
2363
-
2364
- http://bugs.mysql.com/bug.php?id=68760
2365
-
2366
- *Ryuta Kamizono*
2367
-
2368
- * Allow a precision option for MySQL datetimes.
2369
-
2370
- *Ryuta Kamizono*
2371
-
2372
- * Fixed automatic `inverse_of` for models nested in a module.
2373
-
2374
- *Andrew McCloud*
2375
-
2376
- * Change `ActiveRecord::Relation#update` behavior so that it can
2377
- be called without passing ids of the records to be updated.
2378
-
2379
- This change allows updating multiple records returned by
2380
- `ActiveRecord::Relation` with callbacks and validations.
2381
-
2382
- # Before
2383
- # ArgumentError: wrong number of arguments (1 for 2)
2384
- Comment.where(group: 'expert').update(body: "Group of Rails Experts")
2385
-
2386
- # After
2387
- # Comments with group expert updated with body "Group of Rails Experts"
2388
- Comment.where(group: 'expert').update(body: "Group of Rails Experts")
2389
-
2390
- *Prathamesh Sonpatki*
2391
-
2392
- * Fix `reaping_frequency` option when the value is a string.
2393
-
2394
- This usually happens when it is configured using `DATABASE_URL`.
2395
-
2396
- *korbin*
2397
-
2398
- * Fix error message when trying to create an associated record and the foreign
2399
- key is missing.
2400
-
2401
- Before this fix the following exception was being raised:
2402
-
2403
- NoMethodError: undefined method `val' for #<Arel::Nodes::BindParam:0x007fc64d19c218>
2404
-
2405
- Now the message is:
2406
-
2407
- ActiveRecord::UnknownAttributeError: unknown attribute 'foreign_key' for Model.
2408
-
2409
- *Rafael Mendonça França*
2410
-
2411
- * Fix change detection problem for PostgreSQL bytea type and
2412
- `ArgumentError: string contains null byte` exception with pg-0.18.
2413
-
2414
- Fixes #17680.
2415
-
2416
- *Lars Kanis*
2417
-
2418
- * When a table has a composite primary key, the `primary_key` method for
2419
- SQLite3 and PostgreSQL adapters was only returning the first field of the key.
2420
- Ensures that it will return nil instead, as Active Record doesn't support
2421
- composite primary keys.
2422
-
2423
- Fixes #18070.
2424
-
2425
- *arthurnn*
2426
-
2427
- * `validates_size_of` / `validates_length_of` do not count records
2428
- which are `marked_for_destruction?`.
2429
-
2430
- Fixes #7247.
2431
-
2432
- *Yves Senn*
2433
-
2434
- * Ensure `first!` and friends work on loaded associations.
2435
-
2436
- Fixes #18237.
2437
-
2438
- *Sean Griffin*
2439
-
2440
- * `eager_load` preserves readonly flag for associations.
2441
-
2442
- Fixes #15853.
2443
-
2444
- *Takashi Kokubun*
2445
-
2446
- * Provide `:touch` option to `save()` to accommodate saving without updating
2447
- timestamps.
2448
-
2449
- Fixes #18202.
2450
-
2451
- *Dan Olson*
2452
-
2453
- * Provide a more helpful error message when an unsupported class is passed to
2454
- `serialize`.
2455
-
2456
- Fixes #18224.
2457
-
2458
- *Sean Griffin*
2459
-
2460
- * Add bigint primary key support for MySQL.
2461
-
2462
- Example:
2463
-
2464
- create_table :foos, id: :bigint do |t|
2465
- end
2466
-
2467
- *Ryuta Kamizono*
2468
-
2469
- * Support for any type of primary key.
2470
-
2471
- Fixes #14194.
2472
-
2473
- *Ryuta Kamizono*
2474
-
2475
- * Dump the default `nil` for PostgreSQL UUID primary key.
2476
-
2477
- *Ryuta Kamizono*
2478
-
2479
- * Add a `:foreign_key` option to `references` and associated migration
2480
- methods. The model and migration generators now use this option, rather than
2481
- the `add_foreign_key` form.
2482
-
2483
- *Sean Griffin*
2484
-
2485
- * Don't raise when writing an attribute with an out-of-range datetime passed
2486
- by the user.
2487
-
2488
- *Grey Baker*
2489
-
2490
- * Replace deprecated `ActiveRecord::Tasks::DatabaseTasks#load_schema` with
2491
- `ActiveRecord::Tasks::DatabaseTasks#load_schema_for`.
2492
-
2493
- *Yves Senn*
2494
-
2495
- * Fix bug with `ActiveRecord::Type::Numeric` that caused negative values to
2496
- be marked as having changed when set to the same negative value.
2497
-
2498
- Fixes #18161.
2499
-
2500
- *Daniel Fox*
2501
-
2502
- * Introduce `force: :cascade` option for `create_table`. Using this option
2503
- will recreate tables even if they have dependent objects (like foreign keys).
2504
- `db/schema.rb` now uses `force: :cascade`. This makes it possible to
2505
- reload the schema when foreign keys are in place.
2506
-
2507
- *Matthew Draper*, *Yves Senn*
2508
-
2509
- * `db:schema:load` and `db:structure:load` no longer purge the database
2510
- before loading the schema. This is left for the user to do.
2511
- `db:test:prepare` will still purge the database.
2512
-
2513
- Fixes #17945.
2514
-
2515
- *Yves Senn*
2516
-
2517
- * Fix undesirable RangeError by `Type::Integer`. Add `Type::UnsignedInteger`.
2518
-
2519
- *Ryuta Kamizono*
1340
+ * Add support for multiple databases to `rails db:abort_if_pending_migrations`.
2520
1341
 
2521
- * Add `foreign_type` option to `has_one` and `has_many` association macros.
1342
+ *Mark Lee*
2522
1343
 
2523
- This option enables to define the column name of associated object's type for polymorphic associations.
1344
+ * Fix sqlite3 collation parsing when using decimal columns.
2524
1345
 
2525
- *Ulisses Almeida*, *Kassio Borges*
1346
+ *Martin R. Schuster*
2526
1347
 
2527
- * Remove deprecated behavior allowing nested arrays to be passed as query
2528
- values.
1348
+ * Fix invalid schema when primary key column has a comment.
2529
1349
 
2530
- *Melanie Gilman*
1350
+ Fixes #29966.
2531
1351
 
2532
- * Deprecate passing a class as a value in a query. Users should pass strings
2533
- instead.
1352
+ *Guilherme Goettems Schneider*
2534
1353
 
2535
- *Melanie Gilman*
1354
+ * Fix table comment also being applied to the primary key column.
2536
1355
 
2537
- * `add_timestamps` and `remove_timestamps` now properly reversible with
2538
- options.
1356
+ *Guilherme Goettems Schneider*
2539
1357
 
2540
- *Noam Gagliardi-Rabinovich*
1358
+ * Allow generated `create_table` migrations to include or skip timestamps.
2541
1359
 
2542
- * `ActiveRecord::ConnectionAdapters::ColumnDumper#column_spec` and
2543
- `ActiveRecord::ConnectionAdapters::ColumnDumper#prepare_column_options` no
2544
- longer have a `types` argument. They should access
2545
- `connection#native_database_types` directly.
1360
+ *Michael Duchemin*
2546
1361
 
2547
- *Yves Senn*
2548
1362
 
2549
- Please check [4-2-stable](https://github.com/rails/rails/blob/4-2-stable/activerecord/CHANGELOG.md) for previous changes.
1363
+ Please check [6-0-stable](https://github.com/rails/rails/blob/6-0-stable/activerecord/CHANGELOG.md) for previous changes.